Hello, This is the work I've done at mod_mam[0] in order to support the latest version of XEP-0313
The module now supports both versions "urn:xmpp:mam:0" and "urn:xmpp:mam:1" Attached patch from hg export output. Cheers, Victor Seva [0] https://github.com/sipwise/prosody/commit/9e65f1029f84b0336f5096f6e 56b27cb117ec568 -- You received this message because you are subscribed to the Google Groups "prosody-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to prosody-dev+unsubscr...@googlegroups.com. To post to this group, send email to prosody-dev@googlegroups.com. Visit this group at https://groups.google.com/group/prosody-dev. For more options, visit https://groups.google.com/d/optout.
# HG changeset patch # User Victor Seva <linuxman...@torreviejawireless.org> # Date 1483002970 -3600 # Thu Dec 29 10:16:10 2016 +0100 # Node ID 0408d0df2197d9190668a50fafc2225f40d93e81 # Parent 06e3b0ef8bdfcad9f76e94d7850161e89db88715 mod_mam: support XEP-0313 v0.5 keeping compatibility with previous XEP-0313 v0.3 diff -r 06e3b0ef8bdf -r 0408d0df2197 mod_mam/mamprefsxml.lib.lua --- a/mod_mam/mamprefsxml.lib.lua Mon Dec 26 15:43:32 2016 +0100 +++ b/mod_mam/mamprefsxml.lib.lua Thu Dec 29 10:16:10 2016 +0100 @@ -4,7 +4,6 @@ -- This file is MIT/X11 licensed. local st = require"util.stanza"; -local xmlns_mam = "urn:xmpp:mam:0"; local default_attrs = { always = true, [true] = "always", @@ -12,7 +11,7 @@ roster = "roster", } -local function tostanza(prefs) +local function tostanza(prefs, xmlns_mam) local default = prefs[false]; default = default_attrs[default]; local prefstanza = st.stanza("prefs", { xmlns = xmlns_mam, default = default }); diff -r 06e3b0ef8bdf -r 0408d0df2197 mod_mam/mod_mam.lua --- a/mod_mam/mod_mam.lua Mon Dec 26 15:43:32 2016 +0100 +++ b/mod_mam/mod_mam.lua Thu Dec 29 10:16:10 2016 +0100 @@ -3,7 +3,8 @@ -- -- This file is MIT/X11 licensed. -local xmlns_mam = "urn:xmpp:mam:0"; +local xmlns_mam0 = "urn:xmpp:mam:0"; +local xmlns_mam1 = "urn:xmpp:mam:1"; local xmlns_delay = "urn:xmpp:delay"; local xmlns_forward = "urn:xmpp:forward:0"; @@ -54,11 +55,11 @@ local cleanup; -- Handle prefs. -module:hook("iq/self/"..xmlns_mam..":prefs", function(event) +local function handle_prefs(event, xmlns_mam) local origin, stanza = event.origin, event.stanza; local user = origin.username; if stanza.attr.type == "get" then - local prefs = prefs_to_stanza(get_prefs(user)); + local prefs = prefs_to_stanza(get_prefs(user), xmlns_mam); local reply = st.reply(stanza):add_child(prefs); origin.send(reply); else -- type == "set" @@ -72,24 +73,47 @@ end end return true; +end + +module:hook("iq/self/"..xmlns_mam1..":prefs", function(event) + return handle_prefs(event, xmlns_mam1) end); -local query_form = dataform { - { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; }; +module:hook("iq/self/"..xmlns_mam0..":prefs", function(event) + return handle_prefs(event, xmlns_mam0) +end); + +local query_form = {} +query_form[xmlns_mam1] = dataform { + { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam1; }; + { name = "with"; type = "jid-single"; }; + { name = "start"; type = "text-single" }; + { name = "end"; type = "text-single"; }; +}; +query_form[xmlns_mam0] = dataform { + { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam0; }; { name = "with"; type = "jid-single"; }; { name = "start"; type = "text-single" }; { name = "end"; type = "text-single"; }; }; -- Serve form -module:hook("iq-get/self/"..xmlns_mam..":query", function(event) +local function get_form(event, xmlns_mam) local origin, stanza = event.origin, event.stanza; - origin.send(st.reply(stanza):add_child(query_form:form())); + origin.send(st.reply(stanza):add_child(query_form[xmlns_mam]:form())); return true; +end + +module:hook("iq-get/self/"..xmlns_mam1..":query", function(event) + return get_form(event, xmlns_mam1); +end); + +module:hook("iq-get/self/"..xmlns_mam0..":query", function(event) + return get_form(event, xmlns_mam0); end); -- Handle archive queries -module:hook("iq-set/self/"..xmlns_mam..":query", function(event) +local function handle_query(event, xmlns_mam) local origin, stanza = event.origin, event.stanza; local query = stanza.tags[1]; local qid = query.attr.queryid; @@ -101,7 +125,7 @@ local form = query:get_child("x", "jabber:x:data"); if form then local err; - form, err = query_form:data(form); + form, err = query_form[xmlns_mam]:data(form); if err then origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))); return true; @@ -145,9 +169,13 @@ return true; end local total = tonumber(err); + local msg_reply_attr; - origin.send(st.reply(stanza)); - local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; + if xmlns_mam == xmlns_mam0 then + origin.send(st.reply(stanza)); + msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; + end + local results = {}; @@ -192,11 +220,27 @@ -- That's all folks! module:log("debug", "Archive query %s completed", tostring(qid)); - origin.send(st.message(msg_reply_attr) - :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete }) - :add_child(rsm.generate { - first = first, last = last, count = total })); + local reply_stanza; + if xmlns_mam == xmlns_mam0 then + reply_stanza = st.message(msg_reply_attr); + else + reply_stanza = st.reply(stanza); + end + + if form or xmlns_mam == xmlns_mam0 then + reply_stanza:tag("fin",{ xmlns = xmlns_mam, queryid = qid, complete = complete }) + :add_child(rsm.generate { first = first, last = last, count = total }) + end + origin.send(reply_stanza); return true; +end + +module:hook("iq-set/self/"..xmlns_mam1..":query", function(event) + return handle_query(event, xmlns_mam1); +end); + +module:hook("iq-set/self/"..xmlns_mam0..":query", function(event) + return handle_query(event, xmlns_mam0); end); local function has_in_roster(user, who) @@ -330,9 +374,11 @@ module:hook("message/bare", message_handler, 2); module:hook("message/full", message_handler, 2); -module:add_feature(xmlns_mam); -- COMPAT with XEP-0313 v 0.1 +module:add_feature(xmlns_mam0); -- COMPAT with XEP-0313 v 0.1 +module:add_feature(xmlns_mam1); -- COMPAT with XEP-0313 v 0.5 module:hook("account-disco-info", function(event) - (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); + (event.reply or event.stanza):tag("feature", {var=xmlns_mam0}):up(); + (event.reply or event.stanza):tag("feature", {var=xmlns_mam1}):up(); end);
signature.asc
Description: This is a digitally signed message part