Check `canAskAgain` for notification permissions (#4460)
parent
90ec22a674
commit
5dd195bcb7
|
@ -72,14 +72,17 @@ export function useNotificationsRegistration() {
|
|||
|
||||
export function useRequestNotificationsPermission() {
|
||||
const gate = useGate()
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
return async (context: 'StartOnboarding' | 'AfterOnboarding' | 'Login') => {
|
||||
return async (
|
||||
context: 'StartOnboarding' | 'AfterOnboarding' | 'Login' | 'Home',
|
||||
) => {
|
||||
const permissions = await Notifications.getPermissionsAsync()
|
||||
|
||||
if (
|
||||
!isNative ||
|
||||
permissions?.status === 'granted' ||
|
||||
permissions?.status === 'denied'
|
||||
(permissions?.status === 'denied' && !permissions.canAskAgain)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
@ -95,6 +98,9 @@ export function useRequestNotificationsPermission() {
|
|||
) {
|
||||
return
|
||||
}
|
||||
if (context === 'Home' && !currentAccount) {
|
||||
return
|
||||
}
|
||||
|
||||
const res = await Notifications.requestPermissionsAsync()
|
||||
logEvent('notifications:request', {
|
||||
|
|
|
@ -17,7 +17,7 @@ export type LogEvents = {
|
|||
}
|
||||
'notifications:openApp': {}
|
||||
'notifications:request': {
|
||||
context: 'StartOnboarding' | 'AfterOnboarding' | 'Login'
|
||||
context: 'StartOnboarding' | 'AfterOnboarding' | 'Login' | 'Home'
|
||||
status: 'granted' | 'denied' | 'undetermined'
|
||||
}
|
||||
'state:background:sampled': {
|
||||
|
|
|
@ -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'
|
||||
|
@ -67,10 +68,15 @@ function HomeScreenReady({
|
|||
const maybeFoundIndex = allFeeds.indexOf(rawSelectedFeed)
|
||||
const selectedIndex = Math.max(0, maybeFoundIndex)
|
||||
const selectedFeed = allFeeds[selectedIndex]
|
||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||
|
||||
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
||||
useOTAUpdates()
|
||||
|
||||
React.useEffect(() => {
|
||||
requestNotificationsPermission('Home')
|
||||
}, [requestNotificationsPermission])
|
||||
|
||||
const pagerRef = React.useRef<PagerRef>(null)
|
||||
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
||||
React.useLayoutEffect(() => {
|
||||
|
|
Loading…
Reference in New Issue