Comparison

plugins/archive.lua @ 303:0dda04d5eb84

plugins.archive: Treat query params correctly
author Kim Alvefur <zash@zash.se>
date Fri, 08 Jun 2012 06:44:20 +0200
parent 297:447dffdaf46c
child 304:e09ae2395d41
comparison
equal deleted inserted replaced
302:0c83cb476246 303:0dda04d5eb84
7 local xmlns_mam = "urn:xmpp:mam:tmp" 7 local xmlns_mam = "urn:xmpp:mam:tmp"
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;
13 local tonumber = tonumber;
12 14
13 function verse.plugins.archive(stream) 15 function verse.plugins.archive(stream)
14 function stream:query_archive(where, query_params, callback) 16 function stream:query_archive(where, query_params, callback)
15 local queryid = uuid(); 17 local queryid = uuid();
16 local query_st = st.iq{ type="get", to = where } 18 local query_st = st.iq{ type="get", to = where }
17 :tag("query", { xmlns = xmlns_mam, queryid = queryid }); 19 :tag("query", { xmlns = xmlns_mam, queryid = queryid });
18 20
19 local params = { "with", "start", "end" }; 21 local qwith = query_params["with"];
20 local query_params = query_params or {}; 22 if qwith then
21 for i=1,#params do 23 query_st:tag("with"):text(qwith):up();
22 local k = params[i]; 24 end
23 if query_params[k] then 25
24 query_st:tag(k):text(query_params[k]):up(); 26 local qstart, qend = tonumber(query_params["start"]), tonumber(query_params["end"]);
25 end 27 if qstart then
28 query_st:tag("start"):text(datetime(qstart)):up();
29 end
30 if qend then
31 query_st:tag("end"):text(datetime(qend)):up();
26 end 32 end
27 33
28 local results = {}; 34 local results = {};
29 local function handle_archived_message(message) 35 local function handle_archived_message(message)
30 local result_tag = message:get_child("result", xmlns_mam); 36 local result_tag = message:get_child("result", xmlns_mam);