feat: backfeed of responses to crossposts (v2.13.0)

Likes, reposts, quotes and replies to a note's GoToSocial, Bluesky and
Threads copies are read back from the silos and stored as webmentions
(ADR-073): age-based schedule to 90 days, pruning of withdrawn responses,
#nobridge/#nobot opt-outs, admin backfill and Check now, Threads counts,
a Quotes group, local avatar copies, and delete tombstones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-10 12:19:57 -07:00
1 parent 6aaac982d5
commit 55ce6a1fdd
27 files changed
+1763 -40

No files matched your search

+34 -10
View File
@@ -39,7 +39,8 @@ def get_webmentions_for_note(note_id: int) -> Dict[str, List[Dict[str, Any]]]:
note_id: Note database ID
Returns:
Dict with keys: 'replies', 'likes', 'reposts', 'bookmarks', 'mentions'
Dict with keys: 'replies', 'likes', 'reposts', 'bookmarks', 'quotes'
(backfed quote posts, v2.13.0), 'mentions'
Each value is a list of webmention dicts
"""
db = get_db()
@@ -56,24 +57,34 @@ def get_webmentions_for_note(note_id: int) -> Dict[str, List[Dict[str, Any]]]:
WHEN 'like' THEN 2
WHEN 'repost' THEN 3
WHEN 'bookmark' THEN 4
WHEN 'mention' THEN 5
WHEN 'quote' THEN 5
WHEN 'mention' THEN 6
END,
received_at ASC
"""
rows = db.execute(query, (note_id,)).fetchall()
# Backfed responses say which silo they came from (v2.13.0)
silo_names = {}
if any(row['origin'] != 'webmention' for row in rows):
from starpunk.backfeed import SILO_NAMES
from starpunk.syndication import get_targets
silo_names = {**SILO_NAMES, **{t.id: t.name for t in get_targets().values()}}
# Group by type
grouped = {
'replies': [],
'likes': [],
'reposts': [],
'bookmarks': [],
'quotes': [],
'mentions': []
}
for row in rows:
wm = dict(row)
wm['via'] = silo_names.get(wm['origin']) if wm['origin'] != 'webmention' else None
# Parse timestamps (source_published may be missing or malformed)
for key in ('received_at', 'source_published'):
if isinstance(wm.get(key), str):
@@ -91,6 +102,8 @@ def get_webmentions_for_note(note_id: int) -> Dict[str, List[Dict[str, Any]]]:
grouped['reposts'].append(wm)
elif mention_type == 'bookmark':
grouped['bookmarks'].append(wm)
elif mention_type == 'quote':
grouped['quotes'].append(wm)
else:
grouped['mentions'].append(wm)
@@ -100,15 +113,18 @@ def get_webmentions_for_note(note_id: int) -> Dict[str, List[Dict[str, Any]]]:
def list_webmentions(
status_filter: Optional[str] = None,
page: int = 1,
per_page: int = 25
per_page: int = 25,
origin_filter: Optional[str] = None,
) -> tuple[List[Dict[str, Any]], int]:
"""
List webmentions for admin with pagination and filtering.
Args:
status_filter: Filter by moderation_status ('pending', 'approved', 'hidden')
status_filter: Filter by moderation_status ('pending', 'approved', 'hidden',
'deleted'). Deleted ones are left out unless asked for (v2.13.0).
page: Page number (1-indexed)
per_page: Items per page (default: 25)
origin_filter: 'webmention' or a backfeed silo id (v2.13.0)
Returns:
Tuple of (webmentions list, total_pages)
@@ -124,12 +140,16 @@ def list_webmentions(
count_query = "SELECT COUNT(*) FROM webmentions"
params = []
where_clause = ""
conditions = ["moderation_status = ?" if status_filter else "moderation_status != 'deleted'"]
if status_filter:
where_clause = " WHERE w.moderation_status = ?"
count_query += " WHERE moderation_status = ?"
params.append(status_filter)
if origin_filter:
conditions.append("origin = ?")
params.append(origin_filter)
where = " AND ".join(conditions)
where_clause = " WHERE " + where.replace("moderation_status", "w.moderation_status").replace(
"origin", "w.origin")
count_query += " WHERE " + where
# Count total
total_count = db.execute(count_query, params).fetchone()[0]
@@ -206,7 +226,7 @@ def count_webmentions(status_filter: Optional[str] = None) -> int:
query = "SELECT COUNT(*) FROM webmentions WHERE moderation_status = ?"
result = db.execute(query, (status_filter,)).fetchone()
else:
query = "SELECT COUNT(*) FROM webmentions"
query = "SELECT COUNT(*) FROM webmentions WHERE moderation_status != 'deleted'"
result = db.execute(query).fetchone()
return result[0] if result else 0
@@ -260,6 +280,9 @@ def delete_webmentions(webmention_ids: List[int]) -> int:
"""
Delete webmentions by IDs.
The row stays as a tombstone (moderation_status 'deleted', v2.13.0), so
a re-sent webmention or the next backfeed check doesn't bring it back.
Args:
webmention_ids: List of webmention IDs to delete
@@ -276,7 +299,8 @@ def delete_webmentions(webmention_ids: List[int]) -> int:
)
placeholders = ','.join('?' * len(webmention_ids))
query = f"DELETE FROM webmentions WHERE id IN ({placeholders})"
query = (f"UPDATE webmentions SET moderation_status = 'deleted', updated_at = CURRENT_TIMESTAMP "
f"WHERE id IN ({placeholders}) AND moderation_status != 'deleted'")
cursor = db.execute(query, webmention_ids)
db.commit()