# HG changeset patch # User Kim Alvefur # Date 1346000210 -7200 # Node ID 9927d88a1b2aa4a77c8a80efad58b6e198b329c1 # Parent be509416d64c1a30acfee25fe8f5e740576c6fb8 mod_carbons: Merge enable and disable handlers diff -r be509416d64c -r 9927d88a1b2a mod_carbons/mod_carbons.lua --- a/mod_carbons/mod_carbons.lua Sat Aug 25 19:25:16 2012 +0200 +++ b/mod_carbons/mod_carbons.lua Sun Aug 26 18:56:50 2012 +0200 @@ -10,25 +10,18 @@ local xmlns_forward = "urn:xmpp:forward:0"; local host_sessions = hosts[module.host].sessions; -module:hook("iq/self/"..xmlns_carbons..":enable", function(event) +local function toggle_carbons(event) local origin, stanza = event.origin, event.stanza; if stanza.attr.type == "set" then - module:log("debug", "%s enabled carbons", origin.full_jid); - origin.want_carbons = true; + local state = stanza.tags[1].name; + module:log("debug", "%s %sd carbons", origin.full_jid, state); + origin.want_carbons = state == "enable"; origin.send(st.reply(stanza)); return true end -end); - -module:hook("iq/self/"..xmlns_carbons..":disable", function(event) - local origin, stanza = event.origin, event.stanza; - if stanza.attr.type == "set" then - module:log("debug", "%s disabled carbons", origin.full_jid); - origin.want_carbons = nil; - origin.send(st.reply(stanza)); - return true - end -end); +end +module:hook("iq/self/"..xmlns_carbons..":disable", toggle_carbons); +module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); local function message_handler(event, c2s) local origin, stanza = event.origin, event.stanza;