0

I am developing a chat application like Facebook. In home page I am listing all the chats, When opening a chat I am calling a REST API for getting new messages. Only after opening a chat I am calling the rest API for listing new messages. From the home page, there is no way to get new message details.

Also, I implemented the push notification in my app using FCM. The push notification will receive when a new message comes.

Form this implementation how can I show the number of unread messages in a chat? Please suggest a suitable solution to show the unread message count?

Is this feature possible to implement using push notification? But push notification's OnMessageReceived() is executed only when the app is in a foreground state. When the app is in the background or killed state OnMessageReceived() will not execute. Also notifications are not received when the app is in log out state.

Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105

1 Answers1

1

Your chat app should be realtime, you can't approach that using REST API to keep it updated since it's only one way, you can use web socket for example (like socket.io) and then you'll have a duplex communication between the server and the client allowing you to keep it updated. Now coming to your question, you can increment the count of unread messages in each chat from the home screen, because you'll be able to receive messages (events) while in the home screen

mahmoudafer
  • 1,139
  • 3
  • 14
  • 30
  • But push notification's `OnMessageReceived()` is executed only when the app is in a foreground state. When the app is in the background or killed state `OnMessageReceived()` will not execute. Also notifications are not received when the app is in log out state. – Sreejith Sree May 16 '19 at 12:12
  • That wasn't your question.. see the documentation for registering for notifications: https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push#register-your-app-for-push-notifications – mahmoudafer May 16 '19 at 12:21