Comparison

plugins/mod_csi.lua @ 11120:b2331f3dfeea

Merge 0.11->trunk
author Matthew Wild <mwild1@gmail.com>
date Wed, 30 Sep 2020 09:50:33 +0100
parent 10429:0b04d25c4ffb
child 12977:74b9e05af71e
comparison
equal deleted inserted replaced
11119:68df52bf08d5 11120:b2331f3dfeea
1 local st = require "util.stanza"; 1 local st = require "util.stanza";
2 local xmlns_csi = "urn:xmpp:csi:0"; 2 local xmlns_csi = "urn:xmpp:csi:0";
3 local csi_feature = st.stanza("csi", { xmlns = xmlns_csi }); 3 local csi_feature = st.stanza("csi", { xmlns = xmlns_csi });
4 4
5 local csi_handler_available = nil;
5 module:hook("stream-features", function (event) 6 module:hook("stream-features", function (event)
6 if event.origin.username then 7 if event.origin.username and csi_handler_available then
7 event.features:add_child(csi_feature); 8 event.features:add_child(csi_feature);
8 end 9 end
9 end); 10 end);
10 11
11 function refire_event(name) 12 function refire_event(name)
19 end 20 end
20 21
21 module:hook("stanza/"..xmlns_csi..":active", refire_event("csi-client-active")); 22 module:hook("stanza/"..xmlns_csi..":active", refire_event("csi-client-active"));
22 module:hook("stanza/"..xmlns_csi..":inactive", refire_event("csi-client-inactive")); 23 module:hook("stanza/"..xmlns_csi..":inactive", refire_event("csi-client-inactive"));
23 24
25 function module.load()
26 if prosody.hosts[module.host].events._handlers["csi-client-active"] then
27 csi_handler_available = true;
28 module:set_status("core", "CSI handler module loaded");
29 else
30 csi_handler_available = false;
31 module:set_status("warn", "No CSI handler module loaded");
32 end
33 end
34 module:hook("module-loaded", module.load);
35 module:hook("module-unloaded", module.load);