comparison 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
parents 5f7dd5336dbe
children 9087431d35f6
comparison
equal deleted inserted replaced
803:be509416d64c 804:9927d88a1b2a
8 local jid_split = require "util.jid".split; 8 local jid_split = require "util.jid".split;
9 local xmlns_carbons = "urn:xmpp:carbons:1"; 9 local xmlns_carbons = "urn:xmpp:carbons:1";
10 local xmlns_forward = "urn:xmpp:forward:0"; 10 local xmlns_forward = "urn:xmpp:forward:0";
11 local host_sessions = hosts[module.host].sessions; 11 local host_sessions = hosts[module.host].sessions;
12 12
13 module:hook("iq/self/"..xmlns_carbons..":enable", function(event) 13 local function toggle_carbons(event)
14 local origin, stanza = event.origin, event.stanza; 14 local origin, stanza = event.origin, event.stanza;
15 if stanza.attr.type == "set" then 15 if stanza.attr.type == "set" then
16 module:log("debug", "%s enabled carbons", origin.full_jid); 16 local state = stanza.tags[1].name;
17 origin.want_carbons = true; 17 module:log("debug", "%s %sd carbons", origin.full_jid, state);
18 origin.want_carbons = state == "enable";
18 origin.send(st.reply(stanza)); 19 origin.send(st.reply(stanza));
19 return true 20 return true
20 end 21 end
21 end); 22 end
22 23 module:hook("iq/self/"..xmlns_carbons..":disable", toggle_carbons);
23 module:hook("iq/self/"..xmlns_carbons..":disable", function(event) 24 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons);
24 local origin, stanza = event.origin, event.stanza;
25 if stanza.attr.type == "set" then
26 module:log("debug", "%s disabled carbons", origin.full_jid);
27 origin.want_carbons = nil;
28 origin.send(st.reply(stanza));
29 return true
30 end
31 end);
32 25
33 local function message_handler(event, c2s) 26 local function message_handler(event, c2s)
34 local origin, stanza = event.origin, event.stanza; 27 local origin, stanza = event.origin, event.stanza;
35 local orig_type = stanza.attr.type; 28 local orig_type = stanza.attr.type;
36 local orig_to = stanza.attr.to; 29 local orig_to = stanza.attr.to;