Files
Amicitia-Tabellarius/.agents/features/reactions-replies.md
T

7.7 KiB
Raw Blame History

Reactions and replies — two payloads, and messages that can be named (PROTOCOL.md §4)

Amicitia F27, step 2 of its full-chat plan (Amicitia/.agents/features/full-chat.md §2). Everything here is inside MLS: the relay's view (§5, §8) does not change. No new route, no new column.

1. Why and what

A chat people move to needs the two smallest things every messenger has: a reaction on a message (👍, ❤️, 😂 …) and a reply that quotes the message it answers. Both need a message to have a name both sides agree on. Today a text carries a seq, but the receiving app is never told it, and nothing says whose seq.

So this change:

  1. names every message by (author, seq): the author's 16-byte MLS credential identity (random, made on the device, already in every credential, never a name) and the author's own seq;
  2. adds replyTo to text, and a new payload reaction;
  3. tells the app a received message's seq, and both identities, so it can store and name messages;
  4. turns a payload of a kind this client does not know that carries a seq into an event Unsupported, so a later kind (polls, files, stickers) shows Update the app to see this message instead of vanishing. Today such a payload fails to parse and is dropped without a trace.

2. Design

sequenceDiagram
    participant A as Anna's app
    participant C as Client (Anna)
    participant R as Relay
    participant D as Client (Ben)
    participant B as Ben's app
    A->>C: compose_text(ben, "lunch?", None) → seq 7
    C->>R: MLS blob {"kind":"text","body":"lunch?","seq":7}
    R->>D: fetch
    D->>B: Message{seq 7, reply_to: None}; B names it (Anna, 7)
    B->>D: react(anna, (Anna, 7), Some("👍"))
    D->>R: MLS blob {"kind":"reaction","to":{"author":"…","seq":7},"emoji":"👍"}
    R->>C: fetch
    C->>A: Reaction{to (Anna, 7), emoji "👍"}

2.1 The payloads

{"kind":"text","body":"…","seq":8,"replyTo":{"author":"<22 chars>","seq":7}}
{"kind":"reaction","to":{"author":"<22 chars>","seq":7},"emoji":"👍"}
{"kind":"reaction","to":{"author":"<22 chars>","seq":7}}
  • MessageRef {author, seq}: author is unpadded base64url of 16 bytes (the protocol crate's new Author, like MailboxId); seq ≥ 1.
  • text.replyTo is optional; without it a text is byte-for-byte today's.
  • reaction: emoji present sets the sender's reaction to that message (replacing their earlier one); absent removes it. One reaction per person per message is the app's rule, and the wire makes it the only one expressible: there is no "add a second". emoji is 1–32 bytes of UTF-8 with no control characters (the longest emoji ZWJ sequences are 28 bytes). Which emoji are offered is the app's choice; the client does not keep a list, so a newer app's emoji still arrives.
  • A reaction carries no seq: it is not a message, it cannot be replied to or reacted to, and a receipt does not cover it.

2.2 What the receiving client checks

A reference names a message only if its author is one of the two members of this conversation and its seq is one that exists: ≤ our sent_seq when it names ours, ≤ their highest seq received when it names theirs (blobs from one sender arrive in order, so their message is always before a reaction to it).

Received Bad reference Result
reaction author not a member, seq 0, or a seq that does not exist yet dropped, never shown (like any blob that does not make sense)
reaction emoji empty, over 32 bytes, or with a control character dropped
text with replyTo as above the text is shown, without the reference: the words are real, only the quote is not
unknown kind with a seq ≥ 1 — Unsupported{seq}; counts for receipts like a text
unknown kind without a seq, or not JSON — dropped, as today
A blocked contact's reactions and unsupported items are dropped, as their texts are.

2.3 The client's API (Amicitia pins it)

  • Event::Message gains seq: u64 and reply_to: Option<MessageRef>.
  • New Event::Reaction { contact, to: MessageRef, emoji: Option<String> }.
  • New Event::Unsupported { contact, seq }.
  • Client::author() -> Author (ours) and Client::contact_author(contact) -> Option<Author> (theirs, read from the MLS group's other member — nothing new in the snapshot).
  • Client::compose_text(contact, text, reply_to: Option<MessageRef>); compose(contact, text) stays and means compose_text(…, None). A reply whose reference fails §2.2's check on our own side is refused with ClientError::BadReference before anything is sealed.
  • Client::react(contact, to: MessageRef, emoji: Option<&str>) -> Outgoing; the same checks, and ClientError::TooLong / BadReference for a bad emoji.

2.4 An older client

A client before this change has deny_unknown_fields on text and no reaction: a reply or a reaction fails to parse there and is dropped (acknowledged, never shown). Nobody runs Amicitia outside development yet; from this change on, unknown kinds degrade to Unsupported. Unknown fields in a known kind still fail (deny_unknown_fields stays: a field the receiver ignores could change what the sender meant). So a later change that adds a field to text would make older clients drop those texts without a trace; new fields therefore go into new kinds, which older clients show as Unsupported. PROTOCOL.md §4 says so.

3. Risks

  • Privacy: members (the two people) learn the emoji and which message; they already see every message. The relay sees one more blob. A reaction's blob is small (about the size of a one-word text) — the relay could guess "a reaction or a very short text", which it can already do for short texts; padding is G41's later work. Stated in §5's note on sizes.
  • Integrity: a reaction can only come from a member (MLS authenticates the sender), so nobody else can react in someone's name. A member can react to a message that exists only; they cannot reference a message from another conversation (different authors).
  • Events (Amicitia): none — reactions are not check-ins (full-chat §4).
  • Offline: as every payload: staged, posted after the snapshot is saved.

4. Gaps and designed solutions

Gap Design
Unknown kinds vanish today Unsupported{seq} (§2.2)
A known kind with new fields fails on older clients New fields go into new kinds (§2.4), written into PROTOCOL.md §4
Reaction blobs are small (size leak) Same as short texts today; padding to buckets is G41's (later)
A reaction to a message the receiver deleted The client cannot know; the app drops reactions to messages it does not have

5. Verification

Case Test
A reply arrives with its reference; the app is told seq and both authors match client/tests/reactions.rs
A reaction sets, replaces and removes (emoji absent) same
A reaction to a seq that does not exist, or by a non-member author, is dropped unit test through receive_payload
A reply with a bad reference is shown without the reference unit test
Emoji empty, 33 bytes, or with a control character: refused when composing, dropped when received unit + integration
An unknown kind with a seq → Unsupported, and a receipt covers it; without seq → nothing unit test
A blocked contact's reaction is dropped integration
compose unchanged on the wire (no replyTo key) unit test on the JSON
The relay's database holds no emoji and no reply text (canary) real_relay.rs, client/tests/state.rs
Author parses only canonical 22-char base64url of 16 bytes protocol unit + proptest
Planted bugs the review