fix(threads): viewing a room no longer marks threads you follow read (#217)

markAsRead ran on every room visit (timeline at the bottom and focused) and
sent a threaded receipt for every unread thread, so a reply in a thread you
started or replied in lost its unread badge the moment you glanced at the
room, without opening the thread.

Reads from just viewing the timeline are now "passive":
- threads you follow (started, replied in, or were mentioned in) stay unread
  until their panel is opened; other threads are still cleared so they don't
  keep the room dot lit forever;
- while a followed thread has an unread reply, the main receipt is scoped to
  the main timeline instead of unthreaded, because an unthreaded receipt
  also reads every older thread reply (the next main message would clear the
  thread anyway). The check also asks whether the latest reply is read, since
  the thread's count lags when the reply and a main message share a sync;
- the thread open in the panel is skipped, as the panel sends its own
  receipt (was two identical receipts per reply).

Explicit "mark as read" (room menu, Escape, bulk actions) still clears
everything. Unit tests for each rule plus a local-homeserver e2e that checks
the server's per-thread count survives a reply + newer main message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
Lotus CI
2026-09-26 19:31:00 -04:00
co-authored by Claude Opus 5.5
parent f5d3c43b6c
commit a8db61f79f
4 changed files with 259 additions and 14 deletions
+50
View File
@@ -169,6 +169,56 @@ test.describe('local homeserver regression', () => {
await ctx.close();
});
test('a thread I started keeps its unread replies while I view the room (#217)', async ({
page,
}) => {
const room = await createRoom(alice, 'Thread Unread Room', { invite: [bob.userId] });
await joinRoom(bob, room);
const inThread = (root: string) => ({
'm.relates_to': {
rel_type: 'm.thread',
event_id: root,
is_falling_back: true,
'm.in_reply_to': { event_id: root },
},
});
const root = await sendText(alice, room, 'my thread root');
await loginUI(page, alice);
await openRoom(page, room);
// While the room is open and at the bottom: a thread reply, then a newer
// main-timeline message. Neither may clear the thread without opening it.
await sendText(bob, room, 'reply in your thread', inThread(root));
await sendText(bob, room, 'newer main message');
await expect(page.getByText('newer main message')).toBeVisible();
const chip = page
.locator('[data-message-item]', { hasText: 'my thread root' })
.getByRole('button', { name: /1 reply/ });
const threadUnread = async () => {
// not_types varies so Synapse's sync response cache can't serve a stale answer.
const filter = {
room: {
rooms: [room],
timeline: { limit: 1, unread_thread_notifications: true, not_types: [uniq('x.')] },
},
};
const sync = await api<{
rooms: {
join: Record<string, { unread_thread_notifications?: Record<string, unknown> }>;
};
}>(
'GET',
`/_matrix/client/v3/sync?timeout=0&filter=${enc(JSON.stringify(filter))}`,
alice.token,
);
return root in (sync.rooms.join[room]?.unread_thread_notifications ?? {});
};
await page.waitForTimeout(2000); // let any receipt the room view would send go out
expect(await threadUnread()).toBe(true);
await expect(chip).toHaveAccessibleName(/unread replies/);
await chip.click();
await expect.poll(threadUnread).toBe(false);
});
test('timeline image opens the gallery lightbox (#219) @webkit', async ({ page }) => {
const room = await createRoom(alice, 'Lightbox Room');
const png = Buffer.from(