From 110d534a917d890e156063dd10cbaffcdcb95de3 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Tue, 11 Aug 2026 14:55:25 +0200 Subject: [PATCH] Fix inbox badge counting rooms twice via space aggregates --- src/app/hooks/useInboxNotificationCount.test.ts | 15 +++++++++++++++ src/app/hooks/useInboxNotificationCount.ts | 1 + 2 files changed, 16 insertions(+) diff --git a/src/app/hooks/useInboxNotificationCount.test.ts b/src/app/hooks/useInboxNotificationCount.test.ts index bcbc46c2a..770fdf997 100644 --- a/src/app/hooks/useInboxNotificationCount.test.ts +++ b/src/app/hooks/useInboxNotificationCount.test.ts @@ -20,4 +20,19 @@ describe('countInboxNotifications', () => { expect(countInboxNotifications(rooms, unread, new Set(['!dm']))).toBe(6); }); + + it('skips space rooms so aggregated space counts are not double-counted', () => { + const space = { + roomId: '!space', + isSpaceRoom: () => true, + getJoinedMemberCount: () => 3, + } as unknown as Room; + const rooms = [room('!room'), space]; + const unread = new Map([ + ['!room', { total: 4, highlight: 1, from: null }], + ['!space', { total: 4, highlight: 1, from: new Set(['!room']) }], + ]) as RoomToUnread; + + expect(countInboxNotifications(rooms, unread, new Set())).toBe(1); + }); }); diff --git a/src/app/hooks/useInboxNotificationCount.ts b/src/app/hooks/useInboxNotificationCount.ts index 6daf25efb..b12e52497 100644 --- a/src/app/hooks/useInboxNotificationCount.ts +++ b/src/app/hooks/useInboxNotificationCount.ts @@ -13,6 +13,7 @@ export const countInboxNotifications = ( mDirects: Set ): number => rooms.reduce((count, room) => { + if (room.isSpaceRoom()) return count; const unread = roomToUnread.get(room.roomId); if (!unread) return count; return count + (isDMRoom(room, mDirects) ? unread.total : unread.highlight);