diff --git a/docs/design/v2.13.0/2026-11-10-backfeed.md b/docs/design/v2.13.0/2026-11-10-backfeed.md index cbd1604..e57637e 100644 --- a/docs/design/v2.13.0/2026-11-10-backfeed.md +++ b/docs/design/v2.13.0/2026-11-10-backfeed.md @@ -27,14 +27,15 @@ Implements ADR-073. ## Verification -- `tests/test_backfeed.py` (21 tests): schedule; text/facet HTML; storing, +- `tests/test_backfeed.py` (22 tests): schedule; text/facet HTML; storing, updating and moderation kept; pruning only on complete harvests and restoring; opt-outs; tombstones; backfill and its pacing; likes/reposts and drafts skipped; refused credentials; backoff; note page (via label, quotes, Threads counts, local avatars); avatar save/serve/cleanup; webmention can't overwrite a backfed row; the three clients against fake APIs; migration 020 on a pre-020 database keeps rows and foreign keys; - the admin Backfeed panel, backfill and Check now. + the admin Backfeed panel, backfill and Check now; Threads avatar URLs + (signed, changing per request) aren't refetched while a copy exists. - Tests for the touched areas (webmentions, syndication, microformats, migrations, templates, routes): all pass. The full suite runs in CI. - `test_microformats_v280` expects response authors' `u-photo`: kept via diff --git a/starpunk/backfeed.py b/starpunk/backfeed.py index 899b212..4e367af 100644 --- a/starpunk/backfeed.py +++ b/starpunk/backfeed.py @@ -256,9 +256,18 @@ def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest) -> N keep = [r for r in harvest.responses if not _opted_out(r)] dropped = [r.source_url for r in harvest.responses if _opted_out(r)] + from starpunk.avatars import cached_name + before = _display_state(db, note_id) for r in keep: snippet = _snippet(r.content_html) if r.content_html else None + # Threads avatar URLs are signed and change on every request: keep + # the stored URL while its saved copy exists, so it isn't refetched + old = db.execute("SELECT author_photo FROM webmentions WHERE source_url = ? AND target_url = ?", + (r.source_url, target_url)).fetchone() + if old and old["author_photo"] and origin == "threads" \ + and cached_name(current_app.config["DATA_PATH"], old["author_photo"]): + r.author_photo = old["author_photo"] db.execute( """ INSERT INTO webmentions ( diff --git a/tests/test_backfeed.py b/tests/test_backfeed.py index 392023e..4a78dbe 100644 --- a/tests/test_backfeed.py +++ b/tests/test_backfeed.py @@ -540,3 +540,25 @@ def test_admin_backfill_and_check_now(app, client): backfeed.denied["gotosocial"] = "Needs a GoToSocial token with read:statuses" assert "Needs a GoToSocial token" in browser.get("/admin/webmentions?origin=gotosocial").get_data(as_text=True) + + +def test_threads_avatar_kept_while_its_copy_exists(app, client, web): + note, _ = crossposted(app) + with app.app_context(): + get_db(app).execute("UPDATE syndications SET target = 'threads'") + get_db(app).commit() + syndication._client_cache["threads"] = client + app.config["THREADS_ACCESS_TOKEN"] = "token" + web.files["https://cdn.example/p.jpg?sig=1"] = png() + first = reply(1) + first.author_photo = "https://cdn.example/p.jpg?sig=1" + client.harvest = Harvest([first]) + run(app) + with app.app_context(): + get_db(app).execute("UPDATE syndications SET backfeed_next_at = datetime('now')") + get_db(app).commit() + again = reply(1) + again.author_photo = "https://cdn.example/p.jpg?sig=2" # not fetchable: would be a refetch + client.harvest = Harvest([again]) + run(app) + assert rows(app, note.id)[0]["author_photo"] == "https://cdn.example/p.jpg?sig=1"