1

I am using the Smack 4.3.4 android library. I am facing issues while fetching the chat history of a particular group using the below code. But its return 0 However, There are many messages which I can see using another client web.

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())
       }

       multiUserChat?.addMessageListener(incomingMessageListener)
   }

private fun chatHistory(){
       CoroutineScope(Dispatchers.IO).launch {
           var mamManager = MamManager.getInstanceFor(multiUserChat)

           var result =  async {
               mamManager.enableMamForAllMessages()
               mamManager.queryMostRecentPage(jId, 70)
           }.await()
        Log.e("GrpChatAct","Total Messages: "+result.messageCount)
     }
}

I also tried with below changes in MamManager:

var mamManager = MamManager.getInstanceFor(mConnection)

Where mConnection is smack connection object.

But still, I am getting 0 messages in the result.

I followed code from this reference.

Is there anything I miss in the code or mistakes I made?

Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
  • Are you absolutely sure that a MAM archive is being maintained. On Openfire, you need to have installed the Monitoring plugin for that. Also, the Monitoring plugin must be configured to store messages (which it does not do by default). – Guus Sep 23 '20 at 11:25
  • I also tried same and not getting past messages. It is working fine for one to one chat – Mihir Patel Oct 20 '20 at 10:54
  • @MihirPatel I solved it with the latest version. – Sagar Maiyad Nov 07 '20 at 11:15

1 Answers1

0

fetching the chat history of a particular group using the below code

val multiUserChatManager = MultiUserChatManager.getInstanceFor(XmppChatConnection.instance?.connection)

 val multiUserChat = multiUserChatManager?.getMultiUserChat(mucJid)
                    val mamManager = MamManager.getInstanceFor(multiUserChat)
                    val mamQueryArgs = MamManager.MamQueryArgs.builder()
                            .limitResultsSince(endDate)
                            .setResultPageSize(1000000000)
                            .queryLastPage()
                            .build()
                    val mamQuery = mamManager.queryArchive(mamQueryArgs)
                    val messageList = mamQuery.messages