Quantcast
Channel: Ignite Realtime : Discussion List - Openfire Dev
Viewing all articles
Browse latest Browse all 957

Retrieving the last 10 messages from the last conversation archive

$
0
0

Hi,

 

I'm working on a web based Jabber client and would like to use OpenFire's conversation archive to load the last 10 messages of the last conversation for example when the user logs in or reloads the page etc.

 

I can successfully use <list> and <before> to get the last conversation but <before> doesn't seem to work with <retreive> to get the last 10 messages in the conversation. See: http://xmpp.org/extensions/xep-0059.html#last. Here are my XMPP messages:

 

Request the last conversation:

 

<iq type='get' id='...' xmlns='jabber:client'><list xmlns='urn:xmpp:archive' with='...'><set xmlns='http://jabber.org/protocol/rsm'><max>1</max><before/></set></list></iq>

 

Receive the last conversation:

<iq to="..." id="..." type="result"><list xmlns="urn:xmpp:archive"><chat with="..." start="2014-05-27T13:29:17.358Z"></chat><set xmlns="http://jabber.org/protocol/rsm"><first index="2">4</first><last>4</last><count>3</count></set></list></iq>

 

Request the last 10 messages:

 

<iq type='get' id='...' xmlns='jabber:client'><retrieve xmlns='urn:xmpp:archive' with='...' start='2014-05-27T13:29:17.358Z'><set xmlns='http://jabber.org/protocol/rsm'><max>10</max><before/></set></retrieve></iq>

 

Receive no messages:

 

<iq to="..." id="..." type="result"><chat xmlns="urn:xmpp:archive" with="." start="2014-05-27T13:29:17.358Z"></chat></iq>

 

If I drop the <before> then I get the first 10 messages:

 

<iq to="..." id="..." type="result"><chat xmlns="urn:xmpp:archive" with="..." start="2014-05-27T13:29:17.358Z"><to secs="0"><body>a</body></to><to secs="0"><body>b</body></to><to secs="1"><body>c</body></to><to secs="2"><body>d</body></to><to secs="2"><body>e</body></to><to secs="3"><body>f</body></to><to secs="3"><body>g</body></to><to secs="3"><body>h</body></to><to secs="3"><body>i</body></to><to secs="4"><body>j</body></to><set xmlns="http://jabber.org/protocol/rsm"><first index="0">0</first><last>9</last><count>26</count></set></chat></iq>

 

Looking at the code I think the problem is here: https://github.com/igniterealtime/Openfire/blob/v3.9.3/src/plugins/monitoring/sr c/java/com/reucon/openfire/plugin/archive/xep0136/IQRetrieveHandler.java#L60

 

Shouldn't it be something along the lines of:

toIndex = max - resultSet.getBefore().intValue();

fromIndex = toIndex - max;

 

Also there might need to be special handling as an empty <before> element gets mapped to the long 9223372036854775807L:

https://github.com/igniterealtime/Openfire/blob/v3.9.3/src/plugins/monitoring/sr c/java/com/reucon/openfire/plugin/archive/xep0059/XmppResultSet.java#L51

 

Prehaps I'm misinterperating how before is supposed to work.

 

Thanks in advance for any help,

From Richard.



Viewing all articles
Browse latest Browse all 957

Latest Images

Trending Articles



Latest Images