view mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua @ 4895:2542fd80cd15

mod_turn_external: Fix type of config option (thanks mirux) There was a separate boolean option to enable TLS before, but it was merged with the port number option and it seems the typed API interface got confused. Backport of trunk rev aa7a8aa64d3f
author Kim Alvefur <zash@zash.se>
date Tue, 15 Feb 2022 21:51:52 +0100
parents 85d4ab318d66
children c83bc703825d
line wrap: on
line source

local jid = require "util.jid";
local set = require "util.set";

local active_affiliations = set.new({ "member", "admin", "owner" });

module:hook("muc-occupant-joined", function (event)
	local room, occupant = event.room, event.occupant;
	local user_jid = occupant.bare_jid;
	local user_affiliation = room:get_affiliation(user_jid);
	if not active_affiliations:contains(user_affiliation) then
		return;
	end
	local aff_data = event.room:get_affiliation_data(user_jid);
	if not aff_data then
		local reserved_nick = jid.resource(occupant.nick);
		module:log("debug", "Automatically reserving nickname '%s' for <%s>", reserved_nick, user_jid);
		room:set_affiliation_data(user_jid, "reserved_nickname", reserved_nick);
	end
end);