postComment in src/discuss/load.ts is the only write in the discuss package. It is called by the discussPost source for both a new top-level comment and a reply.
Steps
postComment(store, server, account, target, parentId, text, nowMs) returns {ok, error, value} and never throws:
Refuse an empty body, a missing account, or a target with no uid.
signerFor(store, account) from Identity; refuse when the key is not on the device.
GET /api/Resource for the document to read its current version.
For a reply, fetch the parent comment and check that it targets the same document and has the versions needed.
Build and sign with createComment from Crypto: changes, refs, comments and profiles: timestampMs (rounded nowMs), docId {uid, path}, docVersion, a one-paragraph content, and the reply versions from replyVersions.
POST {server}/api/PublishBlobs with Content-Type: application/cbor, a DAG-CBOR body {blobs: [{cid?, data}]} and exactTimeout: 15000 (Publishing signed blobs).
On success compute the comment's record id with commentRecordIdFromBlob, call forget(server, ref) and return value = the thread href /c/{author}/{tsid}.
Messages shown to people
Message | Cause |
|---|---|
| empty text |
| no account |
| target has no uid |
| no local signer |
|
|
| parent targets another document |
| parent lacks |
| non-2xx from PublishBlobs; detail is |
| any other exception |
| the reply's parent could not be looked up |
Tests
Four of the six tests in load.test.ts cover posting: a parent from another document is refused before signing or publishing; a nested parent without a root version is refused; a corrupt signing key returns a safe refusal; a valid nested reply sends the current document, parent and root versions with a 15000 ms deadline. The Contract test "post a comment and replies on dev.hyper.media with a throwaway key" runs it end to end (Discuss: screens and components).
Known limits
Comments are one plain paragraph: no formatting, mentions, attachments, quotes or private visibility from the composer.
No optimistic row. The new comment appears when the refreshed listing (or the direct lookup) returns it.
No retry. A failed post keeps the draft so the person can send again.
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime