Content: replies
A reply is an article entry whose reply-to names the blob ID of the article it answers (Replies). Three operations of the content device (device 4) and one form of publish let a program show and write them: replies asks the relays for the replies to an article, article tells which entry published an article the host holds, write a reply hands the user the host's own screen for publishing one, and publish in reply publishes one itself. They use the same request block, submit call, handles, completion rules and statuses as the other operations; "Content: blobs, requests and statuses" and "Content: feeds, names, search and publishing" come before this article.
op | Operation | C helper | Consent |
|---|---|---|---|
17h | Replies | content_replies, content_replies_has_more | no |
18h | Article | content_article | no |
19h | Write a reply | content_write_reply | no |
07h | Publish, in reply (offset 100h or 101h) | content_publish_reply | yes |
A host with only the machine's reading profile may complete all four with 05h without carrying them out.
Replies (17h)
content_replies(r, article, buf, len). id is the blob ID of the article (all zeros: a bad request). offset is 0 for the first page, 1 for the next (any other value: a bad request); length is the size of the buffer at addr, 1 to 16,384, in RAM. size is not read.
On completion the buffer holds the replies as timeline records ("Content: feeds, names, search and publishing", Timeline; only flag bit 0 may be set): article entries whose reply-to is id, as many whole records as fit. They are merged from all the host's relays, verified, one per feed and seq, in the order the relays give them, ranked as for a find of articles. length is the bytes delivered, size the number of replies (at most 16), and offset 1 if the host has more to give, else 0 (content_replies_has_more(r)).
So the next page is the completed block submitted again, content_submit(r), with length set back to the buffer's size (completion wrote the bytes delivered there). offset 1 gives up to 16 replies to that id that the machine's replies requests since its last offset 0 did not deliver.
| Case | Status |
|---|---|
| replies merged (possibly none) | 01h |
offset 1 and the host holds no such request with more to give (none was made, the last had no more, or the host no longer holds it) | 02h |
| no relay answered and at least one refused (asked too often) | 05h |
| otherwise, no relay could be asked or none answered | 03h |
A host keeps at least the machine's last replies request. It does not store the replies' entries: a program that shows one gets its blob with get, by the record's blob ID. Which replies to show is the program's choice; anyone can reply to anything. The reference reader shows those of the feeds the user follows (the subscriptions, 03h) and keeps the others folded away.
Article (18h)
content_article(r, blob, buf, len): which entry published an article the host holds, to show what a reply answers. id is a blob ID (all zeros: a bad request); length and addr are a buffer, 1 to 16,384 bytes, in RAM; offset and size are not read. It completes from the host's own state, without the network, with one timeline record: that of an article entry (kind 1) of a subscribed feed whose blob is id (of several, the one the host stored first), size 1 and length the bytes delivered. With none, status 02h: show the article by its link, terse: and the ID.
Write a reply (19h)
content_write_reply(r, article): asks the host to let the user write a reply to the article whose blob ID is id (all zeros: a bad request). offset, length, addr and size are not read.
A host with a screen of its own for publishing, which no program can see (the reference host's F10 Publish page), opens it with that article as the one replied to and completes with 01h once it is shown. The user then chooses a file, previews and publishes it, or leaves, as on that screen at any time; the program is told nothing more, and a published reply reaches it like any entry. A host without such a screen, or a headless one, completes with 05h: say how else to reply, for example terse feed publish <file> --title <t> --reply-to terse:<id>. It needs no consent, since it publishes nothing.
This is how a program that cannot hold the user's text (a reader is a sandboxed program) lets them reply.
Publish in reply (07h)
content_publish_reply(r, blob, buf, len): a publish whose offset is the kind plus 100h, 100h or 101h, an article in reply. buf holds the title, len bytes (0 to 120), then at once the 32-byte blob ID of the article replied to, in the same memory (wholly in ROM or wholly in RAM), copied at submit; length is the title's length. An all-zero reply-to, or one not in the same memory, is a bad request. CONTENT_PUBLISH_REPLY (100h) is the value added to the kind.
Otherwise it is a publish: the blob must be in the host's store (else 02h), the host asks the user and the prompt says what the reply answers (the article's title and feed, if the host holds its entry, else the short form of its ID), and on success size is the new entry's seq. The 32 bytes are charged with the title, 1 unit per 4 bytes.
Example: count the replies
#include "terse.h" static content_req req; static uint8_t buf[4096]; static uint32_t total; /* article: the 32-byte blob ID of an article. */ void ask(const uint8_t *article) { total = 0; content_replies(&req, article, buf, sizeof buf); } /* Called after a content-done event for this request. */ void on_done(void) { if (req.status != STATUS_DONE) return; total += req.size; if (content_replies_has_more(&req)) { req.length = sizeof buf; /* the next page */ content_submit(&req); } }
Each record in buf is a timeline record; its byte 2 + 44 on is the reply's blob ID, to get and show it.