fix(unread): render a dot instead of a placeholder count of 1

This commit is contained in:
Erwan Leboucher committed 2026-09-20 20:33:09 +02:00
1 parent cb0a01b293
commit 6f051de835
6 files changed
+25 -1

No files matched your search

@@ -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<SidebarUnreadBadgeProps>) {
const [showUnreadCounts] = useSetting(settingsAtom, 'showUnreadCounts');
@@ -26,6 +28,7 @@ export function SidebarUnreadBadge({
highlight,
count,
dm,
estimated,
showUnreadCounts,
badgeCountDMsOnly,
showPingCounts,
@@ -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({
@@ -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,
@@ -562,6 +562,7 @@ export function RoomNavItem({
<SidebarUnreadBadge
highlight={unread.highlight > 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}
/>
</UnreadBadgeCenter>
)}
+1
View File
@@ -46,6 +46,7 @@ const unreadInfoToUnread = (unreadInfo: UnreadInfo): Unread => ({
highlight: unreadInfo.highlight,
total: unreadInfo.total,
from: null,
estimated: unreadInfo.estimated,
});
const putUnreadInfo = (
+1
View File
@@ -60,6 +60,7 @@ export type Unread = {
total: number;
highlight: number;
from: Set<string> | null;
estimated?: boolean;
};
export type RoomToUnread = Map<string, Unread>;
export type UnreadInfo = {