How to use Firebase push messaging depends on the user's account status at the device

Viewed 182

I've read all the documents of Firebase messaging,
but in my use case, I don't know how I should implement it...

In my use case :

The User can sign in at multiple devices.
Whenever an user has signed in at the specific device, the device should get notified when the user account receives any event.

This might be a little complex, but please take a look at the three situations below :

enter image description here

Each number of situation:

  1. User A signs in at Device 1, so Device 1 will get notified for User A.
  2. Now User A signs in at Device 2 as well, so both Device 1 and Device 2 should get notified for User A.
  3. Then finally User B signs in at Device 1, so Device 1 no longer get notified for User A, instead, it will get notified for User B now.

The lifetime of the User and the FirebaseInstance Token are different, so how could I make this? (I have a backend server to store the registration Id.) What's in my brain:

For 1 situation: To simply get the device token and save to the backend database.

For 2 situation: For this situation, I need to create a RegistrationToken table for saving multiple device's token with a relationship with User so that one user can own multiple registration tokens.

For 3 situation: Update the relationship to User B instead of User A if the token exists in the database.

But I think those solutions will be a hard work and uncommon, please tell me how do you solve this problem?

1 Answers
Related