mirror of
https://github.com/tooot-app/app
synced 2025-02-11 17:30:50 +01:00
parent
922d7c7917
commit
4b8885ef2c
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user