XMPP query archive by latest messages

后端 未结 3 731
醉酒成梦
醉酒成梦 2021-01-13 01:13

I\'m reading http://xmpp.org/extensions/xep-0313.html to query Ejabberd for messages archived with a certain user.

This is the xml that I\'m sending:



        
3条回答
  •  感情败类
    2021-01-13 01:28

    People who would like to use Smack to fetch this can use below code

     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;
        }
    

提交回复
热议问题