Hello Guys,
I am looking to extend this example app and add Notifications so that if a user has the app in the background, he gets a notification for a new message.
This is what I am thinking and would love to get your opinion on this, to see if there is a better way.
1. For Each chat session, we make a unique Id and users in the chat session subscribe to a topic of the form : /topic/chat/<uniqueId>
2. When a user sends a message, it gets added to the Firebase realtime database.
3. On the server, we listen for messages to the Firebase realtime database and use Firebase Cloud Messaging to send topic message. The message is created with both a 'data' and 'notification' payload. If the app is in the foreground, we essentially want to give control to the app, and in that case, we want it to be a no-op as the Firebase realtime database would have taken care of this. If the app is not in the foreground, we want Firebase to show a display notification.
Is there a better way to achieve this ? Your feedback is highly appreciated.
Thanks,
Maaz