From 4f6ee1a00bf7a99f9e8efdb07de12a8df4e3bab5 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 13 Feb 2026 18:04:10 -0500 Subject: [PATCH] feat: Add a preference for desktop notification badge off/count/indicator (#11436) --- .../Notifications/Notifications.tsx | 26 ++++++--- app/models/User.ts | 17 ++++-- app/scenes/Settings/Preferences.tsx | 56 ++++++++++++++++++- app/typings/window.d.ts | 2 +- server/models/User.ts | 15 +++-- server/routes/api/users/schema.ts | 14 ++++- server/routes/api/users/users.ts | 9 +-- shared/constants.ts | 2 + shared/i18n/locales/en_US/translation.json | 4 ++ shared/types.ts | 22 +++++++- 10 files changed, 140 insertions(+), 27 deletions(-) diff --git a/app/components/Notifications/Notifications.tsx b/app/components/Notifications/Notifications.tsx index 942bc4820e..b899fd6db9 100644 --- a/app/components/Notifications/Notifications.tsx +++ b/app/components/Notifications/Notifications.tsx @@ -4,8 +4,10 @@ import * as React from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; import { s, hover } from "@shared/styles"; +import { NotificationBadgeType, UserPreference } from "@shared/types"; import Notification, { type NotificationFilter } from "~/models/Notification"; import { markNotificationsAsRead } from "~/actions/definitions/notifications"; +import useCurrentUser from "~/hooks/useCurrentUser"; import useStores from "~/hooks/useStores"; import NotificationMenu from "~/menus/NotificationMenu"; import Desktop from "~/utils/Desktop"; @@ -34,6 +36,7 @@ function Notifications( ref: React.RefObject ) { const { notifications } = useStores(); + const user = useCurrentUser(); const { t } = useTranslation(); const [filter, setFilter] = React.useState("all"); @@ -61,25 +64,34 @@ function Notifications( ); }, [notifications.active, filter]); + const badgeType = user.getPreference(UserPreference.NotificationBadge); + const unreadCount = notifications.approximateUnreadCount; + // Update the notification count in the dock icon, if possible. React.useEffect(() => { // Account for old versions of the desktop app that don't have the // setNotificationCount method on the bridge. if (Desktop.bridge && "setNotificationCount" in Desktop.bridge) { - void Desktop.bridge.setNotificationCount( - notifications.approximateUnreadCount - ); + if (badgeType === NotificationBadgeType.Disabled || unreadCount === 0) { + void Desktop.bridge.setNotificationCount(0); + } else if (badgeType === NotificationBadgeType.Count) { + void Desktop.bridge.setNotificationCount(unreadCount); + } else { + void Desktop.bridge.setNotificationCount("・"); + } } // PWA badging if ("setAppBadge" in navigator) { - if (notifications.approximateUnreadCount) { - void navigator.setAppBadge(notifications.approximateUnreadCount); + if (unreadCount > 0 && badgeType !== NotificationBadgeType.Disabled) { + void navigator.setAppBadge( + badgeType === NotificationBadgeType.Count ? unreadCount : undefined + ); } else { void navigator.clearAppBadge(); } } - }, [notifications.approximateUnreadCount]); + }, [unreadCount, badgeType]); return ( @@ -105,7 +117,7 @@ function Notifications( short nude /> - {notifications.approximateUnreadCount > 0 && ( + {unreadCount > 0 && (