Discuss: loading and posting
discuss/load.ts and sources.ts: the three sources, listing comments, looking up threads, and the caches and epoch.

src/discuss/load.ts is the network half of the discuss package. It lists a document's comments, resolves a thread from one comment id, and signs and publishes new comments. src/discuss/sources.ts exposes it to the root contract.

Sources

Source

Arguments

Calls

discussList

[server, targets, epoch]

loadDiscussions

discussThreadList

[server, ids, epoch]

loadThreads

discussPost

[server, account, target, parent, text, nowMs], plus the secret store

postComment

epochSeen works like read's: when the epoch for a server changes, forget(server) drops its listings. The second argument every source receives, store, is the secret store that Identity reads keys from; the matching grant in app.ts is secret.keep seed-keys (Grants and capabilities).

Reading

Function

Behaviour

listComments(server, ref)

GET /api/ListComments with targetId = targetIdJson. Returns {comments, authors}. Cached per server and ref; concurrent asks share one request. Each listed comment is also stored in commentCache.

normRef(target)

A route or document target to a plain ref.

loadDiscussions(server, targets)

Dedupes non-empty targets and returns one Discussion each through summarize. A failed listing returns a Discussion with error and no threads, so one failure does not blank the others.

loadThread(server, id)

Looks up the comment (GET /api/Resource?id=hm://author/tsid, expecting type: "comment"), derives the document ref from targetAccount and targetPath, then loads the listing and the document title in parallel and builds rows with threadRows.

loadThreads(server, ids)

Dedupes ids containing /, percent-decodes each, loads each thread.

Two details in loadThread:

    The thread root is threadRoot || id, so opening a reply's id shows the whole thread.

    "The listing may lag a fresh comment: show what we can look up directly." If the root is not in the listing, the root and the comment are fetched individually and shown alone.

The document title comes from ResourceMetadata (docTitle), falling back to the last path segment or Document.

Caches

All caches are module-level Maps keyed with the server (trailing slashes trimmed) and a vertical bar:

    listCache and listInflight: by ref.

    commentCache: by comment id (author/tsid).

    titleCache: by ref.

    generations: a counter per server.

forget(server, ref?) bumps the generation. Without ref it clears the server's listings and titles; with ref only that document's. In both cases it detaches all of the server's in-flight listings and comment records: "In-flight lookups may not yet reveal their target… their generation prevents stale repopulation." Loaders write to a cache only when the generation is unchanged since they started. Failures are never cached.

Posting

postComment signs and publishes a comment. Its steps and every message it can return are in Discuss: posting a comment.

Messages for failed reads

    Couldn't load the discussion.: a read failure that is not a SeedError (client errors pass through as they are).

    This comment is unavailable.: Resource did not return a comment.

Tests

load.test.ts has 6 Bun tests with a mocked fetch: refresh discards in-flight listings and late results; thread refresh invalidates removed comments and changed titles; a reply parent from another document is refused before signing; a nested parent without a root version is refused "not signed into a new thread"; a corrupt signing key gives a safe refusal "rather than throwing its secret"; a valid nested reply sends the current document, parent and root versions.

Known limits

    The listing is fetched whole, with no paging.

    Thread lookups need the comment's author/tsid id; there is no lookup by version.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime