Disable badge incrementing for DMs (#4088)
* disable badge increments for dms * revert decrementing in js for dms * reset badge on read notifications * remove some other code * prevent duplicate notification events
This commit is contained in:
parent
49314e2d1f
commit
d2c81c9d3d
6 changed files with 24 additions and 28 deletions
|
@ -46,8 +46,9 @@ const DEFAULT_HANDLER_OPTIONS = {
|
|||
shouldSetBadge: true,
|
||||
}
|
||||
|
||||
// This needs to stay outside the hook to persist between account switches
|
||||
// These need to stay outside the hook to persist between account switches
|
||||
let storedPayload: NotificationPayload | undefined
|
||||
let prevDate = 0
|
||||
|
||||
export function useNotificationsHandler() {
|
||||
const queryClient = useQueryClient()
|
||||
|
@ -58,9 +59,6 @@ export function useNotificationsHandler() {
|
|||
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||
const closeAllActiveElements = useCloseAllActiveElements()
|
||||
|
||||
// Safety to prevent double handling of the same notification
|
||||
const prevDate = React.useRef(0)
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isAndroid) return
|
||||
|
||||
|
@ -169,11 +167,10 @@ export function useNotificationsHandler() {
|
|||
payload.reason === 'chat-message' &&
|
||||
payload.recipientDid === currentAccount?.did
|
||||
) {
|
||||
const isCurrentConvo = payload.convoId === currentConvoId
|
||||
return {
|
||||
shouldShowAlert: !isCurrentConvo,
|
||||
shouldShowAlert: payload.convoId !== currentConvoId,
|
||||
shouldPlaySound: false,
|
||||
shouldSetBadge: !isCurrentConvo,
|
||||
shouldSetBadge: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,10 +182,10 @@ export function useNotificationsHandler() {
|
|||
|
||||
const responseReceivedListener =
|
||||
Notifications.addNotificationResponseReceivedListener(e => {
|
||||
if (e.notification.date === prevDate.current) {
|
||||
if (e.notification.date === prevDate) {
|
||||
return
|
||||
}
|
||||
prevDate.current = e.notification.date
|
||||
prevDate = e.notification.date
|
||||
|
||||
logger.debug(
|
||||
'Notifications: response received',
|
||||
|
|
|
@ -113,10 +113,16 @@ export function useRequestNotificationsPermission() {
|
|||
)
|
||||
}
|
||||
|
||||
export async function decrementBadgeCount(by = 1) {
|
||||
export async function decrementBadgeCount(by: number | 'reset' = 1) {
|
||||
if (!isNative) return
|
||||
|
||||
const currCount = await getBadgeCountAsync()
|
||||
|
||||
if (by === 'reset') {
|
||||
await setBadgeCountAsync(0)
|
||||
return
|
||||
}
|
||||
|
||||
let newCount = currCount - by
|
||||
if (newCount < 0) {
|
||||
newCount = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue