ring
ring copied to clipboard
Don't send old FCM tokens when new token is generated during startup
This fix stops the code from pushing the old FCM token to Ring when a new token is generated during registration, for example, due to migration to FCMv1 APIs for registration. The bug happens because the very last command in the push notification initialization sequence currently sends the FCM token to Ring any time credentials is defined:
if (credentials) {
onPushNotificationToken.next(credentials.fcm.token)
}
The problem with this is credentials is assigned prior to registration so it would still hold the old FCM token even if a new token was generated during the registration process. Because of this, the sequence of events was something like this:
- credentials = config.pnc (assuming credentials already existed)
- Push notification would register using existing credentials
- If registration updated the FCM token,
onCredentialsChanged()was called which subsequently pushed the new generated FCM token to Ring - However, because
crendentialswas previously defined and still contained the old FCM token, the command noted above would also run immediately pushing the old FCM token back to Ring thus making it impossible to receive notifications with the new push registration
The new code only pushes the stored FCM token if it was unchanged during registration.