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

+32 -1
View File
@@ -82,6 +82,8 @@ class WebmentionWorker(threading.Thread):
self._stop_event = threading.Event()
self._last_processed = None
self._lock_file = None
from starpunk.avatars import Upkeep
self._avatar_upkeep = Upkeep()
def run(self):
"""
@@ -113,6 +115,9 @@ class WebmentionWorker(threading.Thread):
# Phase 3: Process outgoing webmentions
processed += self._process_pending_sends()
# Local copies of response avatars (v2.13.0)
self._avatar_upkeep.run(self.db_path, self.app.config['DATA_PATH'],
self.site_url)
# Update last processed time
if processed > 0:
@@ -281,6 +286,22 @@ class WebmentionWorker(threading.Thread):
source_url, result.get('source_post_url'), result.get('source_uid')) if u}
return bool(copies & source)
def _is_backfed(self, note_id: Optional[int], source_url: str, result: Dict[str, Any]) -> bool:
"""True if the source is a response already stored by backfeed for this note"""
if note_id is None:
return False
conn = sqlite3.connect(self.db_path)
try:
backfed = {normalize_url(row[0]) for row in conn.execute(
"SELECT source_url FROM webmentions WHERE target_note_id = ? AND origin != 'webmention'",
(note_id,),
)}
finally:
conn.close()
source = {normalize_url(u) for u in (
source_url, result.get('source_post_url'), result.get('source_uid')) if u}
return bool(backfed & source)
def _display_state(self, webmention_id: int) -> Optional[tuple]:
"""
What the note page shows for this webmention, or None if hidden
@@ -328,6 +349,11 @@ class WebmentionWorker(threading.Thread):
if self._is_own_syndicated_copy(target_note_id, source_url, result):
raise ValidationError("Source is this note's own syndicated copy")
# A response StarPunk already backfed from the silo (e.g. a reply
# also sent by Bridgy) would show twice (v2.13.0, ADR-073)
if self._is_backfed(target_note_id, source_url, result):
raise ValidationError("Already backfed from the silo")
# Update database with successful validation
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
@@ -372,6 +398,10 @@ class WebmentionWorker(threading.Thread):
conn.commit()
conn.close()
# Pages show a local copy of the avatar (v2.13.0, ADR-073)
from starpunk import avatars
avatars.fetch(self.app.config['DATA_PATH'], result['author_photo'], self.site_url)
logger.info(
f"Validated webmention: {source_url} -> {target_url} "
f"(type={result['mention_type']})"
@@ -422,7 +452,8 @@ class WebmentionWorker(threading.Thread):
# All other errors are 'error' status
if transient:
status = 'error'
elif any(x in error.lower() for x in ['does not link', 'returned 4', 'own syndicated copy']):
elif any(x in error.lower() for x in ['does not link', 'returned 4', 'own syndicated copy',
'already backfed']):
status = 'invalid'
else:
status = 'error'