Bluesky app fork with some witchin' additions 💫

register the push token after request has been approved on android (#4481)

* register the push token after request has been approved on android

* use a `0` string for badge count

* Revert "use a `0` string for badge count"

This reverts commit efac39861817f4237c58211f68ef266d919b4d40.

* temporary fix

authored by hailey.at and committed by

GitHub fac5f6cd 808dd356

+18 -2
+15 -1
src/lib/notifications/notifications.ts
··· 88 88 export function useRequestNotificationsPermission() { 89 89 const gate = useGate() 90 90 const {currentAccount} = useSession() 91 + const agent = useAgent() 91 92 92 93 return async ( 93 94 context: 'StartOnboarding' | 'AfterOnboarding' | 'Login' | 'Home', ··· 125 126 126 127 if (res.granted) { 127 128 // This will fire a pushTokenEvent, which will handle registration of the token 128 - getPushToken(true) 129 + const token = await getPushToken(true) 130 + 131 + // Same hack as above. We cannot rely on the `addPushTokenListener` to fire on Android due to an Expo bug, so we 132 + // will manually register it here. Note that this will occur only: 133 + // 1. right after the user signs in, leading to no `currentAccount` account being available - this will be instead 134 + // picked up from the useEffect above on `currentAccount` change 135 + // 2. right after onboarding. In this case, we _need_ this registration, since `currentAccount` will not change 136 + // and we need to ensure the token is registered right after permission is granted. `currentAccount` will already 137 + // be available in this case, so the registration will succeed. 138 + // We should remove this once expo-notifications (and possibly FCMv1) is fixed and the `addPushTokenListener` is 139 + // working again. See https://github.com/expo/expo/issues/28656 140 + if (isAndroid && currentAccount && token) { 141 + registerPushToken(agent, currentAccount, token) 142 + } 129 143 } 130 144 } 131 145 }
+3 -1
src/screens/Messages/List/ChatListItem.tsx
··· 20 20 import {useModerationOpts} from '#/state/preferences/moderation-opts' 21 21 import {useSession} from '#/state/session' 22 22 import {useHaptics} from 'lib/haptics' 23 + import {decrementBadgeCount} from 'lib/notifications/notifications' 23 24 import {logEvent} from 'lib/statsig/statsig' 24 25 import {sanitizeDisplayName} from 'lib/strings/display-names' 25 26 import {TimeElapsed} from '#/view/com/util/TimeElapsed' ··· 177 178 178 179 const onPress = useCallback( 179 180 (e: GestureResponderEvent) => { 181 + decrementBadgeCount(convo.unreadCount) 180 182 if (isDeletedAccount) { 181 183 e.preventDefault() 182 184 menuControl.open() ··· 185 187 logEvent('chat:open', {logContext: 'ChatsList'}) 186 188 } 187 189 }, 188 - [isDeletedAccount, menuControl], 190 + [convo.unreadCount, isDeletedAccount, menuControl], 189 191 ) 190 192 191 193 const onLongPress = useCallback(() => {