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.
This commit is contained in:
Evie Gauthier committed 2026-03-04 10:54:25 -05:00
1 parent 7f5c9ddf3d
commit cabb65fcaa
1 file changed
+9 -16
+9 -16
View File
@@ -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<RoomToUnread>(new Map());
export const roomToUnreadAtom = atom<RoomToUnread, [RoomToUnreadAction], undefined>(
(get) => get(baseRoomToUnread),
(get, set, action) => {
const dmRoomIds = get(mDirectAtom);
const getEffectiveParents = (roomId: string): Set<string> =>
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<RoomToUnread, [RoomToUnreadAction], undefin
produce(get(baseRoomToUnread), (draftRoomToUnread) =>
deleteUnreadInfo(
draftRoomToUnread,
getAllParents(get(roomToParentsAtom), unreadInfo.roomId),
getEffectiveParents(unreadInfo.roomId),
unreadInfo.roomId
)
)
@@ -160,11 +161,7 @@ export const roomToUnreadAtom = atom<RoomToUnread, [RoomToUnreadAction], undefin
set(
baseRoomToUnread,
produce(get(baseRoomToUnread), (draftRoomToUnread) =>
putUnreadInfo(
draftRoomToUnread,
getAllParents(get(roomToParentsAtom), unreadInfo.roomId),
unreadInfo
)
putUnreadInfo(draftRoomToUnread, getEffectiveParents(unreadInfo.roomId), unreadInfo)
)
);
return;
@@ -173,11 +170,7 @@ export const roomToUnreadAtom = atom<RoomToUnread, [RoomToUnreadAction], undefin
set(
baseRoomToUnread,
produce(get(baseRoomToUnread), (draftRoomToUnread) =>
deleteUnreadInfo(
draftRoomToUnread,
getAllParents(get(roomToParentsAtom), action.roomId),
action.roomId
)
deleteUnreadInfo(draftRoomToUnread, getEffectiveParents(action.roomId), action.roomId)
)
);
}