diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/hooks/useNotificationHandler.ts | 5 | ||||
-rw-r--r-- | src/lib/notifications/notifications.ts | 12 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/lib/hooks/useNotificationHandler.ts b/src/lib/hooks/useNotificationHandler.ts index 6f5fbd66b..e288ac3ad 100644 --- a/src/lib/hooks/useNotificationHandler.ts +++ b/src/lib/hooks/useNotificationHandler.ts @@ -169,10 +169,11 @@ export function useNotificationsHandler() { payload.reason === 'chat-message' && payload.recipientDid === currentAccount?.did ) { + const isCurrentConvo = payload.convoId === currentConvoId return { - shouldShowAlert: payload.convoId !== currentConvoId, + shouldShowAlert: !isCurrentConvo, shouldPlaySound: false, - shouldSetBadge: false, + shouldSetBadge: !isCurrentConvo, } } diff --git a/src/lib/notifications/notifications.ts b/src/lib/notifications/notifications.ts index 52f984a59..1182bfcbb 100644 --- a/src/lib/notifications/notifications.ts +++ b/src/lib/notifications/notifications.ts @@ -1,5 +1,6 @@ import React from 'react' import * as Notifications from 'expo-notifications' +import {getBadgeCountAsync, setBadgeCountAsync} from 'expo-notifications' import {BskyAgent} from '@atproto/api' import {logger} from '#/logger' @@ -109,3 +110,14 @@ export function useRequestNotificationsPermission() { [gate], ) } + +export async function decrementBadgeCount(by = 1) { + if (!isNative) return + + const currCount = await getBadgeCountAsync() + let newCount = currCount - by + if (newCount < 0) { + newCount = 0 + } + await setBadgeCountAsync(newCount) +} |