3

I have installed open fire in my system and by using postman tool i am able to create the user and by using smack i can able to send the message to other user also.. but the problem is that i dont know that how to fetch the chat history between two users..it means if i sent the from and to user names i need to fetch the previous chat history. I am able to see the chat history in the open fire servers--> archieving folder.. But i am not getting that how to fetch the chat history. Is there any Rest API's are available to fetch the chat history between two users..

Please provide any possible solution

Thank You

This is the chat history that I can see

enter image description here

sunikumar
  • 45
  • 9
  • If you are using `MAM` then you can get the history from `MamManager`.See [This](https://stackoverflow.com/questions/30961720/how-retrieve-chat-history-using-java-smack-library-from-openfire-server) and similar questions . – ADM Jul 04 '18 at 09:37
  • Thanks for your response .but i am not using mammanager in my implementation class – sunikumar Jul 04 '18 at 11:05
  • `mammanager` is Part of Smack 4.2 i guess . And `MAM` plugin is available for openfire . If you go to plugin in Open Fire console you will see it as Message Archive . Read https://xmpp.org/extensions/xep-0313.html. – ADM Jul 04 '18 at 11:08

1 Answers1

3

If you want use get chat history from Openfire with smack:

  1. As you have already done, enable MAM (XEP-0313) by installing the MonitoringService plugin in Openfire.

  2. Now from the Openfire server go to: Server>Archiving>Archiving Settings and check "Archive one-to-one chats" and "Archive group chats" and save click "update setting".

  3. From now on any chats will be saved on Openfire. Start a new chat with someone and reinstall your android app.

  4. MAM is a part of "smack-experimental". So you must add this line to your Gradle:

    implementation 'org.igniterealtime.smack:smack-extensions:4.2.2'
    
  5. After a successful connection and authorization for one of them, you can get chat history page by page or as you need with this code:

    MamManager manager = MamManager.getInstanceFor(connection);
    MamManager.MamQueryResult r = manager.mostRecentPage([userBareJID], [numberOfMessages]);
    if (r.forwardedMessages.size() >= 1) //printing first of them
    {
        Message message = (Message) r.forwardedMessages.get(0).getForwardedStanza();
        Log.i("mam", "message received" + message.getBody());
    }
    
Mahdi Moqadasi
  • 2,029
  • 4
  • 26
  • 52
  • Will you please give me some suggestions for this issue also::https://stackoverflow.com/questions/51682932/cant-able-to-upload-file-through-spark2-7-7-client-to-open-fire?noredirect=1#comment90328695_51682932 – sunikumar Aug 04 '18 at 06:23
  • i have already voted for your valuable response but due to less reputations i earned it is not considering my vote – sunikumar Aug 04 '18 at 08:36
  • 1
    You need to add below gradle dependency for using MamManager class "implementation "org.igniterealtime.smack:smack-experimental:4.2.2" – Mihir Patel Sep 29 '20 at 09:59