powered by Jive Software

How to retrieve archived chat messages from openfire using smack api?

Hi,

I am new to smack and openfire. I am trying to fetch chat messages of users using the smack api. I knew that this support has been implemented in Smack 4.2.0 but i am not able to find appropriate api for that. Can anybody please help me with that.

Thanks,

The Smack API you are looking for is called MAM : XEP-0313: Message Archive Management. Of course you need a server which has support for this, like the latest version (4.1.3) of OpenFire. Look for the MamManager (Smack 4.2.0 API)

Hi @Anno van Vliet,

I am aware about the api and used the following code:-

MamManager mamManager = MamManager.getInstanceFor(connection);

boolean isSupported = mamManager.isSupportedByServer(); // it's true

MamQueryResult mamQueryResult = mamManager.queryArchive(10);

`List forwardedMessages = mamQueryResult.forwardedMessages; // I am getting this as a empty list.

// Get fin IQ
MamFinIQ mamFinIQ = mamQueryResult.mamFinIQ; `

Now i am not sure how to proceed ahead to fetch the chat messages. Can you please suggest .

Thanks,

Do like that

var mamManager:MamManager= MamManager.getInstanceFor(connection)

var prevMsg:List = mamManager.queryArchive(JidCreate.entityBareFrom(jid)).forwardedMessages

for (msg in prevMsg){

var prevChat:Message = msg.forwardedStanza as? Message

println("Chat is "+prevChat.body)

var delayInformation:DelayInformation =msg.delayInformation //this is msg sent timestamp

println("\n")

}