How do I get archived Messages for a group chat

Currently, MamManager does not work for me and always return false when i try to

mamManger.isSupported()

so, i created a custom IQ and sending that iq with start and end date like

<iq to='muclight15271617393@muclight.localhost' id='VZNyS-38' type='get'><query xmlns='urn:xmpp:mam:tmp'><start>2018-03-01T00:00:00Z</start><end>2018-05-28T00:00:00Z</end></query></iq>

and it return response with count, but how i can get the messages, as i can see those messages in the smack debug, when it is set to enabled true.
How do i listen for group messages that are archived ?

This probably means that your server doesn’t support MAM. This is something you cannot fix client side.

Although you ca not conclude that this also means that the MUC service does not support MAM.

I understand that, so, what i am doing is,i am sending a custom IQ with start and end date and it returns me all the archived messages, and i dont know how do parse that sort of structure.
the message packet that i get as a result from the above IQ is : - >

<message to='917777777777@localhost/android' from='muclight15272437681@muclight.localhost'>
    <result xmlns='urn:xmpp:mam:tmp' xmlns:stream='http://etherx.jabber.org/streams' id='AR85EC8A9OG1'>
       <forwarded xmlns='urn:xmpp:forward:0' xmlns:stream='http://etherx.jabber.org/streams'>
          <delay xmlns='urn:xmpp:delay' xmlns:stream='http://etherx.jabber.org/streams' from='muclight15272437681@muclight.localhost/915555555555@localhost' stamp='2018-05-25T10:44:16Z'>
          </delay>
          <message xmlns:stream='http://etherx.jabber.org/streams' from='muclight15272437681@muclight.localhost/915555555555@localhost' to='' id='ZJCf7-88' type='groupchat'>
             <body xmlns:stream='http://etherx.jabber.org/streams'>hloo</body>
             <active xmlns='http://jabber.org/protocol/chatstates' xmlns:stream='http://etherx.jabber.org/streams'></active>
             <request xmlns='urn:xmpp:receipts' xmlns:stream='http://etherx.jabber.org/streams'></request>
           </message>
       </forwarded>
     </result>
</message>

I tried PacketParserUtils.parseMessage() but didn’t worked for me

@Flow @Paul_Schaub

You could still try what happens, if you use the MamManager.
Maybe it just works in your case.
You could also take a look at queryArchive(MamQueryIQ) to see, how the MamManager handles returning results.

I get an error saying error and cancel, the only way that seems possible in that case, is using custom iq, and the problem is if we enable the mam manager it will archive every message in the database and it will make it hard to persist that amount of data, so we need to parse that sort of message packet.

Smack is currently lacking an API to query different MamArchives besides the current user’s archive. So it is not yet perfect for the non-self-user case, but I expect that to change in future release.

I’ll possible roll something up soon.

any way i can get the messages using?

MamManager.MamQueryResult mamQueryResult = mamManager.queryArchive(jid);

I’ve to correct myself here. Smack has already an API to query different MAM archives. Just use MamManager's getInstanceFor(XMPPConnection connection, Jid archiveAddress) method, and use the MUC address as archive address.

And no, queryArchive(Jid) does not what you want (as explained in the javadoc).

I am also looking for solution for this issue. Currently, i am not getting messages of room.

I solved using latest library version 4.4.0.beta01.

Please don’t bump too many old threads and also please share how exactly you solved your issue.

private fun initGroupChatRoom(){
        val mucEnterConfiguration = multiUserChat?.getEnterConfigurationBuilder(nickname)!!
            .requestNoHistory()
            .build()

        try {
            if (!multiUserChat!!.isJoined) {
                multiUserChat?.join(mucEnterConfiguration)
            }
        }catch (e: Exception){
            Log.e("GrpChatAct","Join Error: "+e.toString())
        }
    }

private fun getChatHistory(){
        chat_last_history_progress_bar.show()
        CoroutineScope(Dispatchers.IO).launch {
            var mamManager = MamManager.getInstanceFor(multiUserChat)
            var mamArgs = MamManager.MamQueryArgs.builder().queryLastPage()
                .setResultPageSize(70)
                .build()

            var result =  async { mamManager.queryArchive(mamArgs) }.await()
            isCompleted = result.isComplete
            Log.e("GroupChatAct","Size: "+result.messageCount)
            withContext(Dispatchers.Main){
                chatList.clear()
                mMsgAdapter?.notifyDataSetChanged()
            }
            parseMessageList(result.page.forwarded.asReversed())
            withContext(Dispatchers.Main){
                chat_last_history_progress_bar.hide()
                mMsgAdapter?.notifyDataSetChanged()
                mMsgAdapter?.setLoaded()
            }
        }
    }

Here Is the code using version 4.4.0.beta01.

1 Like