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 |
|---|---|---|
|
|
|
|
|
|
|
|
|
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 |
|---|---|
| |
A route or document target to a plain ref. | |
Dedupes non-empty targets and returns one | |
Looks up the comment ( | |
Dedupes ids containing |
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