diff options
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/screens/Home.tsx | 11 | ||||
-rw-r--r-- | src/view/shell/index.tsx | 23 |
2 files changed, 13 insertions, 21 deletions
diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index bd17e5fe4..d2d31ce6a 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -20,6 +20,7 @@ import { } from '#/state/shell' import {useSelectedFeed, useSetSelectedFeed} from '#/state/shell/selected-feed' import {useOTAUpdates} from 'lib/hooks/useOTAUpdates' +import {useRequestNotificationsPermission} from 'lib/notifications/notifications' import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types' import {FeedPage} from 'view/com/feeds/FeedPage' import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager' @@ -58,7 +59,9 @@ function HomeScreenReady({ preferences: UsePreferencesQueryResponse pinnedFeedInfos: SavedFeedSourceInfo[] }) { - useOTAUpdates() + const gate = useGate() + const requestNotificationsPermission = useRequestNotificationsPermission() + const allFeeds = React.useMemo( () => pinnedFeedInfos.map(f => f.feedDescriptor), [pinnedFeedInfos], @@ -70,6 +73,11 @@ function HomeScreenReady({ const selectedFeed = allFeeds[selectedIndex] useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName) + useOTAUpdates() + + React.useEffect(() => { + requestNotificationsPermission('AfterOnboarding') + }, [requestNotificationsPermission]) const pagerRef = React.useRef<PagerRef>(null) const lastPagerReportedIndexRef = React.useRef(selectedIndex) @@ -109,7 +117,6 @@ function HomeScreenReady({ }), ) - const gate = useGate() const mode = useMinimalShellMode() const {isMobile} = useWebMediaQueries() useFocusEffect( 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 |