diff options
author | Hailey <me@haileyok.com> | 2024-05-09 10:04:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 10:04:05 -0700 |
commit | 17e3b946cb5fb59f5d8cd115906daa38ca8a8124 (patch) | |
tree | 59a28bc365b3154ac073aa03a3afa2517c93b1a6 /src/lib/notifications/notifications.ts | |
parent | 13418455376bb6573c45f5fb4a023cab34d40d3e (diff) | |
download | voidsky-17e3b946cb5fb59f5d8cd115906daa38ca8a8124.tar.zst |
Handle push notifications for DMs (#3895)
* add some better handling for notifications prep merge move `useNotificationsListener` into shell progress better structure only show messages notifications while using app if it is the current account progress only emit on native current chat emitter only show alerts for the current chat type add logs setup handlers * remove event emitter * just needs cleanup * oops * remove unnecessary `queryClient` param * few fixes * cleanup * nit * remove folds * remove comment * simplify if * add back invalidate * comment out other navigations for now * rename type * handle various navigation cases * push to conversation from notification * update badge in all cases except `chat-message` * ensure no duplicate notifications * rm unused `animationOnReplace` * revert to using `goBack` in the conversation header * add todo comment
Diffstat (limited to 'src/lib/notifications/notifications.ts')
-rw-r--r-- | src/lib/notifications/notifications.ts | 74 |
1 files changed, 1 insertions, 73 deletions
diff --git a/src/lib/notifications/notifications.ts b/src/lib/notifications/notifications.ts index b0bbc1bf9..38c18bf3f 100644 --- a/src/lib/notifications/notifications.ts +++ b/src/lib/notifications/notifications.ts @@ -1,17 +1,9 @@ -import {useEffect} from 'react' import * as Notifications from 'expo-notifications' import {BskyAgent} from '@atproto/api' -import {QueryClient} from '@tanstack/react-query' import {logger} from '#/logger' -import {RQKEY as RQKEY_NOTIFS} from '#/state/queries/notifications/feed' -import {invalidateCachedUnreadPage} from '#/state/queries/notifications/unread' -import {truncateAndInvalidate} from '#/state/queries/util' import {SessionAccount} from '#/state/session' -import {track} from 'lib/analytics/analytics' -import {devicePlatform, isIOS} from 'platform/detection' -import {resetToTab} from '../../Navigation' -import {logEvent} from '../statsig/statsig' +import {devicePlatform} from 'platform/detection' const SERVICE_DID = (serviceUrl?: string) => serviceUrl?.includes('staging') @@ -85,67 +77,3 @@ export function registerTokenChangeHandler( sub.remove() } } - -export function useNotificationsListener(queryClient: QueryClient) { - useEffect(() => { - // handle notifications that are received, both in the foreground or background - // NOTE: currently just here for debug logging - const sub1 = Notifications.addNotificationReceivedListener(event => { - invalidateCachedUnreadPage() - logger.debug( - 'Notifications: received', - {event}, - logger.DebugContext.notifications, - ) - if (event.request.trigger.type === 'push') { - // handle payload-based deeplinks - let payload - if (isIOS) { - payload = event.request.trigger.payload - } else { - // TODO: handle android payload deeplink - } - if (payload) { - logger.debug( - 'Notifications: received payload', - payload, - logger.DebugContext.notifications, - ) - // TODO: deeplink notif here - } - } - }) - - // handle notifications that are tapped on - const sub2 = Notifications.addNotificationResponseReceivedListener( - response => { - logger.debug( - 'Notifications: response received', - { - actionIdentifier: response.actionIdentifier, - }, - logger.DebugContext.notifications, - ) - if ( - response.actionIdentifier === Notifications.DEFAULT_ACTION_IDENTIFIER - ) { - logger.debug( - 'User pressed a notification, opening notifications tab', - {}, - logger.DebugContext.notifications, - ) - track('Notificatons:OpenApp') - logEvent('notifications:openApp', {}) - invalidateCachedUnreadPage() - truncateAndInvalidate(queryClient, RQKEY_NOTIFS()) - resetToTab('NotificationsTab') // open notifications tab - } - }, - ) - - return () => { - sub1.remove() - sub2.remove() - } - }, [queryClient]) -} |