Show the author's own chain on Bluesky and Threads
CI / Typecheck, test, build (pull_request) Successful in 46s
CI / Typecheck, test, build (pull_request) Successful in 46s
People write in chains on both, and a link into one arrives pointing at a single post out of several. Showing only that post loses the thing that was being said. Other people's replies are a different matter: they are a conversation rather than the thing that was shared, and on a busy post there are hundreds of them. A Post is now a list of Segments instead of one body. Most platforms produce exactly one and say so through oneSegment(); the two that thread produce the whole chain, with isAnchor marking the post that was actually linked, which need not be the first. Bluesky walks parent upward and the author's own replies downward, stopping at the first post by anyone else. That needs depth and parentHeight on getPostThread, which drags the entire reply tree along -- a few hundred KB on a popular post -- because there is no way to ask the API for one author's branch. Threads is harder to read. The page ships the linked post, the author's follow-ups, other people's replies and a pile of unrelated recommendations, all as flat thread_items containers with no nesting to go on. What separates a follow-up from a stranger's reply is that a follow-up is the author replying to themselves; a reply from someone else carries the same reply_to_author with a different name on it. The first post of a chain replies to nothing at all, so it is reachable only by walking backwards from the post that answers it -- a test caught that, when linking the second post of a thread returned just the one post. Fixtures for both are real captures. The Bluesky one keeps two of every level's outside replies rather than pruning them away, because a filter is only worth testing against the thing it is supposed to exclude. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BGkRmLfiWuJHx6tQ12EELY
This commit is contained in:
+28
-4
@@ -40,6 +40,22 @@ export type Author = {
|
||||
avatar?: Asset;
|
||||
};
|
||||
|
||||
/**
|
||||
* One post. Usually a whole `Post` is a single segment, but on the platforms
|
||||
* where people write in chains — Bluesky and Threads — the author's own
|
||||
* follow-ups belong with the one that was linked, and other people's replies
|
||||
* do not.
|
||||
*/
|
||||
export type Segment = {
|
||||
text?: string;
|
||||
media: Media[];
|
||||
/** ISO 8601. */
|
||||
postedAt?: string;
|
||||
/** The post the link actually pointed at. Only meaningful when a thread
|
||||
* has more than one segment. */
|
||||
isAnchor?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* The single shape every adapter produces and the renderer consumes. Adding
|
||||
* a platform means producing one of these; nothing downstream changes.
|
||||
@@ -52,15 +68,23 @@ export type Post = {
|
||||
* the copy button hands back. */
|
||||
originalUrl: string;
|
||||
author: Author;
|
||||
text?: string;
|
||||
/** Fixed per platform: the ones that lead with words put the text above
|
||||
* the media, the ones that lead with pictures put it below. */
|
||||
textPosition: 'above' | 'below';
|
||||
media: Media[];
|
||||
/** ISO 8601. */
|
||||
postedAt?: string;
|
||||
/** In the order they were written. Never empty. */
|
||||
segments: Segment[];
|
||||
};
|
||||
|
||||
/** Most platforms have no notion of a chain, so their adapters use this. */
|
||||
export function oneSegment(segment: Segment): Segment[] {
|
||||
return [{ ...segment, isAnchor: true }];
|
||||
}
|
||||
|
||||
/** The segment the link pointed at, or the first one. */
|
||||
export function anchorOf(post: Post): Segment | undefined {
|
||||
return post.segments.find((s) => s.isAnchor) ?? post.segments[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when a post cannot be resolved. Carries enough for the error card
|
||||
* to still be useful: which platform, and the link to hand back.
|
||||
|
||||
Reference in New Issue
Block a user