[🐴] Decrement app badge when opening unread chat (#4040)
* decrement badge count for chats * handle decrement in `useMarkAsRead` * remove async * oops
This commit is contained in:
parent
4bceabc21c
commit
5e8650a204
3 changed files with 28 additions and 6 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue