Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMPP query archive by latest messages

Tags:

xmpp

ejabberd

I'm reading http://xmpp.org/extensions/xep-0313.html to query Ejabberd for messages archived with a certain user.

This is the xml that I'm sending:

<iq type='get' id='get_archive_user1'>
 <query xmlns='urn:xmpp:mam:tmp'>
  <with>user1@localhost</with>
  <set xmlns='http://jabber.org/protocol/rsm'>
   <max>20</max>
  </set>
 </query>
</iq>

I'm receiving the first 20 messages correctly. To request again I'm adding the tag:

<after>(id in element "Last" from last request)</after>

and this also work fine. What I need is to receive the last 20 messages, not the first 20 messages. How can I achieve this?

like image 463
nhenrique Avatar asked Aug 05 '15 09:08

nhenrique


2 Answers

XEP-0313 Message Archive Management rely on XEP-0059 Result Set Management for pagination.

RSM specification explains how to get the last page in a Result Set:

The requesting entity MAY ask for the last page in a result set by including in its request an empty <before/> element, and the maximum number of items to return.

It means you need to add an empty <before/> element in your result set query.

Here is an example based on XEP-0313 version 0.4 on how to get the last 20 messages in a conversation with a given user. The query limit is defined by the parameter max (it defined the size of the pages).

<iq type='set' id='q29302'>
  <query xmlns='urn:xmpp:mam:0'>
    <x xmlns='jabber:x:data' type='submit'>
      <field var='FORM_TYPE' type='hidden'>
        <value>urn:xmpp:mam:0</value>
      </field>
      <field var='with'>
        <value>[email protected]</value>
      </field>
    </x>
    <set xmlns='http://jabber.org/protocol/rsm'>
     <max>20</max>
     <before/>
    </set>
  </query>
</iq>
like image 95
Mickaël Rémond Avatar answered Oct 06 '22 02:10

Mickaël Rémond


You should add an empty <before/> element:

<iq type='get' id='get_archive_user1'>
    <query xmlns='urn:xmpp:mam:tmp'>
        <with>user1@localhost</with>
        <set xmlns='http://jabber.org/protocol/rsm'>
            <max>20</max>
            <before/>
        </set>
    </query>
</iq>

See here.

like image 20
xnyhps Avatar answered Oct 06 '22 01:10

xnyhps