about summary refs log tree commit diff
path: root/src/view/shell/index.tsx
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2023-12-06 18:05:59 +0000
committerGitHub <noreply@github.com>2023-12-06 10:05:59 -0800
commitde38595a7a04e3dfe67c5251472f1817152b8116 (patch)
treee5a227e614b26368d52e9a91f9c0cb007e251497 /src/view/shell/index.tsx
parent7d158f82fb1c82101c3a0cb637f911ac87e8006b (diff)
downloadvoidsky-de38595a7a04e3dfe67c5251472f1817152b8116.tar.zst
Split notification init, add cleanup (#2102)
* Inline never-imported export

* Remove pretense at handling cleanup

* Extract per-session listener to a function

* Split notifications.init() from notifications.onSessionLoaded()

* Tweak forked code to be more similar

* Remove unnecessary guards

* Split notifications.onSessionLoaded in two

* Always use getAgent()

* Remove dep on listenSessionLoaded, add cleanup
Diffstat (limited to 'src/view/shell/index.tsx')
-rw-r--r--src/view/shell/index.tsx16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/view/shell/index.tsx b/src/view/shell/index.tsx
index 5562af9ac..18042c7ed 100644
--- a/src/view/shell/index.tsx
+++ b/src/view/shell/index.tsx
@@ -31,6 +31,7 @@ import {
 import {isAndroid} from 'platform/detection'
 import {useSession} from '#/state/session'
 import {useCloseAnyActiveElement} from '#/state/util'
+import * as notifications from 'lib/notifications/notifications'
 
 function ShellInner() {
   const isDrawerOpen = useIsDrawerOpen()
@@ -52,7 +53,7 @@ function ShellInner() {
     [setIsDrawerOpen],
   )
   const canGoBack = useNavigationState(state => !isStateAtTabRoot(state))
-  const {hasSession} = useSession()
+  const {hasSession, currentAccount} = useSession()
   const closeAnyActiveElement = useCloseAnyActiveElement()
 
   React.useEffect(() => {
@@ -67,6 +68,19 @@ function ShellInner() {
     }
   }, [closeAnyActiveElement])
 
+  React.useEffect(() => {
+    if (currentAccount) {
+      notifications.requestPermissionsAndRegisterToken(currentAccount)
+    }
+  }, [currentAccount])
+
+  React.useEffect(() => {
+    if (currentAccount) {
+      const unsub = notifications.registerTokenChangeHandler(currentAccount)
+      return unsub
+    }
+  }, [currentAccount])
+
   return (
     <>
       <View style={containerPadding}>