Software / code / prosody
Comparison
plugins/mod_csi.lua @ 10429:0b04d25c4ffb
mod_csi: Cache CSI module availability to improve readabilty
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 23 Nov 2019 17:15:34 +0100 |
| parent | 10428:12a10208d86a |
| child | 12977:74b9e05af71e |
comparison
equal
deleted
inserted
replaced
| 10428:12a10208d86a | 10429:0b04d25c4ffb |
|---|---|
| 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 and prosody.hosts[module.host].events._handlers["csi-client-active"] 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) |
| 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 |
| 24 function module.load() | 25 function module.load() |
| 25 if prosody.hosts[module.host].events._handlers["csi-client-active"] then | 26 if prosody.hosts[module.host].events._handlers["csi-client-active"] then |
| 27 csi_handler_available = true; | |
| 26 module:set_status("core", "CSI handler module loaded"); | 28 module:set_status("core", "CSI handler module loaded"); |
| 27 else | 29 else |
| 30 csi_handler_available = false; | |
| 28 module:set_status("warn", "No CSI handler module loaded"); | 31 module:set_status("warn", "No CSI handler module loaded"); |
| 29 end | 32 end |
| 30 end | 33 end |
| 31 module:hook("module-loaded", module.load); | 34 module:hook("module-loaded", module.load); |
| 32 module:hook("module-unloaded", module.load); | 35 module:hook("module-unloaded", module.load); |