comparison mod_carbons/mod_carbons.lua @ 1184:0d3d15586d7e

mod_carbons: Use iq-type events
author Kim Alvefur <zash@zash.se>
date Thu, 05 Sep 2013 01:02:01 +0200
parents 3acb01ca7e5c
children d3e75f6dde9b
comparison
equal deleted inserted replaced
1183:3acb01ca7e5c 1184:0d3d15586d7e
11 local xmlns_forward = "urn:xmpp:forward:0"; 11 local xmlns_forward = "urn:xmpp:forward:0";
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 local state = stanza.tags[1].attr.mode or stanza.tags[1].name;
17 local state = stanza.tags[1].attr.mode or stanza.tags[1].name; 17 module:log("debug", "%s %sd carbons", origin.full_jid, state);
18 module:log("debug", "%s %sd carbons", origin.full_jid, state); 18 origin.want_carbons = state == "enable" and stanza.tags[1].attr.xmlns;
19 origin.want_carbons = state == "enable" and stanza.tags[1].attr.xmlns; 19 return origin.send(st.reply(stanza));
20 origin.send(st.reply(stanza));
21 return true
22 end
23 end 20 end
24 module:hook("iq/self/"..xmlns_carbons..":disable", toggle_carbons); 21 module:hook("iq-set/self/"..xmlns_carbons..":disable", toggle_carbons);
25 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); 22 module:hook("iq-set/self/"..xmlns_carbons..":enable", toggle_carbons);
26 23
27 -- COMPAT 24 -- COMPAT
28 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons); 25 module:hook("iq-set/self/"..xmlns_carbons_old..":disable", toggle_carbons);
29 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons); 26 module:hook("iq-set/self/"..xmlns_carbons_old..":enable", toggle_carbons);
30 module:hook("iq/self/"..xmlns_carbons_really_old..":carbons", toggle_carbons); 27 module:hook("iq-set/self/"..xmlns_carbons_really_old..":carbons", toggle_carbons);
31 28
32 local function message_handler(event, c2s) 29 local function message_handler(event, c2s)
33 local origin, stanza = event.origin, event.stanza; 30 local origin, stanza = event.origin, event.stanza;
34 local orig_type = stanza.attr.type; 31 local orig_type = stanza.attr.type;
35 local orig_from = stanza.attr.from; 32 local orig_from = stanza.attr.from;