0

Having a tricky problem. I have firebase messaging, recording tokens in the database (as prescribed). Then I'm running triggers to send to topics (using functions). I noticed a bug when unsubscribing from a topic (had a space in the name - since fixed) , so the user didn't get to unsubscribe properly. Ever since they are getting that topic. Just wondering if theres a way of deleting old tokens / expiring - then unsubscribing from all topics. Basically I'm looking to create a "reset" button of sorts incase this ever happens again.

I had the same issue on my profile. However my cure (and test) was to delete and recreate my profile. Not an ideal solution! Everything worked great again after that.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
kierandes
  • 161
  • 3
  • 16
  • if the topic had space, then how was the user able to subscribe to it? – Peter Haddad Feb 23 '18 at 10:59
  • I had fixed that issue in subscribing and somehow forgot to apply to unsubscribing. Late night coding :) – kierandes Feb 23 '18 at 11:03
  • I know - I had removed any spaces in topics when subscribing (and added some code to prevent spaces) . It is subscribing to that topic successfully now. – kierandes Feb 23 '18 at 11:07

1 Answers1

1

Basically I'm looking to create a "reset" button of sorts incase this ever happens again.

Currently you cannot do that, topics are based on publish/subscribe model. Therefore the user who subscribes to a topic has to unsubscribe using his own phone to stop receiving notifications related to that topic.

If you created a topic by accident and all users unsubscribe from it, then it is no longer a topic and no one will be able to subscribe to it or receive any notification related to it.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • Ok, so I should perhaps have the phone itself manage subscriptions rather than in the database? Oh, then if I had a tag called "AllAreas" for example - I subscribed then unsubscribed and the only other person unsubscribes. It removes the topic?? That would explain some strange behaviour then. Because one person had that tag and are not getting all the pushes (as it was setup to ). – kierandes Feb 24 '18 at 10:47
  • yes the phone is gonna manage subscription anyway. When a user subscribes to a topic then the phone is subscribed to that topic, so when he unsubscribes from that phone he won't receive notification from that topic. You can store the topic of each user in the database if you want. – Peter Haddad Feb 24 '18 at 10:49
  • Ok. Yes at the moment I'm storing the topic and the phone token of each user. Then as they add a topic or remove a topic, I take the last token submitted to the database and subscribe / unsubscribe accordingly. Its working for 99% of people except one. With the tokens, do older tokens expire as soon as you get a new one? Or does method swizzling hold onto and map messages to old tokens too? My worry being that I'm grabbing the wrong token and that messages for a topic - e.g. "AllAreas" are not going to the right target. – kierandes Feb 24 '18 at 10:53
  • check this https://stackoverflow.com/questions/48588962/get-receivers-device-token-to-send-notification-in-firebase/48589608 – Peter Haddad Feb 24 '18 at 12:45