fix(unread): stop stuck/resurrecting read indicators
handleReceipt recomputed unread from getUnreadNotificationCount, which is
server-computed and stale on the synchronous synthetic receipt echo (the SDK
only zeroes it immediately when the last event is our own message). Reading
someone else's message therefore PUT the stale non-zero count back -> dot stuck
or resurrected on the ack-sync ordering race. Restore upstream cinny's
optimistic DELETE on our own receipt; the UnreadNotifications listener re-asserts
the accurate badge on the server ack.
Also collapse a {total:0,highlight:0} PUT to a DELETE in the reducer (a present
map entry lights the dot via hasUnread=!!unread, so phantom {0,0} PUTs from the
UnreadNotifications listener left stuck dots).
Mark-as-Unread (MSC2867): clear the flag directly in markAsRead (opening an
already-read room sends no receipt, so the receipt-driven auto-clear never
fired), and gate the receipt auto-clear to main/unthreaded receipts so reading
one thread no longer wipes the whole-room flag.
Tests: 700/700 pass; typecheck + prod build clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import { AccountDataEvent } from '../../../types/matrix/accountData';
|
||||
// flag round-trips across the ecosystem.
|
||||
const UNSTABLE_MARKED_UNREAD = 'com.famedly.marked_unread';
|
||||
|
||||
const readMarkedUnread = (room: Room): boolean => {
|
||||
export const readMarkedUnread = (room: Room): boolean => {
|
||||
const stable = room.getAccountData(AccountDataEvent.MarkedUnread)?.getContent()?.unread;
|
||||
if (typeof stable === 'boolean') return stable;
|
||||
return room.getAccountData(UNSTABLE_MARKED_UNREAD)?.getContent()?.unread === true;
|
||||
@@ -41,6 +41,22 @@ export const receiptIsMine = (event: MatrixEvent, userId: string): boolean => {
|
||||
);
|
||||
};
|
||||
|
||||
// True only when OUR receipt in this event is for the main timeline — either
|
||||
// unthreaded (no thread_id) or thread_id "main". A receipt scoped to a specific
|
||||
// thread (thread_id === <threadRootId>) must NOT clear the whole-room marked
|
||||
// flag, since only that one thread was read.
|
||||
export const myMainReceiptPresent = (event: MatrixEvent, userId: string): boolean => {
|
||||
const content = event.getContent();
|
||||
return Object.keys(content).some((eventId) =>
|
||||
Object.keys(content[eventId] ?? {}).some((receiptType) => {
|
||||
const receipt = content[eventId][receiptType]?.[userId];
|
||||
if (!receipt) return false;
|
||||
const threadId = (receipt as { thread_id?: string }).thread_id;
|
||||
return threadId === undefined || threadId === 'main';
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
export const useBindMarkedUnreadAtom = (mx: MatrixClient, anAtom: typeof markedUnreadAtom) => {
|
||||
const setAtom = useSetAtom(anAtom);
|
||||
|
||||
@@ -65,12 +81,15 @@ export const useBindMarkedUnreadAtom = (mx: MatrixClient, anAtom: typeof markedU
|
||||
const onAccountData: RoomEventHandlerMap[RoomEvent.AccountData] = (_event, room) => {
|
||||
syncRoom(room);
|
||||
};
|
||||
// Reading a room clears its marked-unread flag (MSC2867): when our own read
|
||||
// receipt lands for a room that's currently marked, clear it.
|
||||
// Reading a room clears its marked-unread flag (MSC2867): when our own
|
||||
// MAIN-timeline read receipt lands for a room that's currently marked, clear
|
||||
// it. Gated to main/unthreaded receipts so reading a single thread doesn't
|
||||
// wipe the whole-room flag. (This also fires for receipts from our other
|
||||
// devices; the local read path clears via markAsRead in notifications.ts.)
|
||||
const onReceipt: RoomEventHandlerMap[RoomEvent.Receipt] = (event, room) => {
|
||||
const myId = mx.getUserId();
|
||||
if (!myId || !readMarkedUnread(room)) return;
|
||||
if (receiptIsMine(event, myId)) {
|
||||
if (myMainReceiptPresent(event, myId)) {
|
||||
setMarkedUnread(mx, room.roomId, false).catch(() => undefined);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user