Mercurial > prosody-modules
comparison mod_archive/mod_archive.lua @ 195:4d9ed6374a1f
mod_archive: XEP-0059: Result Set Management - Limiting the Number of Items; Paging Forwards Through a Result Set; Getting the Item Count
author | shinysky<shinysky1986(AT)gmail.com> |
---|---|
date | Tue, 06 Jul 2010 00:18:12 +0800 |
parents | 18a0e5c0bb62 |
children | a1c2677257da |
comparison
equal
deleted
inserted
replaced
194:58c37562c67d | 195:4d9ed6374a1f |
---|---|
16 module:add_feature("urn:xmpp:archive"); | 16 module:add_feature("urn:xmpp:archive"); |
17 module:add_feature("urn:xmpp:archive:auto"); | 17 module:add_feature("urn:xmpp:archive:auto"); |
18 module:add_feature("urn:xmpp:archive:manage"); | 18 module:add_feature("urn:xmpp:archive:manage"); |
19 module:add_feature("urn:xmpp:archive:manual"); | 19 module:add_feature("urn:xmpp:archive:manual"); |
20 module:add_feature("urn:xmpp:archive:pref"); | 20 module:add_feature("urn:xmpp:archive:pref"); |
21 module:add_feature("http://jabber.org/protocol/rsm"); | |
21 | 22 |
22 ------------------------------------------------------------ | 23 ------------------------------------------------------------ |
23 -- Utils | 24 -- Utils |
24 ------------------------------------------------------------ | 25 ------------------------------------------------------------ |
25 local function load_prefs(node, host) | 26 local function load_prefs(node, host) |
70 local save = st.stanza('save', {xmlns='urn:xmpp:archive'}); | 71 local save = st.stanza('save', {xmlns='urn:xmpp:archive'}); |
71 local chat = st.stanza('chat', collection.attr); | 72 local chat = st.stanza('chat', collection.attr); |
72 save:add_child(chat); | 73 save:add_child(chat); |
73 return save; | 74 return save; |
74 end | 75 end |
76 | |
77 local function gen_uid(c) | |
78 return c.attr["start"] .. c.attr["with"]; | |
79 end | |
75 | 80 |
76 ------------------------------------------------------------ | 81 ------------------------------------------------------------ |
77 -- Preferences | 82 -- Preferences |
78 ------------------------------------------------------------ | 83 ------------------------------------------------------------ |
79 local function preferences_handler(event) | 84 local function preferences_handler(event) |
349 end | 354 end |
350 end | 355 end |
351 end | 356 end |
352 local reply = st.reply(stanza):tag('list', {xmlns='urn:xmpp:archive'}); | 357 local reply = st.reply(stanza):tag('list', {xmlns='urn:xmpp:archive'}); |
353 if table.getn(resset) > 0 then | 358 if table.getn(resset) > 0 then |
354 local max = tonumber(elem.tags[1].tags[1]:get_text()); | 359 local max = elem.tags[1]:child_with_name("max"); |
360 if max then | |
361 max = tonumber(max:get_text()); | |
362 else max = 100; end | |
363 local after = elem.tags[1]:child_with_name("after"); | |
364 -- local before = elem.tags[1]:child_with_name("before"); | |
365 -- local index = elem.tags[1]:child_with_name("index"); | |
366 if after then after = after:get_text(); end | |
367 local found = false; | |
368 local first, last = nil, nil; | |
355 -- Assuming result set is sorted. | 369 -- Assuming result set is sorted. |
356 for i, c in ipairs(resset) do | 370 for i, c in ipairs(resset) do |
357 if i <= max then | 371 if after and not found then |
372 if gen_uid(c) == after then | |
373 found = true; | |
374 end | |
375 elseif max > 0 then | |
376 if not first then first = i; end | |
377 last = i; | |
358 local chat = st.stanza('chat', c.attr); | 378 local chat = st.stanza('chat', c.attr); |
359 reply:add_child(chat); | 379 reply:add_child(chat); |
380 max = max - 1; | |
360 else break; end | 381 else break; end |
361 end | 382 end |
383 local set = st.stanza('set', {xmlns='http://jabber.org/protocol/rsm'}); | |
384 if first then | |
385 set:tag('first', {index=first-1}):text(gen_uid(resset[first])):up() | |
386 :tag('last'):text(gen_uid(resset[last])):up(); | |
387 end | |
388 set:tag('count'):text(tostring(table.getn(resset))):up(); | |
389 reply:add_child(set); | |
362 end | 390 end |
363 origin.send(reply); | 391 origin.send(reply); |
364 return true; | 392 return true; |
365 end | 393 end |
366 | 394 |