powered by Jive Software

Unable to retrieve archived messages

I have been trying to get the archived messages from MAM and using the inbuilt functions of smack api,

 try {
            if (lastMessageMamId == null) {
                mamQueryResult = getArchivedMessages(mamManager,chat.getUser().getJid().toString(), PAGE_SIZE);
                //  mamQueryResult = mamManager.queryArchive(50);
            } else {
                mamQueryResult = mamManager.pageAfter(chat.getUser().getJid(), lastMessageMamId, PAGE_SIZE);

and it always returns count 0 as result for forwarded messages for initializing the mamManager using

org.jivesoftware.smackx.mam.MamManager mamManager
                = org.jivesoftware.smackx.mam.MamManager.getInstanceFor(connection);

i also created a method to obtain the archived messages by creating the custom packet with start and end , i think it is also created internally by some another method that accepts the start and end date (queryArchive(…))

 public org.jivesoftware.smackx.mam.MamManager.MamQueryResult getArchivedMessages(org.jivesoftware.smackx.mam.MamManager mamManager, String jid, int maxResults) {

        //MamManager mamManager = MamManager.getInstanceFor(connection);
        try {
            DataForm form = new DataForm(DataForm.Type.submit);
            FormField field = new FormField(FormField.FORM_TYPE);

            //FormField formField = new FormField("with");

            Calendar calendar = Calendar.getInstance();

            FormField formField = new FormField("start");

            FormField formField2 = new FormField("end");

            RSMSet rsmSet = new RSMSet(maxResults);

            return mamManager.page(form,rsmSet);

        } catch (Exception e) {
        return null;

but it also return the same count 0, but i have seen the archive table on server, it has messages in it, but i am not sure what is the thing that i am missing
i have also tried querying the mam using

mamQueryResult = mamManager.queryArchive(50);

but same problem

<iq id="H6q9q-60" type="set">
    <query xmlns="urn:xmpp:mam:1" queryid="825e94c6-bd82-421e-b362-90072b421606">
        <x xmlns="jabber:x:data" type="submit">
            <field var="FORM_TYPE" type="hidden">
            <field var="start">
            <field var="end">
        <set xmlns="http://jabber.org/protocol/rsm">

this is the IQ packet that gets generated and the server guy tells me that, this will not work as it does not have to, and from in IQ.

and i seriously dont think that is the problem, i just want my messages, all of my messages, weather they are one to one, or group messages, for this case i am interested in getting in the group messages only, as i my use case does not have one-to-one chat. What am i missing or doing wrong in it?

This statement is not correct. Stanzas send by the client in XMPP client to server connections are not required to have either the ‘to’ or ‘from’ attribute to be set. Servers are required to stamp the ‘from’ attribute as per RFC 6120 § and a missing ‘to’ must be processed on behalf of the account: See RFC §, § 10.3.3 and the conforming example 2 in XEP-0313.

Assuming “group messages” here means MUC rooms, then you probably have to query the MUC room anyway and not the user’s archive. Some (most?) MAM implemenations do not archive groupchat messages in the user archive.

how do i query MUC archive? ow are these different from user archive? as both messages gets stored in same archive table, is there a different database table for the same? if so does smack have some api for the same?

and while making the instance of MAM Manager, should i go with the constructor which has the archiveAddress as second positional argument

 getInstanceFor(XMPPConnection connection, Jid archiveAddress) 

if so then, should i pass in the group jid , in archiveAddress? or something else?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.