Firebase messaging topics, logic [duplicate]

Lets say users subscribe to a topic, checkedIn_"restaurantId", meaning they (and I) gets notified when users check in at the restaurant with that id.

But, I want to avoid to get notified when I (myself) checks in to that restaurant.

How would one manage that?

I only see one way out: I unsubscribe from that topic, then sending message, then subscribe again.


Solution 1:

There is no way to exclude on user from a notification to a topic. The common way to implement is to separate message delivery, from the display of the notification on the device.

If you send a data only message with Firebase Cloud Messaging, it is *always` the responsibility of your application code to handle that message. So if you send the information about the check-in in a data-only message and include the ID of the user in that data, the receiving code can check whether that is their own message and not display a notification in that case.

To learn more, see:

  • the documentation about message types
  • Push notification to all the users subscribed to the topic except login user using FCM Firebase
  • How to exclude device from firebase topic messaging?