Diff

mod_carbons/mod_carbons.lua @ 804:9927d88a1b2a

mod_carbons: Merge enable and disable handlers
author Kim Alvefur <zash@zash.se>
date Sun, 26 Aug 2012 18:56:50 +0200
parent 743:5f7dd5336dbe
child 832:9087431d35f6
line wrap: on
line diff
--- 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;