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:
@@ -1,7 +1,7 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { MatrixEvent } from 'matrix-js-sdk';
|
||||
import { receiptIsMine, setMarkedUnread } from './markedUnread';
|
||||
import { myMainReceiptPresent, receiptIsMine, setMarkedUnread } from './markedUnread';
|
||||
|
||||
// MSC2867 mark-as-unread: reading a room (our own receipt) clears the flag, so
|
||||
// `receiptIsMine` must detect only OUR receipt and ignore others'. And a write
|
||||
@@ -33,6 +33,28 @@ test('receiptIsMine: tolerates empty / malformed content', () => {
|
||||
assert.equal(receiptIsMine(receiptEvent({ $x: {} }), ME), false);
|
||||
});
|
||||
|
||||
// myMainReceiptPresent gates the auto-clear to main-timeline reads, so reading a
|
||||
// single thread does not wipe the whole-room marked-unread flag.
|
||||
test('myMainReceiptPresent: true for an unthreaded receipt (no thread_id)', () => {
|
||||
const event = receiptEvent({ $abc: { 'm.read': { [ME]: { ts: 1 } } } });
|
||||
assert.equal(myMainReceiptPresent(event, ME), true);
|
||||
});
|
||||
|
||||
test('myMainReceiptPresent: true for a thread_id "main" receipt', () => {
|
||||
const event = receiptEvent({ $abc: { 'm.read': { [ME]: { ts: 1, thread_id: 'main' } } } });
|
||||
assert.equal(myMainReceiptPresent(event, ME), true);
|
||||
});
|
||||
|
||||
test('myMainReceiptPresent: false for a thread-scoped receipt', () => {
|
||||
const event = receiptEvent({ $abc: { 'm.read': { [ME]: { ts: 1, thread_id: '$root:server' } } } });
|
||||
assert.equal(myMainReceiptPresent(event, ME), false);
|
||||
});
|
||||
|
||||
test('myMainReceiptPresent: false when only another user has a main receipt', () => {
|
||||
const event = receiptEvent({ $abc: { 'm.read': { [OTHER]: { ts: 1 } } } });
|
||||
assert.equal(myMainReceiptPresent(event, ME), false);
|
||||
});
|
||||
|
||||
test('setMarkedUnread writes both the stable and unstable keys with the flag', async () => {
|
||||
const calls: Array<{ type: string; content: unknown }> = [];
|
||||
const mx = {
|
||||
|
||||
Reference in New Issue
Block a user