diff options
author | Hailey <me@haileyok.com> | 2024-06-07 15:15:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-07 15:15:33 -0700 |
commit | 480a40862f329f98a37772f01fd774d0e6d89a9e (patch) | |
tree | ad39ad65806cb51694d0a92feee8337c7f454aa4 /src/lib | |
parent | c58aedf050ea96ece27549b4c5a084611473db9d (diff) | |
download | voidsky-480a40862f329f98a37772f01fd774d0e6d89a9e.tar.zst |
Use the proper logic on iOS to increment the badge (#4233)
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/notifications/notifications.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/lib/notifications/notifications.ts b/src/lib/notifications/notifications.ts index 705d90c56..55a7948ef 100644 --- a/src/lib/notifications/notifications.ts +++ b/src/lib/notifications/notifications.ts @@ -7,6 +7,7 @@ import {logger} from '#/logger' import {SessionAccount, useAgent, useSession} from '#/state/session' import {logEvent, useGate} from 'lib/statsig/statsig' import {devicePlatform, isNative} from 'platform/detection' +import BackgroundNotificationHandler from '../../../modules/expo-background-notification-handler' const SERVICE_DID = (serviceUrl?: string) => serviceUrl?.includes('staging') @@ -108,19 +109,20 @@ export function useRequestNotificationsPermission() { } } -export async function decrementBadgeCount(by: number | 'reset' = 1) { +export async function decrementBadgeCount(by: number) { if (!isNative) return - const currCount = await getBadgeCountAsync() - - if (by === 'reset') { - await setBadgeCountAsync(0) - return + let count = await getBadgeCountAsync() + count -= by + if (count < 0) { + count = 0 } - let newCount = currCount - by - if (newCount < 0) { - newCount = 0 - } - await setBadgeCountAsync(newCount) + await BackgroundNotificationHandler.setBadgeCountAsync(count) + await setBadgeCountAsync(count) +} + +export async function resetBadgeCount() { + await BackgroundNotificationHandler.setBadgeCountAsync(0) + await setBadgeCountAsync(0) } |