[🐴] 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
|
@ -10,6 +10,7 @@ import {
|
|||
import {useCurrentConvoId} from '#/state/messages/current-convo-id'
|
||||
import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {decrementBadgeCount} from 'lib/notifications/notifications'
|
||||
|
||||
export const RQKEY = ['convo-list']
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -116,10 +117,18 @@ export function useOnMarkAsRead() {
|
|||
return useCallback(
|
||||
(chatId: string) => {
|
||||
queryClient.setQueryData(RQKEY, (old: ConvoListQueryData) => {
|
||||
return optimisticUpdate(chatId, old, convo => ({
|
||||
...convo,
|
||||
unreadCount: 0,
|
||||
}))
|
||||
return optimisticUpdate(chatId, old, convo => {
|
||||
// We only want to decrement the badge by one no matter the unread count, since we only increment once per
|
||||
// sender regardless of message count
|
||||
if (convo.unreadCount > 0) {
|
||||
decrementBadgeCount(1)
|
||||
}
|
||||
|
||||
return {
|
||||
...convo,
|
||||
unreadCount: 0,
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
[queryClient],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue