feat(chat): people's read receipts beside agents', and a reciprocal DM setting

Merged
RA
4d ago
+647-29

What

The "seen" faces under messages now show the people who read, not only the agents, in the same stack and spot, with the same "one seen per run" rule. You never see your own face. The popover says "Visto por Bruno Lima e Claude Code de Ana Souza", with a little more room under that line.

There is also a new setting, Settings › Conta › "Confirmação de leitura", on by default and reciprocal in DMs (as in WhatsApp). The server enforces it.

Why

Valls: "queria ter o read não só dos agents, mas dos users também".

Root cause: the faces come from the room's receipts list (Book.receiptsList, now receiptsFor). Until now it was filled only from agents' cursors (src/agent.ts → Book.receipt). People's read points were stored only in D1 human_reads, for the unread dots, and never reached the room. Nothing in the UI filtered people out; the room never received their reads.

What changed

  • Server, read point: Book.markRead runs when someone opens the room, and for everyone who has the room open when a message lands. It now also writes that person's read point as a receipt (p:<email>, read = delivered: an open room is what they saw).
    • It rides the existing coalesced receipts push (at most one every ~2s per room), so scrolling or a burst of posts doesn't spam.
    • The list goes out only on the room's member sockets.
    • People have their own limit (50), so they can't push agents out of the 20 agent rows.
  • Client (messageFooters, MessageFooter):
    • A person's face never sits on their own message, and yours is never shown.
    • People come before agents, read before delivered.
    • A person's face has no agent badge.
    • The "one seen per run" rule can move a face past where the person read. Then the popover says "leu em parte" instead of "recebeu".
  • Setting: users.read_receipts (ALTERS), returned in /api/me as read_receipts, saved by POST /api/me/read-receipts. The toggle is in Settings › Conta, with a one-line explanation.
    • In a DM, if either person has it off, receiptsFor drops every person's read point. This covers the snapshot, the light /room read and every push.
    • Changing the setting re-pushes the receipts of all your DMs, so the other person's tab updates at once.
    • Rooms ignore the setting. Agents' reads are never hidden.

Checks run

  • bun run check: pass (after rebasing on main)
  • bun test --conditions=browser scripts/ui-panels.test.ts: 171 pass. New: a stack with people and agents (no badge on a person, not yourself, names in the popover, the live move) and the setting toggle (saves, goes back when saving fails)
  • bun test scripts/chat.test.ts scripts/read-receipts.test.ts: pass. New: placement and order of people's faces; server tests for person receipts, the DM reciprocal rule, and rooms ignoring the setting
  • bun run test:design-system: pass (gallery and inbox)
  • bun run screens -- --hover --receipts --publish: pass. The new --receipts flag fails if a message doesn't have the faces it should. It shares the test-agent OAuth setup with --choices (connectTestAgent).

Router bench

not touched

Deliberate decisions

none

Screens

room-1440.png
hover-1440.png
receipts-person-agent-1440.png
receipts-popover-1440.png
receipts-live-before-1440.png
receipts-live-after-1440.png
receipts-390.png
receipts-setting-1440.png
receipts-dm-off-1440.png
receipts-dm-on-1440.png
room-390.png
home-390.png
home-new-390.png
home-new-drag-390.png
home-new-scrim-drag-390.png

The popover in these screens opens over earlier lines. On a room's first message it opens upward and the chat column clips it; that was already true for agents' popovers before this change. The screens close the "Começando a sala" card first, as a used room has it.

🤖 Generated with Claude Code


Summary by cubic

Shows people's read receipts in the seen stack under messages, next to agents', and adds a reciprocal DM read-receipts setting.

  • Book.markRead now writes a person's open-room point as a receipt, riding the existing coalesced receipts push.
  • The footer shows one face per person: never your own, never on their own message, people before agents, no agent badge; the popover reads "Visto por Ana, Bia e Claude de Ana".
  • New Settings › Conta toggle "Confirmação de leitura" (on by default) returns read_receipts in /api/me and saves via POST /api/me/read-receipts.
  • In DMs, either person off makes the server drop everyone's person read points; toggling re-pushes all your DMs. Rooms ignore it and agents' reads stay.
  • Adds --receipts screens and tests for placement, the stack, and the DM rule.