Is it possible to retrieve the chat between the two user?
I am giving my code please if anyone could help?
The below code is not working for me.
version used :
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<smack.version>4.4.6</smack.version>
<maven.compiler.target>17</maven.compiler.target>
code :
package com.cisco.jabber.controller;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.chat2.Chat;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.mam.MamManager;
import org.jivesoftware.smackx.mam.*;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
import java.util.ArrayList;
import java.util.List;
public class ChatRetrieve {
public static List<Message> retrieveChatMessages(AbstractXMPPConnection connection, EntityBareJid userJid) throws Exception {
List<Message> messageList = new ArrayList<>();
MamManager mamManager = MamManager.getInstanceFor(connection);
MamManager.MamQueryArgs mamQueryArgs = MamManager.MamQueryArgs.builder()
.setResultPageSize(50)
.setQueryBeforeLatestMessage(false
.setAlwaysReturnFin(true)
.build();
MamQueryResult mamQueryResult = mamManager.queryArchive(mamQueryArgs);
messageList.addAll(mamQueryResult.getMessages());
ChatManager chatManager = ChatManager.getInstanceFor(connection);
Chat chat = chatManager.chatWith(userJid);
chat.addMessageListener((chat1, message) -> messageList.add(message));
return messageList;
}
}