From 7f5c9ddf3d3203e7ba7df22ac4ec28ceacecb66a Mon Sep 17 00:00:00 2001 From: Evie Gauthier Date: Wed, 4 Mar 2026 10:43:25 -0500 Subject: [PATCH] fix(badges): fix room nav badge counts and add dot badge for non-notifying rooms - Use highlight count on highlighted badge, total on standard (matching the fix applied to other sidebar call sites) - Add useRoomHasUnread hook that subscribes reactively to RoomEvent.Timeline and RoomEvent.Receipt to detect unread messages independently of push-rule notification counts - When a room has unread messages but no notification count entry (e.g. a mentions-only room with new regular messages), show a dot badge (count=0) rather than no badge at all, matching the behaviour of other Matrix clients - Also bold the room name and restore icon opacity for these rooms --- src/app/features/room-nav/RoomNavItem.tsx | 46 +++++++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/app/features/room-nav/RoomNavItem.tsx b/src/app/features/room-nav/RoomNavItem.tsx index d4368c3e..9a3d3b3a 100644 --- a/src/app/features/room-nav/RoomNavItem.tsx +++ b/src/app/features/room-nav/RoomNavItem.tsx @@ -1,5 +1,5 @@ -import { MouseEventHandler, forwardRef, useState, MouseEvent } from 'react'; -import { EventType, Room } from '$types/matrix-sdk'; +import { MouseEventHandler, forwardRef, useState, MouseEvent, useEffect } from 'react'; +import { EventType, Room, RoomEvent as RoomEventEnum } from '$types/matrix-sdk'; import { Avatar, Box, @@ -25,7 +25,7 @@ import { useNavigate } from 'react-router-dom'; import { NavButton, NavItem, NavItemContent, NavItemOptions } from '$components/nav'; import { UnreadBadge, UnreadBadgeCenter } from '$components/unread-badge'; import { RoomAvatar, RoomIcon } from '$components/room-avatar'; -import { getDirectRoomAvatarUrl, getRoomAvatarUrl } from '$utils/room'; +import { getDirectRoomAvatarUrl, getRoomAvatarUrl, roomHaveUnread } from '$utils/room'; import { nameInitials } from '$utils/common'; import { useMatrixClient } from '$hooks/useMatrixClient'; import { useRoomUnread } from '$state/hooks/unread'; @@ -63,6 +63,28 @@ import { useAtomValue } from 'jotai'; import { nicknamesAtom } from '$state/nicknames'; import { RoomNavUser } from './RoomNavUser'; +/** + * Reactively checks whether a room has unread messages, even if the + * push-rule notification count is zero (e.g. mentions-only rooms with + * new regular messages). + */ +function useRoomHasUnread(room: Room): boolean { + const mx = useMatrixClient(); + const [hasUnread, setHasUnread] = useState(() => roomHaveUnread(mx, room)); + + useEffect(() => { + const update = () => setHasUnread(roomHaveUnread(mx, room)); + room.on(RoomEventEnum.Timeline, update); + room.on(RoomEventEnum.Receipt, update); + return () => { + room.removeListener(RoomEventEnum.Timeline, update); + room.removeListener(RoomEventEnum.Receipt, update); + }; + }, [room, mx]); + + return hasUnread; +} + type RoomNavItemMenuProps = { room: Room; requestClose: () => void; @@ -243,6 +265,7 @@ export function RoomNavItem({ const { focusWithinProps } = useFocusWithin({ onFocusWithinChange: setHover }); const [menuAnchor, setMenuAnchor] = useState(); const unread = useRoomUnread(room.roomId, roomToUnreadAtom); + const hasRoomUnread = useRoomHasUnread(room); const typingMember = useRoomTypingMember(room.roomId).filter( (receipt) => receipt.userId !== mx.getUserId() ); @@ -318,6 +341,10 @@ export function RoomNavItem({ }; const optionsVisible = hover || !!menuAnchor; + let unreadCount = 0; + if (unread) { + unreadCount = unread.highlight > 0 ? unread.highlight : unread.total; + } const ariaLabel = [ roomName, room.isCallRoom() @@ -338,7 +365,7 @@ export function RoomNavItem({ )} - {!optionsVisible && unread && ( + {!optionsVisible && (unread || hasRoomUnread) && ( - 0} count={unread.total} /> + 0} count={unreadCount} /> )} {!optionsVisible && notificationMode !== RoomNotificationMode.Unset && (