diff options
author | Hailey <me@haileyok.com> | 2024-05-17 16:05:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-17 16:05:32 -0700 |
commit | d2c81c9d3d6aebae9c73a7567875e0165cfb1f08 (patch) | |
tree | 428f283a80530d71603d2cad87e62d85d20d2bf7 /src/lib/hooks/useNotificationHandler.ts | |
parent | 49314e2d1f20d7471f1d05ce2b118bd030c44aa2 (diff) | |
download | voidsky-d2c81c9d3d6aebae9c73a7567875e0165cfb1f08.tar.zst |
Disable badge incrementing for DMs (#4088)
* disable badge increments for dms * revert decrementing in js for dms * reset badge on read notifications * remove some other code * prevent duplicate notification events
Diffstat (limited to 'src/lib/hooks/useNotificationHandler.ts')
-rw-r--r-- | src/lib/hooks/useNotificationHandler.ts | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/lib/hooks/useNotificationHandler.ts b/src/lib/hooks/useNotificationHandler.ts index 3f1cd439d..f3c4da7f6 100644 --- a/src/lib/hooks/useNotificationHandler.ts +++ b/src/lib/hooks/useNotificationHandler.ts @@ -46,8 +46,9 @@ const DEFAULT_HANDLER_OPTIONS = { shouldSetBadge: true, } -// This needs to stay outside the hook to persist between account switches +// These need to stay outside the hook to persist between account switches let storedPayload: NotificationPayload | undefined +let prevDate = 0 export function useNotificationsHandler() { const queryClient = useQueryClient() @@ -58,9 +59,6 @@ export function useNotificationsHandler() { const {setShowLoggedOut} = useLoggedOutViewControls() const closeAllActiveElements = useCloseAllActiveElements() - // Safety to prevent double handling of the same notification - const prevDate = React.useRef(0) - React.useEffect(() => { if (!isAndroid) return @@ -169,11 +167,10 @@ export function useNotificationsHandler() { payload.reason === 'chat-message' && payload.recipientDid === currentAccount?.did ) { - const isCurrentConvo = payload.convoId === currentConvoId return { - shouldShowAlert: !isCurrentConvo, + shouldShowAlert: payload.convoId !== currentConvoId, shouldPlaySound: false, - shouldSetBadge: !isCurrentConvo, + shouldSetBadge: false, } } @@ -185,10 +182,10 @@ export function useNotificationsHandler() { const responseReceivedListener = Notifications.addNotificationResponseReceivedListener(e => { - if (e.notification.date === prevDate.current) { + if (e.notification.date === prevDate) { return } - prevDate.current = e.notification.date + prevDate = e.notification.date logger.debug( 'Notifications: response received', |