# HG changeset patch # User Kim Alvefur # Date 1325865250 -3600 # Node ID c5b7a4c717a64098e5f4b430449e507cd6d37dda # Parent e1833e9bd25b1f7e0935380ecb4a2a9a5906d489 plugins.archive: Experimental implementation of the Message Archive Management ProtoXEP diff -r e1833e9bd25b -r c5b7a4c717a6 plugins/archive.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/archive.lua Fri Jan 06 16:54:10 2012 +0100 @@ -0,0 +1,44 @@ +local xmlns_mam = "urn:xmpp:mam:tmp" +local uuid = require "util.uuid".generate; + +function verse.plugins.archive(stream) + function stream:query_archive(where, query_params, callback) + local queryid = uuid(); + local query_st = verse.iq{ type="get", to=where } + :tag("query", { xmlns = xmlns_mam, queryid = queryid }); + + local params = { "with", "start", "end" }; + local query_params = query_params or {}; + for i=1,#params do + local k = params[i]; + if query_params[k] then + query_st:tag(k):text(query_params[k]); + end + end + + local results = {}; + local function handle_archived_message(message) + local result_tag = message:get_child("result", xmlns_mam); + if result_tag and result_tag.attr.queryid == queryid then + local forwarded = message:get_child("forwarded", "urn:xmpp:forward:0"); + + local delay = forwarded:get_child("delay", "urn:xmpp:delay"); + local stamp = delay and delay.attr.stamp or nil; + + local message = forwarded:get_child("message", "jabber:client") + + results[#results+1] = { stamp = stamp, message = message }; + return true + end + end + + self:hook("message", handle_archived_message, 1); + self:send_iq(query_st, function(reply) + self:unhook("message", handle_archived_message); + callback(reply.attr.type == "result" and #results, results); + return true + end); + end + + --TODO Settings +end diff -r e1833e9bd25b -r c5b7a4c717a6 squishy --- a/squishy Sun Jan 01 22:48:11 2012 +0100 +++ b/squishy Fri Jan 06 16:54:10 2012 +0100 @@ -52,6 +52,8 @@ "vcard", "vcard_update"; -- Carbons "carbons"; + + "archive"; } for _, plugin in ipairs(plugins) do