diff --git a/src/app/components/sidebar/SidebarUnreadBadge.tsx b/src/app/components/sidebar/SidebarUnreadBadge.tsx index 42476cc6b..b3a18f707 100644 --- a/src/app/components/sidebar/SidebarUnreadBadge.tsx +++ b/src/app/components/sidebar/SidebarUnreadBadge.tsx @@ -8,6 +8,7 @@ type SidebarUnreadBadgeProps = { highlight?: boolean; count: number; dm?: boolean; + estimated?: boolean; mode?: UnreadBadgeMode; }; @@ -15,6 +16,7 @@ export function SidebarUnreadBadge({ highlight, count, dm, + estimated, mode, }: Readonly) { const [showUnreadCounts] = useSetting(settingsAtom, 'showUnreadCounts'); @@ -26,6 +28,7 @@ export function SidebarUnreadBadge({ highlight, count, dm, + estimated, showUnreadCounts, badgeCountDMsOnly, showPingCounts, diff --git a/src/app/components/unread-badge/UnreadBadge.test.tsx b/src/app/components/unread-badge/UnreadBadge.test.tsx index 8c4216439..eb09dd2c7 100644 --- a/src/app/components/unread-badge/UnreadBadge.test.tsx +++ b/src/app/components/unread-badge/UnreadBadge.test.tsx @@ -36,6 +36,18 @@ describe('resolveUnreadBadgeMode', () => { ).toBe('count'); }); + it('returns dot for an estimated count even when unread counts are enabled', () => { + expect( + resolveUnreadBadgeMode({ + count: 1, + estimated: true, + showUnreadCounts: true, + badgeCountDMsOnly: false, + showPingCounts: false, + }) + ).toBe('dot'); + }); + it('returns dot for a room unread when unread counts are disabled', () => { expect( resolveUnreadBadgeMode({ diff --git a/src/app/components/unread-badge/UnreadBadge.tsx b/src/app/components/unread-badge/UnreadBadge.tsx index 6f86f87e7..5b708c173 100644 --- a/src/app/components/unread-badge/UnreadBadge.tsx +++ b/src/app/components/unread-badge/UnreadBadge.tsx @@ -8,6 +8,7 @@ type UnreadBadgeProps = { count: number; /** Whether this badge belongs to a DM room. Used with the badgeCountDMsOnly setting. */ dm?: boolean; + estimated?: boolean; mode?: UnreadBadgeMode; }; @@ -28,18 +29,21 @@ export type UnreadBadgeMode = 'dot' | 'count'; * @param options.showUnreadCounts Whether regular room unread badges should show counts. * @param options.badgeCountDMsOnly Whether direct message unread badges should show counts. * @param options.showPingCounts Whether highlight badges should show counts. + * @param options.estimated Whether the count is a placeholder awaiting backfill. * @returns `'count'` when the current badge context is allowed to show a number, otherwise `'dot'`. */ export function resolveUnreadBadgeMode({ highlight, count, dm, + estimated, showUnreadCounts, badgeCountDMsOnly, showPingCounts, }: ResolveUnreadBadgeModeOptions): UnreadBadgeMode { const showNumber = count > 0 && + !estimated && ((dm && badgeCountDMsOnly) || (!dm && showUnreadCounts) || (highlight && showPingCounts)); return showNumber ? 'count' : 'dot'; @@ -68,7 +72,7 @@ export function UnreadBadgeCenter({ children }: { children: ReactNode }) { ); } -export function UnreadBadge({ highlight, count, dm, mode }: UnreadBadgeProps) { +export function UnreadBadge({ highlight, count, dm, estimated, mode }: UnreadBadgeProps) { const [showUnreadCounts] = useSetting(settingsAtom, 'showUnreadCounts'); const [badgeCountDMsOnly] = useSetting(settingsAtom, 'badgeCountDMsOnly'); const [showPingCounts] = useSetting(settingsAtom, 'showPingCounts'); @@ -79,6 +83,7 @@ export function UnreadBadge({ highlight, count, dm, mode }: UnreadBadgeProps) { highlight, count, dm, + estimated, showUnreadCounts, badgeCountDMsOnly, showPingCounts, diff --git a/src/app/features/room-nav/RoomNavItem.tsx b/src/app/features/room-nav/RoomNavItem.tsx index 8c6d0f447..d8f5c9577 100644 --- a/src/app/features/room-nav/RoomNavItem.tsx +++ b/src/app/features/room-nav/RoomNavItem.tsx @@ -562,6 +562,7 @@ export function RoomNavItem({ 0} count={unread.highlight > 0 ? unread.highlight : unread.total} + estimated={unread.estimated} /> )} @@ -601,6 +602,7 @@ export function RoomNavItem({ highlight={!!unread && unread.highlight > 0} count={unreadCount} dm={direct} + estimated={unread?.estimated} /> )} diff --git a/src/app/state/room/roomToUnread.ts b/src/app/state/room/roomToUnread.ts index d532837b1..870bb09f5 100644 --- a/src/app/state/room/roomToUnread.ts +++ b/src/app/state/room/roomToUnread.ts @@ -46,6 +46,7 @@ const unreadInfoToUnread = (unreadInfo: UnreadInfo): Unread => ({ highlight: unreadInfo.highlight, total: unreadInfo.total, from: null, + estimated: unreadInfo.estimated, }); const putUnreadInfo = ( diff --git a/src/types/matrix/room.ts b/src/types/matrix/room.ts index 15a596bfe..f74936957 100644 --- a/src/types/matrix/room.ts +++ b/src/types/matrix/room.ts @@ -60,6 +60,7 @@ export type Unread = { total: number; highlight: number; from: Set | null; + estimated?: boolean; }; export type RoomToUnread = Map; export type UnreadInfo = {