fix(notifications): preserve thread reply counts when clamping stale main-timeline total

getUnreadNotificationCount() aggregates both the room-level counter and all
thread notification counters. The stale-clamping logic checked whether the
latest main-timeline event was already read and, if so, set total = 0 — this
inadvertently wiped out any thread reply counts that were included in the
combined total.

Fix by reading getRoomUnreadNotificationCount() (main-timeline only) to
determine the stale portion, then subtracting only that from total rather than
zeroing the whole value. Thread highlight and total counts are preserved.
This commit is contained in:
Evie Gauthier committed 2026-03-04 10:54:25 -05:00
1 parent cabb65fcaa
commit 0d87c707e0
1 file changed
+13 -8
+13 -8
View File
@@ -243,15 +243,20 @@ export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadIn
let highlight = room.getUnreadNotificationCount(NotificationCountType.Highlight);
let syntheticDotUnread = false;
// If our latest notification event is confirmed read, clamp stale non-highlight totals.
// If our latest main-timeline notification event is confirmed read, clamp its stale count.
// Only apply to the room (non-thread) portion so thread reply counts are preserved.
if (userId && total > 0 && highlight === 0) {
const liveEvents = room.getLiveTimeline().getEvents();
const latestNotification = [...liveEvents]
.reverse()
.find((event) => !event.isSending() && isNotificationEvent(event));
const latestNotificationId = latestNotification?.getId();
if (latestNotificationId && room.hasUserReadEvent(userId, latestNotificationId)) {
total = 0;
const roomTotal = room.getRoomUnreadNotificationCount(NotificationCountType.Total);
if (roomTotal > 0) {
const liveEvents = room.getLiveTimeline().getEvents();
const latestNotification = [...liveEvents]
.reverse()
.find((event) => !event.isSending() && isNotificationEvent(event));
const latestNotificationId = latestNotification?.getId();
if (latestNotificationId && room.hasUserReadEvent(userId, latestNotificationId)) {
// Subtract only the stale main-timeline count; thread totals remain intact.
total -= roomTotal;
}
}
}