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
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [2.20.2] - 2026-11-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- Replies to replies on crossposts were never captured. Backfeed read only the first level of replies (Threads `/replies`, GoToSocial's direct replies, Bluesky at depth 1). It now reads the whole conversation (Threads `/conversation`, every GoToSocial descendant, Bluesky ten levels deep)
|
||||
- Your own replies in those conversations were skipped, so the other side of a back-and-forth was missing. They are now kept when they answer someone's reply (a reply to your own crosspost is the thread continuing, and is still left out). They don't send you notifications
|
||||
|
||||
### Changed
|
||||
|
||||
- Replies are shown nested under the reply they answer, as comments of comments (`u-comment` inside the parent `h-cite`). Migration 026 adds `webmentions.parent_remote_id`. Existing crossposts pick up their threads at their next backfeed check
|
||||
|
||||
## [2.20.1] - 2026-11-13
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# v2.20.2: Backfeed whole reply threads
|
||||
|
||||
## Why
|
||||
|
||||
https://starpunk.thesatelliteoflove.com/note/20261110191424 showed one reply
|
||||
(curiouskatej, via Threads). The Threads conversation had three:
|
||||
|
||||
```
|
||||
curiouskatej: "It keeps coming up on music compilations…" (kept)
|
||||
└ philskents: "That is terrifying..." (missed)
|
||||
└ curiouskatej: "To be fair it's just as bad as…" (missed)
|
||||
```
|
||||
|
||||
Each client read only the first level of replies: Threads `/{id}/replies`,
|
||||
GoToSocial descendants with `in_reply_to_id == our id`, and Bluesky
|
||||
`getPostThread` at depth 1. All of them also dropped the owner's own replies,
|
||||
which lost one side of the conversation.
|
||||
|
||||
## Changes
|
||||
|
||||
| Area | Change |
|
||||
|---|---|
|
||||
| `backfeed.thread_members(posts, root)` | Decides which replies to keep, and what each answers. Kept: others' replies to our copy, plus any reply (ours too) to a kept reply. Our own replies to our copy are the thread continuing, so they and their replies are left out, as before |
|
||||
| `Response.parent_id`, `.own` | The silo id of the reply this one answers (None for our copy itself), and whether we wrote it |
|
||||
| Threads | `/{id}/conversation` (every depth, newest first) with `replied_to` in the fields |
|
||||
| GoToSocial | All public descendants from `/context` |
|
||||
| Bluesky | `getPostThread` depth `BLUESKY_THREAD_DEPTH` (10), walked recursively; blocked or deleted posts drop their subtree |
|
||||
| Migration 026 | `webmentions.parent_remote_id` |
|
||||
| `backfeed.store` | Stores the parent; own replies are stored as already notified |
|
||||
| `webmention_queries.reply_threads` | Nests replies under their parent (same origin and remote id). A reply whose parent isn't shown goes to the top level |
|
||||
| Templates/CSS | `responses.reply` renders children in `.webmention-thread`, indented with a side rule, as `u-comment h-cite` inside the parent's h-cite |
|
||||
|
||||
The heading still counts every reply ("3 Replies"), and so does the count
|
||||
line under the note.
|
||||
|
||||
Existing crossposts get their threads at their next scheduled check. The
|
||||
check schedule slows with the note's age (ADR-073), and notes past the
|
||||
cutoff aren't checked.
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Migration 026: Threads of backfed replies (v2.20.2)
|
||||
-- parent_remote_id: the silo id of the response a reply answers; NULL when it
|
||||
-- answers our crosspost itself. Replies are shown nested under their parent.
|
||||
ALTER TABLE webmentions ADD COLUMN parent_remote_id TEXT;
|
||||
@@ -484,5 +484,5 @@ def create_app(config=None):
|
||||
|
||||
# Package version (Semantic Versioning 2.0.0)
|
||||
# See docs/standards/versioning-strategy.md for details
|
||||
__version__ = "2.20.1"
|
||||
__version_info__ = (2, 20, 1)
|
||||
__version__ = "2.20.2"
|
||||
__version_info__ = (2, 20, 2)
|
||||
+33
-3
@@ -58,6 +58,34 @@ class Response:
|
||||
opted_out: bool = False # set by the client from silo-specific signals
|
||||
content_html: Optional[str] = None
|
||||
published: Optional[str] = None
|
||||
# Replies in a thread (v2.20.2): the silo id of the response this one
|
||||
# answers (None: our copy itself), and whether we wrote it
|
||||
parent_id: Optional[str] = None
|
||||
own: bool = False
|
||||
|
||||
|
||||
def thread_members(posts: List[dict], root: str) -> Dict[str, Optional[str]]:
|
||||
"""
|
||||
Which replies under one of our copies to keep, and what each answers
|
||||
(v2.20.2). `posts` are {'id', 'parent', 'own'} for every reply in the
|
||||
conversation, in any order. Kept: others' replies to our copy, and any
|
||||
reply (ours too) to a kept reply. Our own replies to our copy are the
|
||||
thread continuing, not responses. Returns {id: parent id or None}.
|
||||
"""
|
||||
kept: Dict[str, Optional[str]] = {}
|
||||
pending = list(posts)
|
||||
while True:
|
||||
rest = []
|
||||
for post in pending:
|
||||
if post["parent"] == root and not post["own"]:
|
||||
kept[post["id"]] = None
|
||||
elif post["parent"] in kept and post["parent"] != post["id"]:
|
||||
kept[post["id"]] = post["parent"]
|
||||
else:
|
||||
rest.append(post)
|
||||
if len(rest) == len(pending):
|
||||
return kept
|
||||
pending = rest
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -292,9 +320,9 @@ def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest,
|
||||
INSERT INTO webmentions (
|
||||
source_url, target_url, target_note_id, mention_type, author_name, author_url,
|
||||
author_photo, content_snippet, validation_status, moderation_status,
|
||||
validated_at, source_published, origin, remote_id, notified_at)
|
||||
validated_at, source_published, origin, remote_id, notified_at, parent_remote_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'valid', ?, CURRENT_TIMESTAMP, ?, ?, ?,
|
||||
CASE WHEN ? THEN CURRENT_TIMESTAMP END)
|
||||
CASE WHEN ? THEN CURRENT_TIMESTAMP END, ?)
|
||||
ON CONFLICT(source_url, target_url) DO UPDATE SET
|
||||
target_note_id = excluded.target_note_id,
|
||||
mention_type = excluded.mention_type,
|
||||
@@ -305,6 +333,7 @@ def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest,
|
||||
source_published = COALESCE(excluded.source_published, webmentions.source_published),
|
||||
origin = excluded.origin,
|
||||
remote_id = excluded.remote_id,
|
||||
parent_remote_id = excluded.parent_remote_id,
|
||||
validation_status = 'valid',
|
||||
validation_error = NULL,
|
||||
validated_at = CURRENT_TIMESTAMP,
|
||||
@@ -312,7 +341,8 @@ def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest,
|
||||
""",
|
||||
(r.source_url, target_url, note_id, r.kind, r.author_name or None, r.author_url or None,
|
||||
r.author_photo or None, snippet, moderation, r.published, origin, r.remote_id,
|
||||
1 if quiet else 0),
|
||||
# Our own replies in a thread are no news to us
|
||||
1 if quiet or r.own else 0, r.parent_id),
|
||||
)
|
||||
if dropped:
|
||||
marks = ",".join("?" * len(dropped))
|
||||
|
||||
+53
-24
@@ -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
|
||||
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):
|
||||
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 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}",
|
||||
|
||||
@@ -107,9 +107,32 @@ def get_webmentions_for_note(note_id: int) -> Dict[str, List[Dict[str, Any]]]:
|
||||
else:
|
||||
grouped['mentions'].append(wm)
|
||||
|
||||
grouped['reply_threads'] = reply_threads(grouped['replies'])
|
||||
return grouped
|
||||
|
||||
|
||||
def reply_threads(replies: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Replies nested under the replies they answer (v2.20.2): each gets
|
||||
'children'; the top-level ones are returned. A reply whose parent isn't
|
||||
shown (hidden, removed) is shown at the top level.
|
||||
"""
|
||||
by_id = {}
|
||||
for wm in replies:
|
||||
wm['children'] = []
|
||||
if wm.get('remote_id'):
|
||||
by_id[(wm.get('origin'), wm['remote_id'])] = wm
|
||||
top = []
|
||||
for wm in replies:
|
||||
parent = by_id.get((wm.get('origin'), wm.get('parent_remote_id'))) \
|
||||
if wm.get('parent_remote_id') else None
|
||||
if parent is not None and parent is not wm:
|
||||
parent['children'].append(wm)
|
||||
else:
|
||||
top.append(wm)
|
||||
return top
|
||||
|
||||
|
||||
def response_counts(note_ids: List[int]) -> Dict[int, Dict[str, int]]:
|
||||
"""
|
||||
Likes, reposts, replies and quotes per note, for lists of notes
|
||||
|
||||
@@ -391,6 +391,10 @@ small { display: block; margin-top: var(--spacing-xs); color: var(--color-text-l
|
||||
.webmention-reply .webmention-date::after { content: ""; position: absolute; inset: 0; }
|
||||
.webmention-reply .webmention-author a, .webmention-reply .e-content a { position: relative; z-index: 1; }
|
||||
.webmention-reply:hover { cursor: pointer; }
|
||||
/* Replies to replies (v2.20.2): nested, with a line down the side */
|
||||
.webmention-thread { position: relative; z-index: 1; margin-top: var(--spacing-sm); padding-left: var(--spacing-md); border-left: 2px solid var(--color-border); }
|
||||
.webmention-thread .webmention-reply { margin-bottom: var(--spacing-sm); padding: var(--spacing-xs) 0 var(--spacing-xs) var(--spacing-xs); background: none; }
|
||||
.webmention-thread .webmention-reply:last-child { margin-bottom: 0; }
|
||||
|
||||
/* Counts in lists of notes (v2.13.4) */
|
||||
.list-counts { display: inline-flex; gap: 0.6rem; color: var(--color-text-light); }
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@
|
||||
{% if replies %}
|
||||
<div class="webmention-group webmention-replies">
|
||||
<h3>{{ replies|length }} {{ 'Reply' if replies|length == 1 else 'Replies' }}</h3>
|
||||
{% for wm in replies %}{{ responses.reply(wm) }}{% endfor %}
|
||||
{% for wm in reply_threads or replies %}{{ responses.reply(wm) }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
</a></span>
|
||||
{%- endmacro %}
|
||||
|
||||
{# A reply, shown as a comment #}
|
||||
{# A reply, shown as a comment; replies to it are nested inside, as
|
||||
comments of the comment (v2.20.2) #}
|
||||
{% macro reply(wm) %}
|
||||
<article class="webmention webmention-reply u-comment h-cite">
|
||||
<div class="webmention-author">{{ author_card(wm) }}</div>
|
||||
@@ -38,6 +39,11 @@
|
||||
<div class="e-content">{{ wm.content_snippet|safe }}</div>
|
||||
{% endif %}
|
||||
<a class="u-url webmention-date" href="{{ response_url(wm) }}">{{ response_time(wm) }}</a> {{ via(wm) }}
|
||||
{% if wm.children %}
|
||||
<div class="webmention-thread">
|
||||
{% for child in wm.children %}{{ reply(child) }}{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</article>
|
||||
{%- endmacro %}
|
||||
|
||||
|
||||
+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