How to send an XMPP message when the sender is disconnected?

I use aSmack and Openfire for my chat application. I can send and receive messages finely. Openfire supports offline messaging when the recipient is offline, storing the message until it goes online.

But what to do when the sender is disconnected or his Internet falls between messages?

Is there an api provided by aSmack / Smack that saves the message until the Internet returns?

Or do I need to send messages through SQLite?

+6
source share
2 answers

Answering well after a while, but maybe he will point someone in the right direction.

After some time searching, I find out that aSmack does not provide any offline storage.

To send a message when the sender is offline, we need offline storage to store the message until the sender returns to the network. I used sqlite for this, but SharedPreferences would also be a good option if we need to delete the message after sending it successfully.

The best solution that I follow is to insert a message in sqlite , save its id in shared preferences , send a message, and then remove the id from shared preferences . While if the intenet connection drops or the message cannot be sent for any reason, then we will use its id in the general settings as a backup. After accessing the Internet, we can go through shared preferences to check if any message has been sent.

+2
source

If you are connected to openfire and the Internet is disconnected, you are still online on openfire because you cannot change your presence if the Internet is disconnected.

For this openfire use http://xmpp.org/extensions/xep-0199.html

If the user application does not respond to the ping request, openfire launches it offline and offline storage.

To receive offline messages in asmack you need to add the following providers. After adding them, you will receive offline messages if they are enabled from the server

 pm.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider()); // Offline Message Indicator pm.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider()); 

enter image description here Ions / xep-0199.html

+2
source

Source: https://habr.com/ru/post/984373/


All Articles