5

I am working on an app which has a group and there are multiple users who are part of the group and each user may have more than 1 device. I am using FCM for sending out notifications to update users about the group updates. Each user is subscribed to user_<user_id> topic from all of his/her devices. So to sending messages to the multiple people in the group, I am registering every user to the topic named like group_<grp_id> and then sending out the notification to the group will deliver it to all the subscribers on all their devices.

How ver I am finding it difficult when a user is removed from server side from a group, how to make sure that, that user is unsubscribed from the topic. So, I have planned that since user's all the working (active) registracion tokens will be subscribed to the topic, I can retrive those tokens and than firing batchRemove API call to InstanceId service will make sure that user is removed from getting updates from the group immediately without waiting for the device getting online and un-registering from the group topic.

But it seems there isn't any API available to retrive token's list of a given topic as per this documentation. Handling each registration tokens by saving to server and removing old tokens when not needed will add a unnesessary burden on the server.

Is there any way to retrive list of token of a topic so that I can remove them from the group?

kirtan403
  • 7,293
  • 6
  • 54
  • 97

1 Answers1

3

EDIT:

As of the moment, the way to do this is to make use of the Instance ID API, and proceeding with checking which registration tokens must be removed/kept.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • In my case group doesn't belong to the single user. It has multiple users each having 1 or more devices. And I should deliver the messages to all the devices of all the users – kirtan403 Nov 14 '16 at 14:13
  • @kirtan403 I see. That is a bit of a tricky situation. I'll take a look around and update my answer later on. – AL. Nov 14 '16 at 14:25
  • Thanks :) The issue is if I will send a topic message to a userA for example to tell it to unsubscribe from the topic and if the device remains offline for some time, the messages sent between these duration will be delivered along with the message to unsubscribe from that topic. That should not happen. – kirtan403 Nov 14 '16 at 14:28
  • So removing it from the server side should do the trick. I think I need to stack up all the Instance id a user registers. And then use it to unregister from the group. But it leads to some high no of unused/expired tokens after some time – kirtan403 Nov 14 '16 at 14:30
  • @kirtan403 So far, I think doing it in your App Server is the way to go. Making use of the InstanceID call you already mentioned. – AL. Nov 14 '16 at 14:34
  • 1
    But that needs to store that dirty looking tokens on the database. But doesn't look like any other option here. Thank you for looking into it :) – kirtan403 Nov 14 '16 at 14:36