view mod_reload_modules/mod_reload_modules.lua @ 3656:3e0f4d727825

mod_vcard_muc: Add an alternative method of signaling avatar change When the avatar has been changed, a signal is sent that the room configuration has changed. Clients then do a disco#info query to find the SHA-1 of the new avatar. They can then fetch it as before, or not if they have it cached already. This is meant to be less disruptive than signaling via presence, which caused problems for some clients. If clients transition to the new method, the old one can eventually be removed. The namespace is made up while waiting for standardization. Otherwise it is very close to what's described in https://xmpp.org/extensions/inbox/muc-avatars.html
author Kim Alvefur <zash@zash.se>
date Sun, 25 Aug 2019 20:46:43 +0200
parents fc08d841a309
children 57eb248f6dd3
line wrap: on
line source

local array, it, set = require "util.array", require "util.iterators", require "util.set";
local mm = require "core.modulemanager";

function reload_all()
	local modules = module:get_option_set("reload_modules", {});
	if not modules then
		module:log("warn", "No modules listed in the config to reload - set reload_modules to a list");
		return;
	end
	local configured_modules = module:get_option_inherited_set("modules_enabled", {});
	local loaded_modules = set.new(array.collect(it.keys(prosody.hosts[module.host].modules)));
	local need_to_load = set.intersection(configured_modules - loaded_modules, modules);
	local need_to_unload = set.intersection(loaded_modules - configured_modules, modules);

	for module_name in need_to_load do
		module:log("debug", "Loading %s", module_name);
		mm.load(module.host, module_name);
	end

	for module_name in need_to_unload do
		module:log("debug", "Unloading %s", module_name);
		mm.unload(module.host, module_name);
	end

	modules:exclude(need_to_load+need_to_unload)

	for module_name in set.intersection(modules,configured_modules) do
		module:log("debug", "Reloading %s", module_name);
		mm.reload(module.host, module_name);
	end
end


if module.hook_global then
	module:hook_global("config-reloaded", reload_all);
else -- COMPAT w/pre-0.9
	function module.load()
		prosody.events.add_handler("config-reloaded", reload_all);
	end
	function module.unload()
		prosody.events.remove_handler("config-reloaded", reload_all);
	end
end