Get last message of each conversation with XEP-0313?
Asked Answered
M

1

9

I'm using an XMPP server that implements XEP-0313 for retrieving conversation history. I would like to fetch only the last message of each conversation, so that I can build a list of your most recent conversations previewing the last message.

I've managed to fetch all messages of all conversations and based on that I could build the list, but it's a big waste of data and not an option. I'm not sure this is the right extension for accomplishing this, so if there is another extension I should be looking at, please guide me in the right direction.

Minister answered 1/2, 2016 at 11:53 Comment(4)
I am developing an android chat app with xmpp. I have successfully implemented that and i am able to send and receive messages. I have stored the chat data internally using SQLite on the device but the chat data is deleted once the app is uninstalled. So i checked about the XEP - 0313 which can save the chat beween the users on the server, and i am having issues with retrieving chat history between two users from the eJabberd server. I have read about the XEP - 0313 but i don't know how i can use that in my android app. I am using Android Studio. ThanksLucarne
@Paritosh I don't see how this has anything to do with my question. Seems like you just want my help implementing XEP-0313. I did this for iOS, so I am not sure what libraries are available for Android, but for iOS I couldn't find an implementation of this protocol at the time, so I had to implement it myself. It was a lot of work, but I can't say that it was difficult. It's just normal development work. If you need someone else to do your development work, you should hire someone. I am currently not available, but if you only need help to get started, I suppose I could find the time.Minister
Hi..!! Thanks for replying. I have successfully implemented the XEP - 0313 in Android now. I just wanted to know how we can implement that library in Android as the methods to fetch the history should be similar as we would be using the same library in Android and iOS. I used MamManger at my end to retrieve the history.Lucarne
@ErikB did you find a proper solution? I'm asking the similar here #52085902 but still no god advisesBordereau
K
6

One thing you can do easily is first retrieve the user's roster and then for each contact retrieve the latest message.

<iq from='[email protected]/balcony'
    id='bv1bs71f'
    type='get'>
  <query xmlns='jabber:iq:roster'/>
</iq>

Result:

<iq id='bv1bs71f'
    to='[email protected]/chamber'
    type='result'>
   <query xmlns='jabber:iq:roster' ver='ver7'>
     <item jid='[email protected]'/>
     <item jid='[email protected]'/>
   </query>
 </iq>

Retrieve the last message from or to [email protected]:

<iq type='set' id='juliet1'>
  <query xmlns='urn:xmpp:mam:1'>
    <x xmlns='jabber:x:data' type='submit'>
      <field var='FORM_TYPE' type='hidden'>
        <value>urn:xmpp:mam:1</value>
      </field>
      <field var='with'>
        <value>[email protected]</value>
      </field>
    </x>
    <set xmlns='http://jabber.org/protocol/rsm'>
      <max>1</max>
      <before/>
    </set>
  </query>
</iq>

Of course users can have conversations with people not on their roster, but in practice this is quite rare on XMPP.

Knoll answered 2/2, 2016 at 12:36 Comment(8)
My experience with XMPP is very limited, but from my understanding, the roster is your "contact list". I'm assuming that it wouldn't include group chats, right? Meaning that if you participate in a group chat it would not show up in the conversation history using this technique, which isn't good enough for me. Please correct me if my assumption is wrong.Minister
Correct, your roster is your contact list. It appears to me that most server implementations don't archive group chat messages anyway, but instead assume the group chat servers expose a MAM archive themselves. That means it's easy to obtain the last message, but it will be much harder to discover which group chats the user has been in unless they are all bookmarked.Knoll
It seems to me like I might need a non-standard XMPP-extension to accomplish the task. I find that a bit surprising considering that my use case must be quite common and XMPP is the dominating standard. Someone must have done this before me.Minister
@ErikB There's been some progress lately on writing a new group chat protocol called MIX: xmpp.org/extensions/xep-0369.html. I think your use-case would be much easier with MIX.Knoll
@Knoll If you do this you'll have to make a network call for each member of your roster. If I have 1000 people on my roster and each network call takes 250ms that 25 seconds plus a ton of network use. Is there any way to do this in bulk?Agnosticism
@ZacharySweigart You don't need to wait 250ms for the results before sending the next query, you can send multiple packets at the same time. It's indeed still a lot of traffic, though.Knoll
I had a socket connection working at the same time in NODEJS to fetch the latest chat from DB, I pass in the JIDs to receive the latest chat for each user.Loath
@Knoll even after im passing <max>1</max> not getting only 1 last message its still give all the messages which are delivered in that user , can you pls guild me how to pass <before/> element here ? or your swift code to send this iq on server side to fetch teh messages ?Artistic

© 2022 - 2024 — McMap. All rights reserved.