From 0d87c707e0569358785e92e44993ca7e6cae752a Mon Sep 17 00:00:00 2001 From: Evie Gauthier Date: Wed, 4 Mar 2026 10:43:25 -0500 Subject: [PATCH] fix(notifications): preserve thread reply counts when clamping stale main-timeline total MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/app/utils/room.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/app/utils/room.ts b/src/app/utils/room.ts index cadd0e95..aed17e84 100644 --- a/src/app/utils/room.ts +++ b/src/app/utils/room.ts @@ -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; + } } }