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
This commit is contained in:
dan 2023-12-06 18:05:59 +00:00 committed by GitHub
parent 7d158f82fb
commit de38595a7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 85 deletions

View file

@ -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}>