feat: application-level read state and inbox triage for conversations

Conversations were hard to manage because "unread" came straight from
Matrix's notification_count, and nothing in the app ever sends a read
receipt — so opening a conversation in the dashboard could never clear it
and the unread set only ever grew. The list also collapsed three
orthogonal facts into one word, labelling "they spoke last and we have
not replied" as "Up to date".

Read state is now ours:

- conversation_read_state table (migration 19) plus
  ConversationReadStateRepository, kept separate from conversation_states
  so a read write can never be lost to mergeConversationState. The
  watermark is monotonic, so a stale poll cannot resurrect an unread
  badge.
- hasUnreadInbound and needsReply are derived server-side and returned on
  every conversation. Matrix's `unread` stays on the contract but the
  dashboard no longer reads it.
- POST /conversations/{id}/read|unread|status and
  POST /conversations/bulk-read, with optimistic cache updates.

Inbox rework:

- List rows are a real grid (checkbox, open button, chip strip) instead of
  a full-bleed absolute overlay button, which previously forced a
  pointer-events escape hatch for anything interactive in a row. Rows use
  aria-current rather than aria-pressed. Not a listbox: options must not
  contain interactive descendants.
- Counted filter pills replace the select, independent state chips replace
  the collapsed status word, plus a sort control (including oldest
  unanswered), a per-account filter, age-coloured timestamps, and an
  explicit count of rows hidden by the seller filter.
- Keyboard: j/k/arrows, Enter, u, e, / and Escape. Shortcuts yield to any
  open dialog so Escape dismisses the modal, not the conversation behind
  it. Multi-select with bulk mark-read and mark-done.
- Detail panel: auto-mark-read on open, a "New messages" divider pinned at
  mount (deriving it from the live watermark made it vanish a second after
  opening), triage actions in the header, the automation banner moved out
  of the composer, day dividers with time-only stamps, and a flex column
  so history scrolls in its own region instead of painting over the
  composer.
- Row order freezes while a conversation is open, with a "N new — refresh"
  pill, so a background poll cannot reorder rows mid-triage.

Two database tests rewound user_version by an offset from the latest
version, which silently re-targets a different migration whenever one is
appended. They now pin absolute versions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jamie BruntonandClaude Opus 5 committed 2026-08-10 10:06:03 +01:00
1 parent c8689af04d
commit 725b5fc4e6
26 files changed
+2625 -203

No files matched your search

+15 -5
View File
@@ -70,6 +70,12 @@ const server = setupServer(
requestKind: null, assets: [], warning: null,
reason: 'No enabled, unused library images are available to share.',
})),
// Opening a conversation advances the read watermark.
http.post('/api/conversations/:id/read', () => HttpResponse.json({ success: true })),
http.post('/api/conversations/:id/unread', () => HttpResponse.json({ success: true })),
http.post('/api/conversations/:id/status', () => HttpResponse.json({ success: true })),
http.post('/api/conversations/bulk-read', () =>
HttpResponse.json({ success: true, updated: 1, failed: [] })),
);
function installConversationList() {
@@ -139,7 +145,7 @@ describe('ConversationsPage', () => {
expect(screen.getByRole('button', { name: /u\/bob/ })).toBeInTheDocument();
await user.clear(screen.getByRole('searchbox', { name: 'Search conversations' }));
await user.selectOptions(screen.getByRole('combobox', { name: 'Filter conversations' }), 'unread');
await user.click(screen.getByRole('button', { name: /^Unread/ }));
expect(screen.getByRole('button', { name: /u\/alice/ })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: /u\/bob/ })).not.toBeInTheDocument();
@@ -249,7 +255,7 @@ describe('ConversationsPage', () => {
const aliceItem = await screen.findByRole('button', { name: /u\/alice/ });
expect(screen.getByText('Image received')).toBeInTheDocument();
await user.selectOptions(screen.getByRole('combobox', { name: 'Filter conversations' }), 'received-images');
await user.click(screen.getByRole('button', { name: /^Images/ }));
expect(screen.getByRole('button', { name: /u\/alice/ })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: /u\/bob/ })).not.toBeInTheDocument();
@@ -459,13 +465,17 @@ describe('ConversationsPage', () => {
expect(screen.queryByRole('button', { name: 'Start conversation' })).not.toBeInTheDocument();
});
it('shows the unread count and marks unread rows with state and time in the label', async () => {
it('counts each triage bucket on its filter pill and marks unread rows in the label', async () => {
installConversationList();
renderConversations();
const aliceButton = await screen.findByRole('button', { name: /u\/alice/ });
expect(screen.getByText('1 unread')).toBeInTheDocument();
expect(aliceButton.getAttribute('aria-label')).toMatch(/^u\/alice, Unread, .+ ago/);
// alice is inbound and unread; bob is a conversation we replied to last.
expect(screen.getByRole('button', { name: 'Unread, 1' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Needs reply, 1' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Waiting on them, 1' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'All, 2' })).toHaveAttribute('aria-pressed', 'true');
expect(aliceButton.getAttribute('aria-label')).toMatch(/^u\/alice, Unread, Needs reply, .+ago/);
expect(aliceButton.closest('li')).toHaveClass('is-unread');
expect(screen.getByRole('button', { name: /u\/bob/ }).closest('li')).not.toHaveClass('is-unread');
});