fix: count opted-out likes and reposts without naming them (v2.13.3)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-10 13:16:19 -07:00
1 parent 76b81d6ad9
commit 113f28aff1
9 files changed
+85 -9

No files matched your search

+19 -3
View File
@@ -64,7 +64,9 @@ class Harvest:
"""What one check found. complete=False: some list was cut short."""
responses: List[Response]
complete: bool = True
counts: Optional[Dict[str, int]] = None # Threads likes/reposts/quotes
# Likes/reposts/quotes shown only as numbers: all of them on Threads
# (its API doesn't say who); elsewhere, those by people who opted out
counts: Optional[Dict[str, int]] = None
# --- Text -----------------------------------------------------------------
@@ -243,11 +245,25 @@ def _display_state(db, note_id: int) -> list:
)]
def hidden_counts(harvest: Harvest) -> Dict[str, int]:
"""
Likes, reposts and quotes to show only as numbers: the silo's own counts
when it gives no names (Threads), else those by people who opted out
(v2.13.3: they're counted, not named)
"""
if harvest.counts is not None:
return harvest.counts
hidden = [r.kind for r in harvest.responses if _opted_out(r)]
return {k: hidden.count(kind) for k, kind in
(("likes", "like"), ("reposts", "repost"), ("quotes", "quote"))}
def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest) -> None:
"""
Upsert a check's responses for one note and silo. With a complete
harvest, that silo's responses for the note that weren't found are
marked invalid. Responses from people who opted out are removed.
marked invalid. Responses from people who opted out are removed (they
are counted instead, see `hidden_counts`).
"""
from starpunk.webmention_processor import _snippet
@@ -358,7 +374,7 @@ def check(row, target) -> None:
site = current_app.config["SITE_URL"].rstrip("/")
harvest = target.client.responses(row["remote_id"], row["remote_url"] or "")
store(db, row["note_id"], f"{site}/note/{row['note_slug']}", row["target"], harvest)
_store_counts(db, row["id"], harvest.counts)
_store_counts(db, row["id"], hidden_counts(harvest))
def process_due(limit: int = 3) -> int: