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:
parent
7d158f82fb
commit
de38595a7a
2 changed files with 92 additions and 85 deletions
|
@ -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}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue