# HG changeset patch # User Kim Alvefur # Date 1350438435 -7200 # Node ID 0900ba54991ea673fa2257b52fa85d6383f53683 # Parent 6e2ec1825182384e3dfe98cf402e15702a186917 mod_carbons: Update to latest version of XEP-0280, while supporting the old version. diff -r 6e2ec1825182 -r 0900ba54991e mod_carbons/mod_carbons.lua --- a/mod_carbons/mod_carbons.lua Mon Oct 15 21:02:43 2012 +0200 +++ b/mod_carbons/mod_carbons.lua Wed Oct 17 03:47:15 2012 +0200 @@ -5,7 +5,8 @@ local st = require "util.stanza"; local jid_bare = require "util.jid".bare; -local xmlns_carbons = "urn:xmpp:carbons:1"; +local xmlns_carbons = "urn:xmpp:carbons:2"; +local xmlns_carbons_old = "urn:xmpp:carbons:1"; local xmlns_forward = "urn:xmpp:forward:0"; local full_sessions, bare_sessions = full_sessions, bare_sessions; @@ -14,7 +15,7 @@ if stanza.attr.type == "set" then local state = stanza.tags[1].name; module:log("debug", "%s %sd carbons", origin.full_jid, state); - origin.want_carbons = state == "enable"; + origin.want_carbons = state == "enable" and stanza.tags[1].attr.xmlns; origin.send(st.reply(stanza)); return true end @@ -22,6 +23,10 @@ module:hook("iq/self/"..xmlns_carbons..":disable", toggle_carbons); module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); +-- COMPAT +module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons); +module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons); + local function message_handler(event, c2s) local origin, stanza = event.origin, event.stanza; local orig_type = stanza.attr.type; @@ -75,6 +80,12 @@ :tag("forwarded", { xmlns = xmlns_forward }) :add_child(copy):reset(); + -- COMPAT + local carbon_old = st.message{ from = bare_jid, type = orig_type, } + :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons_old }):up() + :tag("forwarded", { xmlns = xmlns_forward }) + :add_child(copy):reset(); + user_sessions = user_sessions and user_sessions.sessions; for _, session in pairs(user_sessions) do -- Carbons are sent to resources that have enabled it @@ -85,6 +96,7 @@ and (c2s or session.priority ~= top_priority) then carbon.attr.to = session.full_jid; module:log("debug", "Sending carbon to %s", session.full_jid); + local carbon = session.want_carbons == xmlns_carbons_old and carbon_old or carbon; -- COMPAT session.send(carbon); end end