From 45415ef8daedfee92406134f1bf65ef0fe6ecf5e Mon Sep 17 00:00:00 2001 From: damencho Date: Thu, 30 Nov 2023 17:50:22 -0600 Subject: [PATCH] fix: When host is loaded muc module maybe still be nil in rayo filter. This can prevent outgoing calls due to error. --- .../prosody-plugins/mod_filter_iq_rayo.lua | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/resources/prosody-plugins/mod_filter_iq_rayo.lua b/resources/prosody-plugins/mod_filter_iq_rayo.lua index f8871a21debc..11c7fa85fb17 100644 --- a/resources/prosody-plugins/mod_filter_iq_rayo.lua +++ b/resources/prosody-plugins/mod_filter_iq_rayo.lua @@ -246,8 +246,25 @@ function process_set_affiliation(event) end end -process_host_module(main_muc_component_host, function(host_module, host) - main_muc_service = prosody.hosts[host].modules.muc; +function process_main_muc_loaded(main_muc, host_module) + module:log('debug', 'Main muc loaded'); + main_muc_service = main_muc; + module:log("info", "Hook to muc events on %s", main_muc_component_host); host_module:hook("muc-pre-set-affiliation", process_set_affiliation); +end + +process_host_module(main_muc_component_host, function(host_module, host) + local muc_module = prosody.hosts[host].modules.muc; + + if muc_module then + process_main_muc_loaded(muc_module, host_module); + else + module:log('debug', 'Will wait for muc to be available'); + prosody.hosts[host].events.add_handler('module-loaded', function(event) + if (event.module == 'muc') then + process_main_muc_loaded(prosody.hosts[host].modules.muc, host_module); + end + end); + end end);