src/discuss/logic.ts is pure: "No clock, no randomness, no fetch." It takes what listComments returns and produces the rows the screens draw. Keeping it pure lets Bun tests run it against a captured production answer.
Types
Type | Fields |
|---|---|
The API's comment: | |
uid to | |
| |
| |
|
Hrefs and ids
threadHref(commentId): author/tsid to /c/{author}/{tsid}.
composeHref(ref), commentsHref(ref): /compose/{ref} and /comments/{ref}.
pathSegments(p): a comment's targetPath ("", /a/b or a/b) to segments.
targetIdJson(uid, path): the UnpackedHypermediaId object the API's targetId= parameter wants, in schema key order: id, uid, path (or null), version, blockRef, blockRange, hostname, scheme (all null), latest: true. See Seed site read API.
It re-exports docHref, refOf and parseRef from read's ids.
Rows
rowOf(c, authors, server, depth, replies, parentName) builds one CommentRow:
name from authorName: the trimmed profile name, else the short id.
avatar through mediaUrl at size S.
at from timeMs, which accepts an ISO string, a Date, a number or {seconds}.
md from commentMarkdown.
commentMarkdown runs the comment's blocks through read's blocksToRows and joins the rows into one Markdown string with blank lines between them: text, headings and tables as they are (indented two spaces per depth, with the list marker), code and math inside a fence at least three backticks long and longer than any run in the body, images and embeds as links. The bubble renders it with markup="markdown".
isPublic(c) drops any comment whose visibility contains PRIVATE.
Summary of a document's discussion
summarize(key, ref, comments, authors, server):
count is the number of public comments, replies included.
threads are the comments without a threadRoot, each with its reply count.
Order: newest activity first, where a thread's activity is the latest createTime among its root and replies. Ties break by id.
A thread in reading order
threadRows(rootId, comments, authors, server) returns "the root, then each reply under the comment it answers (depth-first, oldest first)".
Members are public comments whose threadRoot is the root.
"A reply whose parent is missing hangs off the root."
Depth starts at 1 for direct replies and is capped at MAX_DEPTH = 4.
parentName is set when the parent is not the root, to "show who a reply answers when indentation alone can't".
The root row's replies is the member count; each reply's is its direct children.
Returns an empty list when the root is not among the comments; loadThread then falls back to direct lookups.
Reply versions
replyVersions(parent) returns what a reply to parent signs:
replyCommentVersion = parent.version
rootReplyCommentVersion = parent.threadRootVersion || parent.version
The comment marks this as a fix over the React Native app: "a reply attaches to the tapped comment". The values become the Comment blob's replyParent and threadRoot CIDs, see Crypto: changes, refs, comments and profiles and the history page.
paragraphContent(text) is the single-paragraph body the composer sends: one Paragraph block with id c1.
Tests
logic.test.ts has 6 Bun tests. The summary test runs on hypermedia-home-comments.json, a captured ListComments answer for the hyper.media home. The others cover ordering by latest activity and dropping private comments, nesting oldest first, the reply target and thread root, signing a reply to a reply (replyParent is that reply, threadRoot is the root), and ids and Markdown. See Bun unit tests.
User stories
The code described here exists to deliver these stories. Each story lists this page in its Trace (traceability).
US-DISC-01 See the discussion on a document: summarize: public comments, thread order, reply counts
US-DISC-02 Read a thread: threadRows: nesting, order, depth cap, parent names; commentMarkdown
US-DISC-03 Comment on a document: paragraphContent and threadHref
US-DISC-04 Reply in a thread: replyVersions and how the new reply nests
US-APP-06 See people and spaces by name: Comment author names and reply targets
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime