Simplify
This commit is contained in:
@@ -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
|
/**
|
||||||
* time this runs, and this should fire that listener automatically to
|
* If we have an account in scope, we can safely call
|
||||||
* register the token with our server. If for some reason it does not, we
|
* `getAndRegisterPushToken`.
|
||||||
* have a fallback below. See above for more info.
|
*/
|
||||||
*/
|
getAndRegisterPushToken(agent, currentAccount)
|
||||||
const token = await getPushToken()
|
} else {
|
||||||
|
/**
|
||||||
/**
|
* Right after login, `currentAccount` in this scope will be undefined,
|
||||||
* This call is our insurance policy in case `addPushTokenListener`
|
* but calling `getPushToken` will result in `addPushTokenListener`
|
||||||
* didn't fire as a result of `getPushToken`. See comments above for more
|
* listeners being called, which will handle the registration with the
|
||||||
* details.
|
* Bluesky server.
|
||||||
*
|
*/
|
||||||
* Right after login, `currentAccount` in this scope will be undefined,
|
getPushToken()
|
||||||
* hence the guard here. For other callsites, it should be defined
|
|
||||||
* already.
|
|
||||||
*/
|
|
||||||
if (token && currentAccount) {
|
|
||||||
registerPushToken(agent, currentAccount, token)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user