diff options
author | Hailey <me@haileyok.com> | 2024-05-16 12:15:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-16 12:15:35 -0700 |
commit | 5e8650a204cf4b52fa321e672801ce790b3cb554 (patch) | |
tree | 74ed00ea36605acf344c983d637ff8ae4855c429 /src/lib/notifications/notifications.ts | |
parent | 4bceabc21cacd865f5b10684142485faca2c9bb4 (diff) | |
download | voidsky-5e8650a204cf4b52fa321e672801ce790b3cb554.tar.zst |
[🐴] Decrement app badge when opening unread chat (#4040)
* decrement badge count for chats * handle decrement in `useMarkAsRead` * remove async * oops
Diffstat (limited to 'src/lib/notifications/notifications.ts')
-rw-r--r-- | src/lib/notifications/notifications.ts | 12 |
1 files changed, 12 insertions, 0 deletions
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) +} |