feat(threads): "Mark all read" in the threads list (#165)
CI / Build & Quality Checks (push) Canceled after 0s
CI / Trigger Desktop Build (push) Canceled after 0s
CI / Secret scan (gitleaks) (push) Canceled after 0s
CI / Docker image build & smoke test (push) Canceled after 0s
CI / Playwright smoke (e2e) (push) Canceled after 0s

A "Mark all read" chip appears in the Threads panel header whenever any
thread in the room has unread replies, and sends one threaded receipt per
unread thread (never the root — a root lives in the main timeline and a
receipt there would drag the MAIN read marker backwards, the P6
regression). Honours the private-receipt settings.

Verified: two threads with unread replies → the chip appears, the rows
say "unread" in their labels; after clicking, no unread rows and the chip
is gone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
2026-09-23 15:25:53 -04:00
co-authored by Claude Opus 5
parent cf80729a5c
commit fdec3ed7f2
2 changed files with 76 additions and 2 deletions
+29
View File
@@ -0,0 +1,29 @@
import { MatrixClient, NotificationCountType, ReceiptType, Room } from 'matrix-js-sdk';
/**
* [Gitea #165] Send a threaded read receipt for every thread in the room that
* has unread replies. Mirrors the per-thread half of `markAsRead`, including
* its rule: never fall back to the thread root (a root lives in the main
* timeline, so a receipt there would move the MAIN read marker backwards).
* Returns how many threads were marked.
*/
export async function markAllThreadsRead(
mx: MatrixClient,
room: Room,
privateReceipt: boolean,
): Promise<number> {
const receiptType = privateReceipt ? ReceiptType.ReadPrivate : ReceiptType.Read;
const sends = room
.getThreads()
.map((thread) => {
const unread =
room.getThreadUnreadNotificationCount(thread.id, NotificationCountType.Total) ?? 0;
if (unread <= 0) return undefined;
const lastReply = thread.lastReply();
if (!lastReply || lastReply.isSending()) return undefined;
return mx.sendReadReceipt(lastReply, receiptType, false).catch(() => undefined);
})
.filter((p): p is NonNullable<typeof p> => !!p);
await Promise.all(sends);
return sends.length;
}