How retrieve Chat History using Java Smack library

2019-02-03 16:45发布

After installing Open Archive plugin in the Openfire server I can see the chat conversation between two user from the openfire admin panel which is pretty easy and that is web based too. Now I want to retrive those conversation or chat history from chat client application(written in java) where I've used Smack library. I didn't found any helpfull resource for that. Any advice will be helpfull.

4条回答
你好瞎i
2楼-- · 2019-02-03 17:18

Finally I got the answer. Archive Messaging features are currently not implemented in Smack library.

https://community.igniterealtime.org/message/249993#249993

查看更多
SAY GOODBYE
3楼-- · 2019-02-03 17:31

It might be a late answer but now as SMACK API supports XEP-0136 and XEP-0313, so below code can help people landing to this page.

public MamManager.MamQueryResult getArchivedMessages(String jid, int maxResults) {

        MamManager mamManager = MamManager.getInstanceFor(connection);
        try {
            DataForm form = new DataForm(DataForm.Type.submit);
            FormField field = new FormField(FormField.FORM_TYPE);
            field.setType(FormField.Type.hidden);
            field.addValue(MamElements.NAMESPACE);
            form.addField(field);

            FormField formField = new FormField("with");
            formField.addValue(jid);
            form.addField(formField);

            // "" empty string for before
            RSMSet rsmSet = new RSMSet(maxResults, "", RSMSet.PageDirection.before);
            MamManager.MamQueryResult mamQueryResult = mamManager.page(form, rsmSet);

            return mamQueryResult;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
查看更多
We Are One
4楼-- · 2019-02-03 17:35

The solution you're looking for come under XMPP specification's XEP-0136 Message archiving but Smack has not implemented this features yet. but you can retrieve the message history from server using "custom-stanza" features provided by SMACK API. The following links describe how to send the custom stanza. "How retrieve Chat History using Java Smack library from openfire server?".

查看更多
对你真心纯属浪费
5楼-- · 2019-02-03 17:36

Smack just implemented MAM feature [XEP 0313] but yet not released, hope to get it on next release if you want to use this feature build the smack library from source or you can use custom IQ to get archived messages from server.

查看更多
登录 后发表回答