mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
* To MMKV migration working * POC migrated font size settings * Moved settings to mmkv * Fix typos * Migrated contexts slice * Migrated app slice * POC instance emoji update * Migrated drafts * Migrated simple instance properties * All migrated! * Re-structure files * Tolerant of undefined settings * Can properly logging in and out including empty state
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import queryClient from '@utils/queryHooks'
|
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
|
import { generateAccountKey, setAccount, useGlobalStorage } from '@utils/storage/actions'
|
|
import * as Notifications from 'expo-notifications'
|
|
import { useEffect } from 'react'
|
|
import pushUseNavigate from './useNavigate'
|
|
|
|
const pushUseRespond = () => {
|
|
const [accounts] = useGlobalStorage.object('accounts')
|
|
|
|
useEffect(() => {
|
|
const subscription = Notifications.addNotificationResponseReceivedListener(
|
|
({ notification }) => {
|
|
const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Notifications' }]
|
|
queryClient.invalidateQueries(queryKey)
|
|
const payloadData = notification.request.content.data as {
|
|
notification_id?: string
|
|
instanceUrl: string
|
|
accountId: string
|
|
}
|
|
|
|
const currAccount = accounts?.find(
|
|
account =>
|
|
account ===
|
|
generateAccountKey({ domain: payloadData.instanceUrl, id: payloadData.accountId })
|
|
)
|
|
if (currAccount) {
|
|
setAccount(currAccount)
|
|
}
|
|
pushUseNavigate(payloadData.notification_id)
|
|
}
|
|
)
|
|
return () => subscription.remove()
|
|
}, [accounts])
|
|
}
|
|
|
|
export default pushUseRespond
|