Software / code / verse
Comparison
plugins/archive.lua @ 304:e09ae2395d41
squishy, plugins.archive: Fetch RSM lib from prosody-modules and use.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 08 Jun 2012 21:39:01 +0200 |
| parent | 303:0dda04d5eb84 |
| child | 305:4a0206505b9d |
comparison
equal
deleted
inserted
replaced
| 303:0dda04d5eb84 | 304:e09ae2395d41 |
|---|---|
| 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; |
| 13 local rsm = require "util.rsm"; | |
| 13 local tonumber = tonumber; | 14 local tonumber = tonumber; |
| 15 local NULL = {}; | |
| 14 | 16 |
| 15 function verse.plugins.archive(stream) | 17 function verse.plugins.archive(stream) |
| 16 function stream:query_archive(where, query_params, callback) | 18 function stream:query_archive(where, query_params, callback) |
| 17 local queryid = uuid(); | 19 local queryid = uuid(); |
| 18 local query_st = st.iq{ type="get", to = where } | 20 local query_st = st.iq{ type="get", to = where } |
| 27 if qstart then | 29 if qstart then |
| 28 query_st:tag("start"):text(datetime(qstart)):up(); | 30 query_st:tag("start"):text(datetime(qstart)):up(); |
| 29 end | 31 end |
| 30 if qend then | 32 if qend then |
| 31 query_st:tag("end"):text(datetime(qend)):up(); | 33 query_st:tag("end"):text(datetime(qend)):up(); |
| 34 end | |
| 35 query_params["start"], query_params["end"], query_params["with"] = nil, nil, nil; | |
| 36 | |
| 37 if next(query_params) then | |
| 38 query_st:add_child(rsm.generate(query_params)); | |
| 32 end | 39 end |
| 33 | 40 |
| 34 local results = {}; | 41 local results = {}; |
| 35 local function handle_archived_message(message) | 42 local function handle_archived_message(message) |
| 36 local result_tag = message:get_child("result", xmlns_mam); | 43 local result_tag = message:get_child("result", xmlns_mam); |
| 49 end | 56 end |
| 50 | 57 |
| 51 self:hook("message", handle_archived_message, 1); | 58 self:hook("message", handle_archived_message, 1); |
| 52 self:send_iq(query_st, function(reply) | 59 self:send_iq(query_st, function(reply) |
| 53 self:unhook("message", handle_archived_message); | 60 self:unhook("message", handle_archived_message); |
| 61 local rset = reply.tags[1] and rsm.get(reply.tags[1]); | |
| 62 for k,v in pairs(rset or NULL) do results[k]=v; end | |
| 54 callback(reply.attr.type == "result" and #results, results); | 63 callback(reply.attr.type == "result" and #results, results); |
| 55 return true | 64 return true |
| 56 end); | 65 end); |
| 57 end | 66 end |
| 58 | 67 |