fix: backfeed whole reply threads and nest them (v2.20.2)

Backfeed only read first-level replies (Threads /replies, GoToSocial
direct replies, Bluesky depth 1) and skipped the owner's own replies, so
conversations under crossposts lost everything after the first reply.

- Threads /conversation, all GoToSocial descendants, Bluesky depth 10
- backfeed.thread_members keeps others' replies to our copy and any reply
  (ours included) to a kept reply; own replies are stored as notified
- Migration 026: webmentions.parent_remote_id; replies render nested as
  comments of comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-13 20:43:30 -07:00
1 parent 952ca300c0
commit bf6e0fdc0b
11 files changed
+283 -42

No files matched your search

+53 -24
View File
@@ -240,8 +240,9 @@ class MastodonClient:
}
def responses(self, remote_id: str, remote_url: str, cap: int = 1000):
"""Likes, boosts and public direct replies of one of our statuses"""
from starpunk.backfeed import Harvest, Response
"""Likes, boosts and public replies of one of our statuses, with the
replies to those replies (v2.20.2)"""
from starpunk.backfeed import Harvest, Response, thread_members
me = self._account_id()
found, complete = [], True
@@ -255,14 +256,18 @@ class MastodonClient:
found.append(Response(kind=kind, source_url=f"{remote_url}#{fragment}-{account['id']}",
remote_id=account["id"], **self._author(account)))
context = self._call("GET", f"/api/v1/statuses/{remote_id}/context").json() or {}
for status in context.get("descendants") or []:
account = status.get("account") or {}
if (status.get("in_reply_to_id") != remote_id or status.get("visibility") != "public"
or account.get("id") == me):
public = [st for st in context.get("descendants") or [] if st.get("visibility") == "public"]
kept = thread_members([{"id": st["id"], "parent": st.get("in_reply_to_id"),
"own": (st.get("account") or {}).get("id") == me} for st in public],
remote_id)
for status in public:
if status["id"] not in kept:
continue
account = status.get("account") or {}
found.append(Response(kind="reply", source_url=status.get("url") or status["uri"],
remote_id=status["id"], content_html=status.get("content") or "",
published=status.get("created_at"), **self._author(account)))
published=status.get("created_at"), parent_id=kept[status["id"]],
own=account.get("id") == me, **self._author(account)))
return Harvest(found, complete)
def delete(self, remote_id: str) -> None:
@@ -277,6 +282,7 @@ class MastodonClient:
BLUESKY_BLOB_LIMIT = 1_000_000 # app.bsky.embed.images maxSize
BLUESKY_THREAD_DEPTH = 10 # how deep backfeed follows replies to replies
_TID_CHARS = "234567abcdefghijklmnopqrstuvwxyz"
@@ -588,8 +594,9 @@ class BlueskyClient:
)
def responses(self, remote_id: str, remote_url: str, cap: int = 1000):
"""Likes, reposts, quotes and direct replies of one of our posts"""
from starpunk.backfeed import Harvest, Response
"""Likes, reposts, quotes and replies of one of our posts, with the
replies to those replies (v2.20.2)"""
from starpunk.backfeed import Harvest, Response, thread_members
if not self.did:
with self._lock:
@@ -612,10 +619,26 @@ class BlueskyClient:
complete = complete and done
posts = [self._post_response("quote", view) for view in quotes]
thread = self._call("GET", "app.bsky.feed.getPostThread",
params={"uri": remote_id, "depth": 1, "parentHeight": 0}).json()
for item in (thread.get("thread") or {}).get("replies") or []:
if item.get("post"): # skips blocked and deleted replies
posts.append(self._post_response("reply", item["post"]))
params={"uri": remote_id, "depth": BLUESKY_THREAD_DEPTH,
"parentHeight": 0}).json()
# The whole conversation under our post (v2.20.2)
views, stack = {}, [(remote_id, item) for item in (thread.get("thread") or {}).get("replies") or []]
while stack:
parent, item = stack.pop()
post = item.get("post")
if not post: # blocked or deleted: its replies go with it
continue
views[post["uri"]] = (parent, post)
stack.extend((post["uri"], child) for child in item.get("replies") or [])
kept = thread_members([{"id": uri, "parent": parent,
"own": (post.get("author") or {}).get("did") == self.did}
for uri, (parent, post) in views.items()], remote_id)
for uri, (_, post) in sorted(views.items(), key=lambda v: v[1][1].get("indexedAt") or ""):
if uri in kept:
response = self._post_response("reply", post)
response.parent_id = kept[uri]
response.own = response.author_id == self.did
posts.append(response)
# Post views carry no bio; fetch them to honour #nobridge
dids = list({p.author_id for p in posts if p.author_id})
bios = {}
@@ -626,7 +649,7 @@ class BlueskyClient:
for post in posts:
post.author_bio = bios.get(post.author_id, "")
found.extend(posts)
return Harvest([r for r in found if r.author_id != self.did], complete)
return Harvest([r for r in found if r.author_id != self.did or r.own], complete)
def delete(self, remote_id: str) -> None:
# at://<did>/app.bsky.feed.post/<rkey>; deleting a missing record succeeds
@@ -1013,15 +1036,17 @@ class ThreadsClient:
# --- Backfeed (v2.13.0, ADR-073) ---
REPLY_FIELDS = "id,text,username,permalink,timestamp,profile_picture_url,hide_status"
REPLY_FIELDS = "id,text,username,permalink,timestamp,profile_picture_url,hide_status,replied_to"
SHOWN = (None, "NOT_HUSHED", "UNHUSHED") # hide_status values of replies nobody hid
def responses(self, remote_id: str, remote_url: str, cap: int = 1000):
"""
Direct replies to one of our posts, and its like/repost/quote counts.
The API doesn't say who liked, reposted or quoted (ADR-073 Decision 7).
Replies to one of our posts, with the replies to those replies
(/conversation, v2.20.2; /replies only has the first level), and its
like/repost/quote counts. The API doesn't say who liked, reposted or
quoted (ADR-073 Decision 7).
"""
from starpunk.backfeed import Harvest, Response, text_html
from starpunk.backfeed import Harvest, Response, text_html, thread_members
self._me()
replies, after, complete = [], None, True
@@ -1029,7 +1054,7 @@ class ThreadsClient:
params = {"fields": self.REPLY_FIELDS}
if after:
params["after"] = after
data = self._call("GET", f"{remote_id}/replies", **params)
data = self._call("GET", f"{remote_id}/conversation", **params)
page = data.get("data") or []
replies.extend(page)
if len(replies) >= cap:
@@ -1039,14 +1064,18 @@ class ThreadsClient:
after = (paging.get("cursors") or {}).get("after")
if not page or not after or not paging.get("next"):
break
# Private accounts have no username or permalink: nothing public to show
shown = [r for r in replies if r.get("username") and r.get("permalink")
and r.get("hide_status") in self.SHOWN]
kept = thread_members([{"id": r["id"], "parent": (r.get("replied_to") or {}).get("id"),
"own": r["username"] == self.username} for r in shown], remote_id)
found = []
for reply in replies:
username = reply.get("username")
# Private accounts have no username or permalink: nothing public to show
if (not username or not reply.get("permalink") or username == self.username
or reply.get("hide_status") not in self.SHOWN):
for reply in sorted(shown, key=lambda r: r.get("timestamp") or ""):
if reply["id"] not in kept:
continue
username = reply["username"]
found.append(Response(
parent_id=kept[reply["id"]], own=username == self.username,
kind="reply", source_url=reply["permalink"], remote_id=reply["id"],
author_id=username, author_name=username,
author_url=f"https://www.threads.com/@{username}",