Comparison

plugins/archive.lua @ 409:171c4a8cc3de

plugins.archive: Update to XEP-0313 v0.6
author Kim Alvefur <zash@zash.se>
date Fri, 07 Apr 2017 19:38:52 +0200
parent 380:0891b4e27766
child 412:ef66f302fe97
comparison
equal deleted inserted replaced
408:635cbd979d7b 409:171c4a8cc3de
2 -- http://xmpp.org/extensions/xep-0313.html 2 -- http://xmpp.org/extensions/xep-0313.html
3 -- (ie not XEP-0136) 3 -- (ie not XEP-0136)
4 4
5 local verse = require "verse"; 5 local verse = require "verse";
6 local st = require "util.stanza"; 6 local st = require "util.stanza";
7 local xmlns_mam = "urn:xmpp:mam:0" 7 local xmlns_mam = "urn:xmpp:mam:2"
8 local xmlns_forward = "urn:xmpp:forward:0"; 8 local xmlns_forward = "urn:xmpp:forward:0";
9 local xmlns_delay = "urn:xmpp:delay"; 9 local xmlns_delay = "urn:xmpp:delay";
10 local uuid = require "util.uuid".generate; 10 local uuid = require "util.uuid".generate;
11 local parse_datetime = require "util.datetime".parse; 11 local parse_datetime = require "util.datetime".parse;
12 local datetime = require "util.datetime".datetime; 12 local datetime = require "util.datetime".datetime;
37 query_st:add_child(rsm.generate(query_params)); 37 query_st:add_child(rsm.generate(query_params));
38 38
39 local results = {}; 39 local results = {};
40 local function handle_archived_message(message) 40 local function handle_archived_message(message)
41 41
42 local finnished = message:get_child("fin", xmlns_mam)
43 if finnished and finnished.attr.queryid == queryid then
44 local rset = rsm.get(finnished);
45 for k,v in pairs(rset or NULL) do results[k]=v; end
46 self:unhook("message", handle_archived_message);
47 callback(results);
48 return true
49 end
50 local result_tag = message:get_child("result", xmlns_mam); 42 local result_tag = message:get_child("result", xmlns_mam);
51 if result_tag and result_tag.attr.queryid == queryid then 43 if result_tag and result_tag.attr.queryid == queryid then
52 local forwarded = result_tag:get_child("forwarded", xmlns_forward); 44 local forwarded = result_tag:get_child("forwarded", xmlns_forward);
53 forwarded = forwarded or message:get_child("forwarded", xmlns_forward); -- COMPAT XEP-0313 pre 2013-05-31 45 forwarded = forwarded or message:get_child("forwarded", xmlns_forward); -- COMPAT XEP-0313 pre 2013-05-31
54 46
63 end 55 end
64 end 56 end
65 57
66 self:hook("message", handle_archived_message, 1); 58 self:hook("message", handle_archived_message, 1);
67 self:send_iq(query_st, function(reply) 59 self:send_iq(query_st, function(reply)
60 self:unhook("message", handle_archived_message);
68 if reply.attr.type == "error" then 61 if reply.attr.type == "error" then
69 self:warn(table.concat({reply:get_error()}, " ")) 62 self:warn(table.concat({reply:get_error()}, " "))
70 self:unhook("message", handle_archived_message);
71 callback(false, reply:get_error()) 63 callback(false, reply:get_error())
64 return true;
72 end 65 end
73 return true 66 local finnished = reply:get_child("fin", xmlns_mam)
67 if finnished and finnished.attr.queryid == queryid then
68 local rset = rsm.get(finnished);
69 for k,v in pairs(rset or NULL) do results[k]=v; end
70 callback(results);
71 return true
72 end
74 end); 73 end);
75 end 74 end
76 75
77 local default_attrs = { 76 local default_attrs = {
78 always = true, [true] = "always", 77 always = true, [true] = "always",