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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With