This commit is contained in:
Eric Bailey
2025-06-24 19:04:33 -05:00
parent c79234ec03
commit dba9f59a70
+12 -14
View File
@@ -126,6 +126,9 @@ export function useNotificationsRegistration() {
getAndRegisterPushToken(agent, currentAccount) getAndRegisterPushToken(agent, currentAccount)
/** /**
* Register the push token with the Bluesky server, whenever it changes.
* This is also fired any time `getDevicePushTokenAsync` is called.
*
* According to the Expo docs, there is a chance that the token will change * According to the Expo docs, there is a chance that the token will change
* while the app is open in some rare cases. This will fire * while the app is open in some rare cases. This will fire
* `registerPushToken` whenever that happens. * `registerPushToken` whenever that happens.
@@ -174,25 +177,20 @@ export function useRequestNotificationsPermission() {
}) })
if (res.granted) { if (res.granted) {
if (currentAccount) {
/** /**
* Load bearing. The `addPushTokenListener` will be registered by the * If we have an account in scope, we can safely call
* time this runs, and this should fire that listener automatically to * `getAndRegisterPushToken`.
* register the token with our server. If for some reason it does not, we
* have a fallback below. See above for more info.
*/ */
const token = await getPushToken() getAndRegisterPushToken(agent, currentAccount)
} else {
/** /**
* This call is our insurance policy in case `addPushTokenListener`
* didn't fire as a result of `getPushToken`. See comments above for more
* details.
*
* Right after login, `currentAccount` in this scope will be undefined, * Right after login, `currentAccount` in this scope will be undefined,
* hence the guard here. For other callsites, it should be defined * but calling `getPushToken` will result in `addPushTokenListener`
* already. * listeners being called, which will handle the registration with the
* Bluesky server.
*/ */
if (token && currentAccount) { getPushToken()
registerPushToken(agent, currentAccount, token)
} }
} }
} }