OdyseeTeam / odysee-frontend

The code that runs odysee.com
https://odysee.com
MIT License
213 stars 68 forks source link

automatically resubscribe to firebase token if removed #992

Open tzarebczan opened 2 years ago

tzarebczan commented 2 years ago

Sometimes a firebase token can get invalidated, and later needs to be re-subscribed to.

Not sure how we track the state of browser notifications, but if we know they should be enabled, and the get call for the token call fails, re-run the call to add it back.

If we don't store anything else to tell that we should have notifications on, we can start storing for new ones in localstorage maybe?

tzarebczan commented 2 years ago

This was the relevant code, didn't check where/how it's invoked:

const validate = async (userId: number) => {
  if (!hasRegistration(userId)) return;
  window.requestIdleCallback(async () => {
    const serverTokens = await Lbryio.call('cfm', 'list');
    const fcmToken = await getFcmToken();
    if (!fcmToken) return;
    const exists = serverTokens.find((item) => item.value === fcmToken);
    if (!exists) {
      await subscribe(userId, false);
    }
  });
};
tzarebczan commented 2 years ago

per @toshokanneko , it's called on sign in only