Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

stop using `addPushTokenListener` (#4467)

* stop using push token listener

* cleanup the hack

* add a comment

* remove test code

* Fix patch

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>

authored by

Hailey
Dan Abramov
and committed by
GitHub
c73ad43a 4e9a6520

+19 -4
+1 -1
patches/expo-notifications+0.28.7.patch
··· 63 63 64 64 + @Nullable 65 65 + public String getChannelId() { 66 - + return mTitle; 66 + + return mChannelId; 67 67 + } 68 68 + 69 69 @Nullable
+18 -3
src/lib/notifications/notifications.ts
··· 6 6 import {logger} from '#/logger' 7 7 import {SessionAccount, useAgent, useSession} from '#/state/session' 8 8 import {logEvent, useGate} from 'lib/statsig/statsig' 9 - import {devicePlatform, isNative} from 'platform/detection' 9 + import {devicePlatform, isAndroid, isNative} from 'platform/detection' 10 10 import BackgroundNotificationHandler from '../../../modules/expo-background-notification-handler' 11 11 12 12 const SERVICE_DID = (serviceUrl?: string) => ··· 43 43 const granted = 44 44 skipPermissionCheck || (await Notifications.getPermissionsAsync()).granted 45 45 if (granted) { 46 - Notifications.getDevicePushTokenAsync() 46 + return Notifications.getDevicePushTokenAsync() 47 47 } 48 48 } 49 49 ··· 56 56 return 57 57 } 58 58 59 - getPushToken() 59 + // HACK - see https://github.com/bluesky-social/social-app/pull/4467 60 + // An apparent regression in expo-notifications causes `addPushTokenListener` to not fire on Android whenever the 61 + // token changes by calling `getPushToken()`. This is a workaround to ensure we register the token once it is 62 + // generated on Android. 63 + if (isAndroid) { 64 + ;(async () => { 65 + const token = await getPushToken() 66 + 67 + // Token will be undefined if we don't have notifications permission 68 + if (token) { 69 + registerPushToken(agent, currentAccount, token) 70 + } 71 + })() 72 + } else { 73 + getPushToken() 74 + } 60 75 61 76 // According to the Expo docs, there is a chance that the token will change while the app is open in some rare 62 77 // cases. This will fire `registerPushToken` whenever that happens.