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'
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

View File

@ -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