1

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

4

1 回答 1

5

您需要关注 xep - 0136

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

对于 smack,您需要通过以下方式获取它:

  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();
        }
    }
于 2016-12-25T09:38:52.537 回答