From cabb65fcaac86fced78b633b9b7f9d7ad6549263 Mon Sep 17 00:00:00 2001 From: Evie Gauthier Date: Wed, 4 Mar 2026 10:43:25 -0500 Subject: [PATCH] fix(badges): exclude DM rooms from space unread badge aggregation When a DM room is also a child of a space, its unread counts were propagating upward into the space's aggregated badge, causing the space to show a badge even though the unread belonged to a direct message. In the roomToUnreadAtom write function, check mDirectAtom before calling getAllParents: if the room is a DM, use an empty parent set so its unread stays isolated to the direct tab and does not roll up into any space badge. --- src/app/state/room/roomToUnread.ts | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/app/state/room/roomToUnread.ts b/src/app/state/room/roomToUnread.ts index 7d12691c..706b4bd7 100644 --- a/src/app/state/room/roomToUnread.ts +++ b/src/app/state/room/roomToUnread.ts @@ -32,6 +32,7 @@ import { useSyncState } from '$hooks/useSyncState'; import { useRoomsNotificationPreferencesContext } from '$hooks/useRoomsNotificationPreferences'; import { getClientSyncDiagnostics } from '$client/initMatrix'; import { roomToParentsAtom } from './roomToParents'; +import { mDirectAtom } from '../mDirectList'; export type RoomToUnreadAction = | { @@ -122,14 +123,14 @@ const baseRoomToUnread = atom(new Map()); export const roomToUnreadAtom = atom( (get) => get(baseRoomToUnread), (get, set, action) => { + const dmRoomIds = get(mDirectAtom); + const getEffectiveParents = (roomId: string): Set => + dmRoomIds.has(roomId) ? new Set() : getAllParents(get(roomToParentsAtom), roomId); + if (action.type === 'RESET') { const draftRoomToUnread: RoomToUnread = new Map(); action.unreadInfos.forEach((unreadInfo) => { - putUnreadInfo( - draftRoomToUnread, - getAllParents(get(roomToParentsAtom), unreadInfo.roomId), - unreadInfo - ); + putUnreadInfo(draftRoomToUnread, getEffectiveParents(unreadInfo.roomId), unreadInfo); }); set(baseRoomToUnread, draftRoomToUnread); return; @@ -143,7 +144,7 @@ export const roomToUnreadAtom = atom deleteUnreadInfo( draftRoomToUnread, - getAllParents(get(roomToParentsAtom), unreadInfo.roomId), + getEffectiveParents(unreadInfo.roomId), unreadInfo.roomId ) ) @@ -160,11 +161,7 @@ export const roomToUnreadAtom = atom - putUnreadInfo( - draftRoomToUnread, - getAllParents(get(roomToParentsAtom), unreadInfo.roomId), - unreadInfo - ) + putUnreadInfo(draftRoomToUnread, getEffectiveParents(unreadInfo.roomId), unreadInfo) ) ); return; @@ -173,11 +170,7 @@ export const roomToUnreadAtom = atom - deleteUnreadInfo( - draftRoomToUnread, - getAllParents(get(roomToParentsAtom), action.roomId), - action.roomId - ) + deleteUnreadInfo(draftRoomToUnread, getEffectiveParents(action.roomId), action.roomId) ) ); }