Also on iOS
This commit is contained in:
xmflsct 2023-01-26 23:55:48 +01:00
parent 922d7c7917
commit 4b8885ef2c
2 changed files with 20 additions and 18 deletions

View File

@ -7,6 +7,7 @@ import { useEffect } from 'react'
import pushUseNavigate from './useNavigate' import pushUseNavigate from './useNavigate'
const pushUseReceive = () => { const pushUseReceive = () => {
const [accountActive] = useGlobalStorage.string('account.active')
const [accounts] = useGlobalStorage.object('accounts') const [accounts] = useGlobalStorage.object('accounts')
useEffect(() => { useEffect(() => {
@ -19,25 +20,25 @@ const pushUseReceive = () => {
accountId: string accountId: string
} }
const currAccount = accounts?.find( const incomingAccount = generateAccountKey({
account => domain: payloadData.instanceUrl,
account === id: payloadData.accountId
generateAccountKey({ domain: payloadData.instanceUrl, id: payloadData.accountId }) })
) const foundAccount = accounts?.find(account => account === incomingAccount)
displayMessage({ displayMessage({
duration: 'long', duration: 'long',
message: notification.request.content.title!, message: notification.request.content.title!,
description: notification.request.content.body!, description: notification.request.content.body!,
onPress: () => { onPress: async () => {
if (currAccount) { if (foundAccount && foundAccount !== accountActive) {
setAccount(currAccount) await setAccount(foundAccount)
} }
pushUseNavigate(payloadData.notification_id) pushUseNavigate(payloadData.notification_id)
} }
}) })
}) })
return () => subscription.remove() return () => subscription.remove()
}, [accounts]) }, [accountActive, accounts])
} }
export default pushUseReceive export default pushUseReceive

View File

@ -6,11 +6,12 @@ import { useEffect } from 'react'
import pushUseNavigate from './useNavigate' import pushUseNavigate from './useNavigate'
const pushUseRespond = () => { const pushUseRespond = () => {
const [accountActive] = useGlobalStorage.string('account.active')
const [accounts] = useGlobalStorage.object('accounts') const [accounts] = useGlobalStorage.object('accounts')
useEffect(() => { useEffect(() => {
const subscription = Notifications.addNotificationResponseReceivedListener( const subscription = Notifications.addNotificationResponseReceivedListener(
({ notification }) => { async ({ notification }) => {
const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Notifications' }] const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Notifications' }]
queryClient.invalidateQueries(queryKey) queryClient.invalidateQueries(queryKey)
const payloadData = notification.request.content.data as { const payloadData = notification.request.content.data as {
@ -19,19 +20,19 @@ const pushUseRespond = () => {
accountId: string accountId: string
} }
const currAccount = accounts?.find( const incomingAccount = generateAccountKey({
account => domain: payloadData.instanceUrl,
account === id: payloadData.accountId
generateAccountKey({ domain: payloadData.instanceUrl, id: payloadData.accountId }) })
) const foundAccount = accounts?.find(account => account === incomingAccount)
if (currAccount) { if (foundAccount && foundAccount !== accountActive) {
setAccount(currAccount) await setAccount(foundAccount)
} }
pushUseNavigate(payloadData.notification_id) pushUseNavigate(payloadData.notification_id)
} }
) )
return () => subscription.remove() return () => subscription.remove()
}, [accounts]) }, [accountActive, accounts])
} }
export default pushUseRespond export default pushUseRespond