Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How retrieve Chat History using Java Smack library from openfire server?

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.

like image 581
Dhiren Hamal Avatar asked Jun 21 '15 06:06

Dhiren Hamal


3 Answers

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.

like image 50
Md Samiul Alim Sakib Avatar answered Dec 15 '22 23:12

Md Samiul Alim Sakib


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;
    }
like image 33
Santosh Joshi Avatar answered Dec 15 '22 22:12

Santosh Joshi


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?".

like image 31
Dila Gurung Avatar answered Dec 15 '22 23:12

Dila Gurung