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:
1 parent
952ca300c0
commit
bf6e0fdc0b
11 files changed
+283
-42
No files matched your search
+107
-11
@@ -392,18 +392,25 @@ def mastodon_api(request):
|
||||
"account": who or account("r" + n)}
|
||||
return httpx.Response(200, json={"ancestors": [], "descendants": [
|
||||
status("10"), status("11", vis="unlisted"), status("12", parent="10"),
|
||||
status("13", who=account("me"))]})
|
||||
status("13", who=account("me")), status("14", parent="12", who=account("me")),
|
||||
status("15", parent="13")]})
|
||||
return httpx.Response(404)
|
||||
|
||||
|
||||
def test_mastodon_client_reads_likes_boosts_and_public_direct_replies():
|
||||
def test_mastodon_client_reads_likes_boosts_and_public_reply_threads():
|
||||
gts = MastodonClient(GTS, "t", http=httpx.Client(transport=httpx.MockTransport(mastodon_api)))
|
||||
harvest = gts.responses("01COPY", COPY)
|
||||
assert harvest.complete
|
||||
got = [(r.kind, r.source_url) for r in harvest.responses]
|
||||
# 11 isn't public; 13 is our own thread continuing, so 15 under it is left out too.
|
||||
# 12 answers 10, and our 14 answers 12 (v2.20.2)
|
||||
assert got == [("like", f"{COPY}#liked-by-1"), ("like", f"{COPY}#liked-by-3"),
|
||||
("repost", f"{COPY}#reposted-by-2"), ("reply", f"{GTS}/@u/statuses/10")]
|
||||
assert harvest.responses[-1].content_html == "<p>reply 10</p>"
|
||||
("repost", f"{COPY}#reposted-by-2"), ("reply", f"{GTS}/@u/statuses/10"),
|
||||
("reply", f"{GTS}/@u/statuses/12"), ("reply", f"{GTS}/@u/statuses/14")]
|
||||
replies = {r.remote_id: r for r in harvest.responses if r.kind == "reply"}
|
||||
assert replies["10"].content_html == "<p>reply 10</p>"
|
||||
assert [(replies[i].parent_id, replies[i].own) for i in ("10", "12", "14")] == \
|
||||
[(None, False), ("10", False), ("12", True)]
|
||||
assert gts.responses("01COPY", COPY, cap=1).complete is False
|
||||
|
||||
|
||||
@@ -457,14 +464,22 @@ def test_threads_client_reads_replies_and_counts():
|
||||
params = parse_qs(request.url.query.decode())
|
||||
if path.endswith("/me"):
|
||||
return httpx.Response(200, json={"id": "42", "username": "me"})
|
||||
if path.endswith("/111/replies"):
|
||||
assert "profile_picture_url" in params["fields"][0]
|
||||
if path.endswith("/111/conversation"):
|
||||
# The whole conversation, newest first, as Meta returns it (v2.20.2)
|
||||
assert "profile_picture_url" in params["fields"][0] and "replied_to" in params["fields"][0]
|
||||
to = lambda i: {"replied_to": {"id": i}}
|
||||
return httpx.Response(200, json={"data": [
|
||||
{"id": "6", "text": "Ha", "username": "ann", "permalink": "https://www.threads.com/@ann/post/C",
|
||||
"timestamp": "2026-11-10T02:00:00+0000", "hide_status": "NOT_HUSHED", **to("5")},
|
||||
{"id": "5", "text": "Yes", "username": "me", "permalink": "https://www.threads.com/@me/post/B",
|
||||
"timestamp": "2026-11-10T01:00:00+0000", **to("1")},
|
||||
{"id": "7", "text": "under mine", "username": "bo", "permalink": "p", "hide_status": "NOT_HUSHED",
|
||||
**to("4")},
|
||||
{"id": "1", "text": "Hi", "username": "ann", "permalink": "https://www.threads.com/@ann/post/A",
|
||||
"timestamp": "2026-11-10T00:00:00+0000", "hide_status": "NOT_HUSHED"},
|
||||
{"id": "2", "text": "private"},
|
||||
{"id": "3", "text": "hidden", "username": "x", "permalink": "p", "hide_status": "HIDDEN"},
|
||||
{"id": "4", "text": "mine", "username": "me", "permalink": "p"}]})
|
||||
"timestamp": "2026-11-10T00:00:00+0000", "hide_status": "NOT_HUSHED", **to("111")},
|
||||
{"id": "2", "text": "private", **to("111")},
|
||||
{"id": "3", "text": "hidden", "username": "x", "permalink": "p", "hide_status": "HIDDEN", **to("111")},
|
||||
{"id": "4", "text": "mine", "username": "me", "permalink": "p", **to("111")}]})
|
||||
if path.endswith("/111/insights"):
|
||||
assert params["metric"] == ["likes,reposts,quotes"]
|
||||
return httpx.Response(200, json={"data": [
|
||||
@@ -474,7 +489,10 @@ def test_threads_client_reads_replies_and_counts():
|
||||
|
||||
threads = ThreadsClient("tok", http=httpx.Client(transport=httpx.MockTransport(api)))
|
||||
harvest = threads.responses("111", "https://www.threads.com/@me/post/X")
|
||||
assert [(r.kind, r.author_name, r.content_html) for r in harvest.responses] == [("reply", "ann", "<p>Hi</p>")]
|
||||
# Our own reply to our post continues the thread (4, and 7 under it, are left out);
|
||||
# our reply to ann (5) and her answer (6) are kept, oldest first
|
||||
assert [(r.author_name, r.content_html, r.parent_id, r.own) for r in harvest.responses] == [
|
||||
("ann", "<p>Hi</p>", None, False), ("me", "<p>Yes</p>", "1", True), ("ann", "<p>Ha</p>", "5", False)]
|
||||
assert harvest.counts == {"likes": 12, "reposts": 3, "quotes": 0}
|
||||
|
||||
|
||||
@@ -658,3 +676,81 @@ def test_quote_counts_include_anonymous_ones(app, client):
|
||||
assert "Quoter" in page, "the named quote is listed under Responses"
|
||||
home = app.test_client().get("/").get_data(as_text=True)
|
||||
assert 'title="3 quotes"' in home
|
||||
|
||||
|
||||
# --- Reply threads (v2.20.2) ------------------------------------------------------
|
||||
|
||||
def test_thread_members_follow_replies_to_replies():
|
||||
from starpunk.backfeed import thread_members
|
||||
posts = [ # newest first, as Threads lists them
|
||||
{"id": "c", "parent": "b", "own": False},
|
||||
{"id": "b", "parent": "a", "own": True},
|
||||
{"id": "x", "parent": "self", "own": False},
|
||||
{"id": "self", "parent": "COPY", "own": True},
|
||||
{"id": "a", "parent": "COPY", "own": False},
|
||||
{"id": "loop", "parent": "loop", "own": False},
|
||||
]
|
||||
assert thread_members(posts, "COPY") == {"a": None, "b": "a", "c": "b"}
|
||||
|
||||
|
||||
def test_bluesky_client_reads_nested_replies():
|
||||
me, post = "did:plc:me", "at://did:plc:me/app.bsky.feed.post/abc"
|
||||
|
||||
def view(did, rkey, text, at):
|
||||
return {"uri": f"at://{did}/app.bsky.feed.post/{rkey}", "indexedAt": at,
|
||||
"author": {"did": did, "handle": did.rsplit(":", 1)[1] + ".example"},
|
||||
"record": {"text": text, "createdAt": at}}
|
||||
|
||||
def api(request):
|
||||
nsid = request.url.path.removeprefix("/xrpc/")
|
||||
if nsid == "com.atproto.server.createSession":
|
||||
return httpx.Response(200, json={"did": me, "handle": "me.example", "accessJwt": "a",
|
||||
"refreshJwt": "r"})
|
||||
if nsid in ("app.bsky.feed.getLikes", "app.bsky.feed.getRepostedBy", "app.bsky.feed.getQuotes"):
|
||||
return httpx.Response(200, json={"likes": [], "repostedBy": [], "posts": []})
|
||||
if nsid == "app.bsky.feed.getPostThread":
|
||||
assert int(dict(request.url.params)["depth"]) > 1
|
||||
return httpx.Response(200, json={"thread": {"post": {}, "replies": [
|
||||
{"post": view("did:plc:eve", "r1", "First", "2026-11-10T01:00:00Z"), "replies": [
|
||||
{"post": view(me, "r2", "Thanks", "2026-11-10T02:00:00Z"), "replies": [
|
||||
{"post": view("did:plc:eve", "r3", "Anytime", "2026-11-10T03:00:00Z")}]}]},
|
||||
{"post": view(me, "self", "More from me", "2026-11-10T00:30:00Z")}]}})
|
||||
if nsid == "app.bsky.actor.getProfiles":
|
||||
return httpx.Response(200, json={"profiles": []})
|
||||
return httpx.Response(400, json={"error": "Unknown"})
|
||||
|
||||
bsky = BlueskyClient("https://bsky.example", "me.example", "pw",
|
||||
http=httpx.Client(transport=httpx.MockTransport(api)))
|
||||
replies = [(r.remote_id.rsplit("/", 1)[1], r.parent_id and r.parent_id.rsplit("/", 1)[1], r.own)
|
||||
for r in bsky.responses(post, "https://bsky.app/profile/me.example/post/abc").responses]
|
||||
assert replies == [("r1", None, False), ("r2", "r1", True), ("r3", "r2", False)]
|
||||
|
||||
|
||||
def test_reply_threads_are_stored_and_shown_nested(app, client):
|
||||
app.config["WEBMENTION_ENABLED"] = True
|
||||
note, _ = crossposted(app)
|
||||
first, mine, answer = reply(1, "It keeps coming up"), reply(2, "That is terrifying"), reply(3, "To be fair")
|
||||
mine.parent_id, mine.own, mine.author_name = "1", True, "philskents"
|
||||
answer.parent_id = "2"
|
||||
client.harvest = Harvest([first, mine, answer])
|
||||
run(app)
|
||||
|
||||
stored = {r["remote_id"]: r for r in rows(app, note.id)}
|
||||
assert [stored[i]["parent_remote_id"] for i in "123"] == [None, "1", "2"]
|
||||
assert stored["2"]["notified_at"], "our own reply is no news to us"
|
||||
assert not stored["1"]["notified_at"]
|
||||
|
||||
page = app.test_client().get(f"/note/{note.slug}").data.decode()
|
||||
assert "3 Replies" in page
|
||||
# Each answer sits inside the reply it answers
|
||||
outer = page.index("It keeps coming up")
|
||||
assert outer < page.index('class="webmention-thread"') < page.index("That is terrifying") \
|
||||
< page.index("To be fair")
|
||||
assert page.count('class="webmention-thread"') == 2
|
||||
|
||||
import mf2py
|
||||
items = mf2py.parse(doc=page, url=f"{SITE}/note/{note.slug}")["items"]
|
||||
entry = next(i for i in items if "h-entry" in i["type"])
|
||||
(comment,) = entry["properties"]["comment"]
|
||||
(nested,) = comment["properties"]["comment"]
|
||||
assert "terrifying" in json.dumps(nested) and "To be fair" in json.dumps(nested["properties"]["comment"])
|
||||
Reference in new issue
Block a user