comparison mod_muc_gc10/mod_muc_gc10.lua @ 2957:0f813e22e3fa

Merge commit
author JC Brand <jc@opkode.com>
date Tue, 27 Mar 2018 10:51:25 +0200
parents 37ec4c2f319a
children 8a15a9b13881
comparison
equal deleted inserted replaced
2956:d0ca211e1b0e 2957:0f813e22e3fa
1 local jid_bare = require "util.jid".bare;
2 local st = require "util.stanza";
3
4 local rooms = module:depends"muc".rooms;
5
6 module:hook("presence/full", function (event)
7 local stanza, origin = event.stanza, event.origin;
8 if stanza.attr.type ~= nil then return end
9
10 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc");
11
12 local room_jid = jid_bare(stanza.attr.to);
13 local room = rooms[room_jid];
14 if not room then
15 if muc_x then
16 -- Normal MUC creation
17 else
18 module:log("info", "GC 1.0 room creation from %s", stanza.attr.from);
19 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version"));
20 end
21 return;
22 end
23 local current_nick = room._jid_nick[stanza.attr.from];
24
25 if current_nick then
26 -- present
27 if muc_x then
28 module:log("info", "MUC desync with %s", stanza.attr.from);
29 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version"));
30 else
31 -- normal presence update
32 end
33 else
34 -- joining
35 if muc_x then
36 -- normal join
37 else
38 module:log("info", "GC 1.0 join from %s", stanza.attr.from);
39 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version"));
40 end
41 end
42 end);
43
44 module:hook("iq-result/host/"..module.name, function (event)
45 local stanza, origin = event.stanza, event.origin;
46 local version = stanza:get_child("query", "jabber:iq:version");
47 if not version then
48 module:log("info", "%s replied with an invalid version reply: %s", stanza.attr.from, tostring(stanza));
49 return true;
50 end
51 module:log("info", "%s is running: %s %s", stanza.attr.from, version:get_child_text("name"), version:get_child_text("version"));
52 end);
53
54 module:hook("iq-error/host/"..module.name, function (event)
55 local stanza, origin = event.stanza, event.origin;
56 module:log("info", "%s replied with an error: %s %s", stanza.attr.from, stanza:get_error());
57 return true;
58 end);