adjust notifications experiment by removing `canAskAgain` (#4271)
* adjust notifications experiment by removing `canAskAgain` * move to `StepFinished` for after onboardingzio/stable
parent
165feedb86
commit
eb6f44853d
|
@ -71,46 +71,41 @@ export function useNotificationsRegistration() {
|
||||||
|
|
||||||
export function useRequestNotificationsPermission() {
|
export function useRequestNotificationsPermission() {
|
||||||
const gate = useGate()
|
const gate = useGate()
|
||||||
const {currentAccount} = useSession()
|
|
||||||
|
|
||||||
return React.useCallback(
|
return async (context: 'StartOnboarding' | 'AfterOnboarding' | 'Login') => {
|
||||||
async (context: 'StartOnboarding' | 'AfterOnboarding' | 'Login') => {
|
const permissions = await Notifications.getPermissionsAsync()
|
||||||
const permissions = await Notifications.getPermissionsAsync()
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!currentAccount ||
|
!isNative ||
|
||||||
!isNative ||
|
permissions?.status === 'granted' ||
|
||||||
permissions?.status === 'granted' ||
|
permissions?.status === 'denied'
|
||||||
(permissions?.status === 'denied' && !permissions?.canAskAgain)
|
) {
|
||||||
) {
|
return
|
||||||
return
|
}
|
||||||
}
|
if (
|
||||||
if (
|
context === 'StartOnboarding' &&
|
||||||
context === 'StartOnboarding' &&
|
gate('request_notifications_permission_after_onboarding_v2')
|
||||||
gate('request_notifications_permission_after_onboarding')
|
) {
|
||||||
) {
|
return
|
||||||
return
|
}
|
||||||
}
|
if (
|
||||||
if (
|
context === 'AfterOnboarding' &&
|
||||||
context === 'AfterOnboarding' &&
|
!gate('request_notifications_permission_after_onboarding_v2')
|
||||||
!gate('request_notifications_permission_after_onboarding')
|
) {
|
||||||
) {
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const res = await Notifications.requestPermissionsAsync()
|
const res = await Notifications.requestPermissionsAsync()
|
||||||
logEvent('notifications:request', {
|
logEvent('notifications:request', {
|
||||||
context: context,
|
context: context,
|
||||||
status: res.status,
|
status: res.status,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res.granted) {
|
if (res.granted) {
|
||||||
// This will fire a pushTokenEvent, which will handle registration of the token
|
// This will fire a pushTokenEvent, which will handle registration of the token
|
||||||
getPushToken(true)
|
getPushToken(true)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
[gate, currentAccount],
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function decrementBadgeCount(by: number | 'reset' = 1) {
|
export async function decrementBadgeCount(by: number | 'reset' = 1) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export type Gate =
|
export type Gate =
|
||||||
// Keep this alphabetic please.
|
// Keep this alphabetic please.
|
||||||
| 'request_notifications_permission_after_onboarding'
|
| 'request_notifications_permission_after_onboarding_v2'
|
||||||
| 'show_follow_back_label_v2'
|
| 'show_follow_back_label_v2'
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {RQKEY as profileRQKey} from '#/state/queries/profile'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
import {useOnboardingDispatch} from '#/state/shell'
|
import {useOnboardingDispatch} from '#/state/shell'
|
||||||
import {uploadBlob} from 'lib/api'
|
import {uploadBlob} from 'lib/api'
|
||||||
|
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
||||||
import {
|
import {
|
||||||
DescriptionText,
|
DescriptionText,
|
||||||
OnboardingControls,
|
OnboardingControls,
|
||||||
|
@ -39,6 +40,7 @@ export function StepFinished() {
|
||||||
const [saving, setSaving] = React.useState(false)
|
const [saving, setSaving] = React.useState(false)
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||||
|
|
||||||
const finishOnboarding = React.useCallback(async () => {
|
const finishOnboarding = React.useCallback(async () => {
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
|
@ -72,6 +74,7 @@ export function StepFinished() {
|
||||||
: 'default',
|
: 'default',
|
||||||
})
|
})
|
||||||
})(),
|
})(),
|
||||||
|
requestNotificationsPermission('AfterOnboarding'),
|
||||||
])
|
])
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.info(`onboarding: bulk save failed`)
|
logger.info(`onboarding: bulk save failed`)
|
||||||
|
@ -98,7 +101,15 @@ export function StepFinished() {
|
||||||
track('OnboardingV2:StepFinished:End')
|
track('OnboardingV2:StepFinished:End')
|
||||||
track('OnboardingV2:Complete')
|
track('OnboardingV2:Complete')
|
||||||
logEvent('onboarding:finished:nextPressed', {})
|
logEvent('onboarding:finished:nextPressed', {})
|
||||||
}, [state, dispatch, onboardDispatch, setSaving, track, agent, queryClient])
|
}, [
|
||||||
|
state,
|
||||||
|
queryClient,
|
||||||
|
agent,
|
||||||
|
dispatch,
|
||||||
|
onboardDispatch,
|
||||||
|
track,
|
||||||
|
requestNotificationsPermission,
|
||||||
|
])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
track('OnboardingV2:StepFinished:Start')
|
track('OnboardingV2:StepFinished:Start')
|
||||||
|
|
|
@ -20,7 +20,6 @@ import {
|
||||||
} from '#/state/shell'
|
} from '#/state/shell'
|
||||||
import {useSelectedFeed, useSetSelectedFeed} from '#/state/shell/selected-feed'
|
import {useSelectedFeed, useSetSelectedFeed} from '#/state/shell/selected-feed'
|
||||||
import {useOTAUpdates} from 'lib/hooks/useOTAUpdates'
|
import {useOTAUpdates} from 'lib/hooks/useOTAUpdates'
|
||||||
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
|
||||||
import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
||||||
import {FeedPage} from 'view/com/feeds/FeedPage'
|
import {FeedPage} from 'view/com/feeds/FeedPage'
|
||||||
import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager'
|
import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager'
|
||||||
|
@ -59,8 +58,6 @@ function HomeScreenReady({
|
||||||
preferences: UsePreferencesQueryResponse
|
preferences: UsePreferencesQueryResponse
|
||||||
pinnedFeedInfos: SavedFeedSourceInfo[]
|
pinnedFeedInfos: SavedFeedSourceInfo[]
|
||||||
}) {
|
}) {
|
||||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
|
||||||
|
|
||||||
const allFeeds = React.useMemo(
|
const allFeeds = React.useMemo(
|
||||||
() => pinnedFeedInfos.map(f => f.feedDescriptor),
|
() => pinnedFeedInfos.map(f => f.feedDescriptor),
|
||||||
[pinnedFeedInfos],
|
[pinnedFeedInfos],
|
||||||
|
@ -74,10 +71,6 @@ function HomeScreenReady({
|
||||||
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
||||||
useOTAUpdates()
|
useOTAUpdates()
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
requestNotificationsPermission('AfterOnboarding')
|
|
||||||
}, [requestNotificationsPermission])
|
|
||||||
|
|
||||||
const pagerRef = React.useRef<PagerRef>(null)
|
const pagerRef = React.useRef<PagerRef>(null)
|
||||||
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
|
|
Loading…
Reference in New Issue