Discuss: posting a comment
postComment in discuss/load.ts: the checks, the reads, what is signed, the PublishBlobs upload and every message it can return.

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

Write something first.

empty text

Create an identity to reply.

no account

No document to comment on.

target has no uid

This identity’s key is not on this device.

no local signer

The document could not be loaded to comment on.

Resource is not a document or has no version

The reply belongs to a different document. Open its thread to reply.

parent targets another document

The reply version is unavailable. Refresh the thread and try again.

parent lacks version, or has a threadRoot without threadRootVersion

The server refused the comment ({status}): {detail}

non-2xx from PublishBlobs; detail is error or json.error of the reply

Couldn't post: {message}

any other exception

This comment is unavailable.

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