7

I am using aSmack and Openfire for my chat application. I am able send and receive message finely. Openfire support offline message transfer when recipient is offline by keeping message until he comes online.

But what to do when sender is offline or his internet drops between communication?

Is there any api provided by aSmack/Smack which keeps message until internet is back ?

Or should i send my messages through SQLite ?

Sushant
  • 1,272
  • 2
  • 15
  • 31
  • Hello @Sushant, I'm facing to the same issue, any help – AITAALI_ABDERRAHMANE Jul 04 '15 at 20:35
  • 1
    @AT_AB i end up using shared preferences and sqlite. Store recipient name in shared preferences before sending message to him, then get all unsent messages from sqlite and send them to that recipient and after successful sent remove recipient from shared preferences. – Sushant Jul 05 '15 at 05:01

2 Answers2

2

If you are connected to openfire and internet goes off then you are still online on openfire because you can't change presence if internet is off.

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

If user app doesn't reply ping request then openfire makes it offline and offline storage starts.

For getting offline messages in asmack you need to add following providers.After adding these you will get 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 hereions/xep-0199.html

Jaspreet Chhabra
  • 1,431
  • 15
  • 23
  • Thanks for your answer. But i am not asking for openfire offline storage. I am asking about aSmack offline storage. Is there any api for it ? – Sushant Mar 31 '15 at 08:08
  • Edited the answer add offline provider – Jaspreet Chhabra Mar 31 '15 at 08:50
  • Yes. I know we can get offline messages when reconnected to server. But if i am offline while sending the message, the message will get lost. What i want is keep the message until i reconnect to network and send when network is back. – Sushant Mar 31 '15 at 12:49
2

Well answering after a while, but perhaps still it would point someone in right direction.

After searching for a while, i get to know that aSmack doesn't provide any offline storage.

To send message when sender is offline, we need offline storage to store message until sender gets back online. I used sqlite for this, but SharedPreferences would also be a good option if we have to delete message after successfull sending.

Best solution, which i follow is, insert message in sqlite, store it's id in shared preferences, send message and then remove id from shared preferences. In mean while if intenet connection drops or message couldn't send by any reason, then we have it's id in shared preferences as backup. After getting online, we can go through shared preferences to check if their is any message is pending to send.

Sushant
  • 1,272
  • 2
  • 15
  • 31
  • I think you are talking about sender side only, what if receiver is offline and when receiver gets online does he/she receives messages during his/her offline period? – Ahesanali Suthar Jul 25 '16 at 06:59
  • 1
    @Ahesanali Momin XMPP server hadles this case. It stores messages if recevier is offline and delivers them when receiver connects to server. – Sushant Jul 26 '16 at 03:36
  • Thank you very much, You are right. XMPP server doing it if we enable this offline message plugin. – Ahesanali Suthar Jul 26 '16 at 06:31
  • Hi @AhesanaliMomin : Can you please provide me the plugin name in which if user is offline under GROUP and connected to the internet he/she will get message instantly? – Hardik Mamtora Feb 22 '17 at 10:03
  • In openfire it listed as save offline message. Something like that. – Ahesanali Suthar Feb 22 '17 at 10:10
  • If you are doing p2p messages at that time offline messages are stored into ofOffline table but when you are talking about group chat all the messages are stored into ofMessageArchive table itself with few seconds delay. @AhesanaliMomin is there any way that monitoring service plugin inserts data in faster manner? moreover can you please look into http://stackoverflow.com/questions/37346341/xmpp-openfire-messages-inserting-late-in-database – Shashank Shah Feb 22 '17 at 10:35
  • is there any way we can check if the message is send or not as newOutgoingMessage(to: EntityBareJid?, message: Message?, chat: Chat?) is always called whenever i send the message and no SmackException.NotConnectedException is thrown – Shubham AgaRwal Jan 31 '18 at 08:51
  • @Killer: I couldn't found any callback method which notifies us after successful send. So we got to check everything before we call send method and then mark that message as "sent" in `sqlite`. – Sushant Feb 04 '18 at 07:50