1
votes

I have successfully implemented one on one chat in my Android application. I have used SQLite to save the chat between two users as in app database. But this chat is removed when the user uninstalls the application. What i need to know is how i can save the chat between two users on my server so whenever the user reinstalls the app or logs in any other device he can see his previous chat. I have enable mod_archive and mod_mam on my ejabberd server and i am able to retrieve offline messages in the app. Thanks

1
even i am also stuck in ios at same point :(PHP Ninja
@Paritosh I am also having same issue in iOS Please let me know if you got the answer for it.Mahesh Narla
@MaheshNarla I am still stuck in this, once i have a perfect solution for this i will definitely let you know.Paritosh Chaudhary

1 Answers

5
votes

You need to follow xep - 0136

http://xmpp.org/extensions/xep-0136.html

For smack you need to get it in following way :

  public void loadArchiveMessages(Jid jid, XMPPTCPConnection xmppTcpConnection){
        try {
            MamManager mamManager=MamManager.getInstanceFor(xmppTcpConnection);
            MamManager.MamQueryResult mamQueryResult = mamManager.queryArchive(jid);
            List<Forwarded> forwardedMessages=mamQueryResult.forwardedMessages;
            Iterator<Forwarded> forwardedIterator=forwardedMessages.iterator();
            while (forwardedIterator.hasNext()){
                Forwarded forwarded=forwardedIterator.next();
                Stanza stanza=forwarded.getForwardedStanza();
                if (stanza instanceof Message) {
                    String messageId=stanza.getStanzaId();
                    xmppTcpConnection.processMessage((Message) stanza);
                }
            }
        } catch (XMPPException.XMPPErrorException e) {
            e.printStackTrace();
        } catch (SmackException.NotLoggedInException e) {
            e.printStackTrace();
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (SmackException.NoResponseException e) {
            e.printStackTrace();
        }
    }