about summary refs log tree commit diff
path: root/src/view/shell/index.tsx
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-05-13 09:19:35 -0700
committerGitHub <noreply@github.com>2024-05-13 09:19:35 -0700
commitd3406c89cf0c5b46197a87298dcd4e1326fef643 (patch)
tree6495ae6ca57f07077500a2e69f6cdc1c334be33e /src/view/shell/index.tsx
parent63b38b413d7a9e243646d11219b0959b3e59cc79 (diff)
downloadvoidsky-d3406c89cf0c5b46197a87298dcd4e1326fef643.tar.zst
Move request for notifications permissions to `HomeReadyScreen` (#3977)
* cleanup the current logic

* add statsig logs

* implement requests for permissions where needed

* oops

* let `addPushTokenListener` handle the token registration

* place new log event type with the other `notifications` type

* place registration next to handler

* more organization

* only call `gate()` if permission is not yet granted

* be more specific to prevent gate pollution

* nit

* make `token` non-optional in `registerToken`

* remove `prevDid`, move `registerPushToken` into `useEffect`

* keep it outside actually

* nit
Diffstat (limited to 'src/view/shell/index.tsx')
-rw-r--r--src/view/shell/index.tsx23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/view/shell/index.tsx b/src/view/shell/index.tsx
index 425c1b3f8..7d080e57b 100644
--- a/src/view/shell/index.tsx
+++ b/src/view/shell/index.tsx
@@ -13,7 +13,7 @@ import * as NavigationBar from 'expo-navigation-bar'
 import {StatusBar} from 'expo-status-bar'
 import {useNavigationState} from '@react-navigation/native'
 
-import {useAgent, useSession} from '#/state/session'
+import {useSession} from '#/state/session'
 import {
   useIsDrawerOpen,
   useIsDrawerSwipeDisabled,
@@ -22,7 +22,7 @@ import {
 import {useCloseAnyActiveElement} from '#/state/util'
 import {useNotificationsHandler} from 'lib/hooks/useNotificationHandler'
 import {usePalette} from 'lib/hooks/usePalette'
-import * as notifications from 'lib/notifications/notifications'
+import {useNotificationsRegistration} from 'lib/notifications/notifications'
 import {isStateAtTabRoot} from 'lib/routes/helpers'
 import {useTheme} from 'lib/ThemeContext'
 import {isAndroid} from 'platform/detection'
@@ -57,13 +57,11 @@ function ShellInner() {
     [setIsDrawerOpen],
   )
   const canGoBack = useNavigationState(state => !isStateAtTabRoot(state))
-  const {hasSession, currentAccount} = useSession()
-  const {getAgent} = useAgent()
+  const {hasSession} = useSession()
   const closeAnyActiveElement = useCloseAnyActiveElement()
   const {importantForAccessibility} = useDialogStateContext()
-  // start undefined
-  const currentAccountDid = React.useRef<string | undefined>(undefined)
 
+  useNotificationsRegistration()
   useNotificationsHandler()
 
   React.useEffect(() => {
@@ -78,19 +76,6 @@ function ShellInner() {
     }
   }, [closeAnyActiveElement])
 
-  React.useEffect(() => {
-    // only runs when did changes
-    if (currentAccount && currentAccountDid.current !== currentAccount.did) {
-      currentAccountDid.current = currentAccount.did
-      notifications.requestPermissionsAndRegisterToken(getAgent, currentAccount)
-      const unsub = notifications.registerTokenChangeHandler(
-        getAgent,
-        currentAccount,
-      )
-      return unsub
-    }
-  }, [currentAccount, getAgent])
-
   return (
     <>
       <Animated.View