Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last message of each conversation with XEP-0313?

Tags:

xmpp

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.

like image 367
Erik B Avatar asked Feb 01 '16 11:02

Erik B


1 Answers

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.

like image 153
xnyhps Avatar answered Sep 24 '22 07:09

xnyhps