# HG changeset patch # User Kim Alvefur # Date 1574525734 -3600 # Node ID 0b04d25c4ffb4cb6924cdf2d8682297f629b283d # Parent 12a10208d86a0f7242deabb8517cabfe16e4ad32 mod_csi: Cache CSI module availability to improve readabilty diff -r 12a10208d86a -r 0b04d25c4ffb plugins/mod_csi.lua --- a/plugins/mod_csi.lua Sat Nov 23 17:09:48 2019 +0100 +++ b/plugins/mod_csi.lua Sat Nov 23 17:15:34 2019 +0100 @@ -2,8 +2,9 @@ local xmlns_csi = "urn:xmpp:csi:0"; local csi_feature = st.stanza("csi", { xmlns = xmlns_csi }); +local csi_handler_available = nil; module:hook("stream-features", function (event) - if event.origin.username and prosody.hosts[module.host].events._handlers["csi-client-active"] then + if event.origin.username and csi_handler_available then event.features:add_child(csi_feature); end end); @@ -23,8 +24,10 @@ function module.load() if prosody.hosts[module.host].events._handlers["csi-client-active"] then + csi_handler_available = true; module:set_status("core", "CSI handler module loaded"); else + csi_handler_available = false; module:set_status("warn", "No CSI handler module loaded"); end end