OOD Waterball
OOD Waterball

Reputation: 801

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

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?

Upvotes: 3

Views: 191

Answers (1)

Snehal Gongle
Snehal Gongle

Reputation: 337

What i will suggest is that when you are registering a new user make a coloum in your database called token to store the firebase device id token So when the new user register you will get a new token assigned to its username Then with every login and log out attempts change the firebase id token This means that when ever someone will login from any device its token will be updated in database and when the user logout just pass null value to it hence you can ensure that users always get the right token according to usernames

Hope it helps...

Upvotes: 1

Related Questions