view mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua @ 5907:d194d1012fd3

Updating dox for mod_rest. Ideas expressed / clarified: 1) Making clear that mod_rest isn't to be installed under VirtualHosts AND as a component. 2) Understanding some of the implications of this choice: A) Changes to user authentication B) How it affects subdomains 3) More consistent use of domain names for clarity. 4) Using different heading sizes to show scope of section. Essentially, I added all the tidbits I had to clarify in getting this to work in my own example.
author Ben Smith <bens@effortlessis.com>
date Mon, 13 May 2024 13:25:13 -0700
parents c83bc703825d
children
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);
		room._reserved_nicks = nil; -- force refresh of nickname map
	end
end);