Comparison

mod_carbons/mod_carbons.lua @ 1183:3acb01ca7e5c

mod_carbons: Handle enabled/disable with the same callback for all versions
author Kim Alvefur <zash@zash.se>
date Thu, 05 Sep 2013 01:00:08 +0200
parent 1167:8ceab2331216
child 1184:0d3d15586d7e
comparison
equal deleted inserted replaced
1182:547b3c05cc06 1183:3acb01ca7e5c
12 local full_sessions, bare_sessions = full_sessions, bare_sessions; 12 local full_sessions, bare_sessions = full_sessions, bare_sessions;
13 13
14 local function toggle_carbons(event) 14 local function toggle_carbons(event)
15 local origin, stanza = event.origin, event.stanza; 15 local origin, stanza = event.origin, event.stanza;
16 if stanza.attr.type == "set" then 16 if stanza.attr.type == "set" then
17 local state = stanza.tags[1].name; 17 local state = stanza.tags[1].attr.mode or stanza.tags[1].name;
18 module:log("debug", "%s %sd carbons", origin.full_jid, state); 18 module:log("debug", "%s %sd carbons", origin.full_jid, state);
19 origin.want_carbons = state == "enable" and stanza.tags[1].attr.xmlns; 19 origin.want_carbons = state == "enable" and stanza.tags[1].attr.xmlns;
20 origin.send(st.reply(stanza)); 20 origin.send(st.reply(stanza));
21 return true 21 return true
22 end 22 end
25 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); 25 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons);
26 26
27 -- COMPAT 27 -- COMPAT
28 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons); 28 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons);
29 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons); 29 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons);
30 30 module:hook("iq/self/"..xmlns_carbons_really_old..":carbons", toggle_carbons);
31 -- COMPAT :(
32 if module:get_option_boolean("carbons_v0") then
33 module:hook("iq/self/"..xmlns_carbons_really_old..":carbons", function(event)
34 local origin, stanza = event.origin, event.stanza;
35 if stanza.attr.type == "set" then
36 local state = stanza.tags[1].attr.mode;
37 origin.want_carbons = state == "enable" and xmlns_carbons_really_old;
38 origin.send(st.reply(stanza));
39 return true;
40 end
41 end);
42 end
43 31
44 local function message_handler(event, c2s) 32 local function message_handler(event, c2s)
45 local origin, stanza = event.origin, event.stanza; 33 local origin, stanza = event.origin, event.stanza;
46 local orig_type = stanza.attr.type; 34 local orig_type = stanza.attr.type;
47 local orig_from = stanza.attr.from; 35 local orig_from = stanza.attr.from;