javaandroidopenfiresmack

one to one chat history with open fire and smack


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


Solution

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