mod_csi: Cache CSI module availability to improve readabilty
authorKim Alvefur <zash@zash.se>
Sat, 23 Nov 2019 17:15:34 +0100
changeset 10433 0b04d25c4ffb
parent 10432 12a10208d86a
child 10434 46dd9df2db0c
mod_csi: Cache CSI module availability to improve readabilty
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