Software /
code /
verse
Comparison
plugins/archive.lua @ 273:c5b7a4c717a6
plugins.archive: Experimental implementation of the Message Archive Management ProtoXEP
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 06 Jan 2012 16:54:10 +0100 |
child | 275:c077b20ad59f |
comparison
equal
deleted
inserted
replaced
272:e1833e9bd25b | 273:c5b7a4c717a6 |
---|---|
1 local xmlns_mam = "urn:xmpp:mam:tmp" | |
2 local uuid = require "util.uuid".generate; | |
3 | |
4 function verse.plugins.archive(stream) | |
5 function stream:query_archive(where, query_params, callback) | |
6 local queryid = uuid(); | |
7 local query_st = verse.iq{ type="get", to=where } | |
8 :tag("query", { xmlns = xmlns_mam, queryid = queryid }); | |
9 | |
10 local params = { "with", "start", "end" }; | |
11 local query_params = query_params or {}; | |
12 for i=1,#params do | |
13 local k = params[i]; | |
14 if query_params[k] then | |
15 query_st:tag(k):text(query_params[k]); | |
16 end | |
17 end | |
18 | |
19 local results = {}; | |
20 local function handle_archived_message(message) | |
21 local result_tag = message:get_child("result", xmlns_mam); | |
22 if result_tag and result_tag.attr.queryid == queryid then | |
23 local forwarded = message:get_child("forwarded", "urn:xmpp:forward:0"); | |
24 | |
25 local delay = forwarded:get_child("delay", "urn:xmpp:delay"); | |
26 local stamp = delay and delay.attr.stamp or nil; | |
27 | |
28 local message = forwarded:get_child("message", "jabber:client") | |
29 | |
30 results[#results+1] = { stamp = stamp, message = message }; | |
31 return true | |
32 end | |
33 end | |
34 | |
35 self:hook("message", handle_archived_message, 1); | |
36 self:send_iq(query_st, function(reply) | |
37 self:unhook("message", handle_archived_message); | |
38 callback(reply.attr.type == "result" and #results, results); | |
39 return true | |
40 end); | |
41 end | |
42 | |
43 --TODO Settings | |
44 end |