How QuickBlox (XMPP-based) presence and unread messages alerts mechanism works

Posted on by Nate Macleitch

This is to explain how QuickBlox chat presence and chat message alerts for offline users work as we’ve been receiving quite a few questions on the mechanism of this lately:

1. User logs in and establishes chat session, sends presence with ‘available’ flag
2. Every 30 seconds chat client sends a ‘keep-alive’ presence to the server. This way both server and other users know the person is still online. In chat this can be displayed as a green dot against user pic / name.
3(a) If user logs out manually, chat client sends presence = unavailable flag.
3(b) if app is put into background, QuickBlox recommends doing the same (presence = unavailable, session log out) but you can choose. On iOS system may kill your app. On Android you could keep it alive as much as you want in background but it will consume more battery power this way.
3(c) if app crashes, server will determine that socket connection is closed and soon will set the status to unavailable automatically.
4. While user keeps the chat session alive and status is ‘available’ they won’t receive any alerts about missed messages. Once user is unavailable, server will be sending all the missed messages via push notifications. To ALL devices belonging to the user.
5. Push notification is the default channel. You may also customise template for the alert via admin panel. This includes choosing whether to quote message excerpt, you may also use wildcard variables such as username etc, or you may want to send just a number of new messages such as “you have 5 unread messages from X”. Badge counter and sound alerts can also be adjusted.
6. If needed be, instead or along with push notification alert, QuickBlox chat server can also send alerts via e-mails or dump to external message base / middle man system such as Apache Kafka, Cassandra DB etc. Additionally, QuickBlox dumps all messages by default into own MongoDB (NoSQL) DB where messages also get accessible via REST JSON API for chat history purposes.