From 5e8650a204cf4b52fa321e672801ce790b3cb554 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 16 May 2024 12:15:35 -0700 Subject: [🐴] Decrement app badge when opening unread chat (#4040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * decrement badge count for chats * handle decrement in `useMarkAsRead` * remove async * oops --- src/lib/notifications/notifications.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lib/notifications/notifications.ts') 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) +} -- cgit 1.4.1