mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua
author Kim Alvefur <zash@zash.se>
Sat, 29 Apr 2023 13:09:46 +0200
changeset 5387 df11a2cbc7b7
parent 4954 c83bc703825d
permissions -rw-r--r--
mod_http_oauth2: Implement RFC 7628 Proof Key for Code Exchange Likely to become mandatory in OAuth 2.1. Backwards compatible since the default 'plain' verifier would compare nil with nil if the relevant parameters are left out.

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);
		room._reserved_nicks = nil; -- force refresh of nickname map
	end
end);