I am interested in the procedure behind the handling of inbound messages and notifications from instant messaging apps such as Telegram and WhatsApp. I am acquainted with the push protocol, but I am curious about how instant messaging apps implement the receiving part.
First, are instant messages from services like WhatsApp and Telegram received in the form of a push notification, or is there duplication/redundancy giving rise to some sort of a race condition between push notifications proper handed to an app instance service worker, and messages handed to an app instance foreground/main processes? Alternatively, are instant messages always and only sent as push notifications, as least for end-to-end encrypted messages from apps like Whatsapp?
Secondly, under the duplication/redundancy hypothesis mentioned above, is the notification handled by the service worker passed over to the app instance, which then displays it in the target chat, or is the notification discarded in favour of the app instance's fetching the original message from Telegram/Whatsapp server? (I have in mind a scenario where this is required to ensure that the sender is provided a reliable confirmation that the message has been received.)
Actually it's a tricky question cause apps like Telegram and WhatsApp probably have some multiple cases handling logic, very complex logic.
But from what I can imagine and actually used in some of my chat apps is the following:
So there is no any duplications since pushes are just to notify a user there is a new message while a user is not in app.