diff --git a/src/utils/push/useReceive.ts b/src/utils/push/useReceive.ts index 6af388c9..89bd88c6 100644 --- a/src/utils/push/useReceive.ts +++ b/src/utils/push/useReceive.ts @@ -7,6 +7,7 @@ import { useEffect } from 'react' import pushUseNavigate from './useNavigate' const pushUseReceive = () => { + const [accountActive] = useGlobalStorage.string('account.active') const [accounts] = useGlobalStorage.object('accounts') useEffect(() => { @@ -19,25 +20,25 @@ const pushUseReceive = () => { accountId: string } - const currAccount = accounts?.find( - account => - account === - generateAccountKey({ domain: payloadData.instanceUrl, id: payloadData.accountId }) - ) + const incomingAccount = generateAccountKey({ + domain: payloadData.instanceUrl, + id: payloadData.accountId + }) + const foundAccount = accounts?.find(account => account === incomingAccount) displayMessage({ duration: 'long', message: notification.request.content.title!, description: notification.request.content.body!, - onPress: () => { - if (currAccount) { - setAccount(currAccount) + onPress: async () => { + if (foundAccount && foundAccount !== accountActive) { + await setAccount(foundAccount) } pushUseNavigate(payloadData.notification_id) } }) }) return () => subscription.remove() - }, [accounts]) + }, [accountActive, accounts]) } export default pushUseReceive diff --git a/src/utils/push/useRespond.ts b/src/utils/push/useRespond.ts index e20f14f7..c44a06cc 100644 --- a/src/utils/push/useRespond.ts +++ b/src/utils/push/useRespond.ts @@ -6,11 +6,12 @@ import { useEffect } from 'react' import pushUseNavigate from './useNavigate' const pushUseRespond = () => { + const [accountActive] = useGlobalStorage.string('account.active') const [accounts] = useGlobalStorage.object('accounts') useEffect(() => { const subscription = Notifications.addNotificationResponseReceivedListener( - ({ notification }) => { + async ({ notification }) => { const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Notifications' }] queryClient.invalidateQueries(queryKey) const payloadData = notification.request.content.data as { @@ -19,19 +20,19 @@ const pushUseRespond = () => { accountId: string } - const currAccount = accounts?.find( - account => - account === - generateAccountKey({ domain: payloadData.instanceUrl, id: payloadData.accountId }) - ) - if (currAccount) { - setAccount(currAccount) + const incomingAccount = generateAccountKey({ + domain: payloadData.instanceUrl, + id: payloadData.accountId + }) + const foundAccount = accounts?.find(account => account === incomingAccount) + if (foundAccount && foundAccount !== accountActive) { + await setAccount(foundAccount) } pushUseNavigate(payloadData.notification_id) } ) return () => subscription.remove() - }, [accounts]) + }, [accountActive, accounts]) } export default pushUseRespond