To allow default role to vary by affiliation data and not just affiliation 
string.

Attached.

--
You received this message because you are subscribed to the Google Groups 
"prosody-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/prosody-dev/aijAPkI1gaSwsbgT%40singpolyma-beefy.lan.
# HG changeset patch
# User Stephen Paul Weber <[email protected]>
# Date 1781055447 18000
#      Tue Jun 09 20:37:27 2026 -0500
# Node ID 89cb461f4ec99c701c4df06316f3c8cd89804d5e
# Parent  2ec517d8d43e59900e6fa5553247e62243d9667e
mod_muc: provide full jid to default role hook

To allow default role to vary by affiliation data and not just affiliation string.

diff -r 2ec517d8d43e -r 89cb461f4ec9 plugins/mod_muc_mam.lua
--- a/plugins/mod_muc_mam.lua	Sun Jun 07 20:32:55 2026 +0200
+++ b/plugins/mod_muc_mam.lua	Tue Jun 09 20:37:27 2026 -0500
@@ -377,7 +377,7 @@
 		if occupant then
 			local actor = jid_bare(occupant.jid);
 			local affiliation = self:get_affiliation(actor) or "none";
-			local role = self:get_role(actor) or self:get_default_role(affiliation);
+			local role = self:get_role(actor) or self:get_default_role(actor);
 			stored_stanza:add_direct_child(st.stanza("x", { xmlns = xmlns_muc_user })
 				:tag("item", { affiliation = affiliation; role = role; jid = actor }));
 		end
diff -r 2ec517d8d43e -r 89cb461f4ec9 plugins/muc/muc.lib.lua
--- a/plugins/muc/muc.lib.lua	Sun Jun 07 20:32:55 2026 +0200
+++ b/plugins/muc/muc.lib.lua	Tue Jun 09 20:37:27 2026 -0500
@@ -48,9 +48,13 @@
 	return self._jid_nick[real_jid]
 end
 
-function room_mt:get_default_role(affiliation)
+function room_mt:get_default_role(real_jid)
+	local node, host = jid_split(real_jid);
+	local bare = node and node.."@"..host or host;
+	local affiliation = self:get_affiliation(bare);
 	local role = module:fire_event("muc-get-default-role", {
 		room = self;
+		bare_jid = bare;
 		affiliation = affiliation;
 		affiliation_rank = valid_affiliations[affiliation or "none"];
 	});
@@ -68,8 +72,7 @@
 --- Occupant functions
 function room_mt:new_occupant(bare_real_jid, nick)
 	local occupant = occupant_lib.new(bare_real_jid, nick);
-	local affiliation = self:get_affiliation(bare_real_jid);
-	occupant.role = self:get_default_role(affiliation);
+	occupant.role = self:get_default_role(bare_real_jid);
 	return occupant;
 end
 
@@ -1156,7 +1159,8 @@
 			return true;
 		end
 	elseif _rol and valid_roles[_rol or "none"] and not _aff then
-		local role = self:get_role(self:get_occupant_jid(actor)) or self:get_default_role(affiliation);
+		local occupant_jid = self:get_occupant_jid(actor)
+		local role = self:get_role(occupant_jid) or self:get_default_role(occupant_jid);
 		if valid_roles[role or "none"] >= valid_roles.moderator then
 			if _rol == "none" then _rol = nil; end
 			local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin";);
@@ -1268,7 +1272,7 @@
 	local room, stanza = event.room, event.stanza;
 	local _from = stanza.attr.from;
 	local inviter = room:get_occupant_by_real_jid(_from);
-	local role = inviter and inviter.role or room:get_default_role(room:get_affiliation(_from));
+	local role = inviter and inviter.role or room:get_default_role(_from);
 	if valid_roles[role or "none"] <= valid_roles.visitor then
 		event.origin.send(st.error_reply(stanza, "auth", "forbidden"));
 		return true;
@@ -1495,7 +1499,7 @@
 	end
 
 	-- Update roles
-	local role = self:get_default_role(affiliation);
+	local role = self:get_default_role(jid);
 	local role_rank = valid_roles[role or "none"];
 	local occupants_updated = {}; -- Filled with old roles
 	for nick, occupant in self:each_occupant() do -- luacheck: ignore 213
diff -r 2ec517d8d43e -r 89cb461f4ec9 plugins/muc/whois.lib.lua
--- a/plugins/muc/whois.lib.lua	Sun Jun 07 20:32:55 2026 +0200
+++ b/plugins/muc/whois.lib.lua	Tue Jun 09 20:37:27 2026 -0500
@@ -51,7 +51,7 @@
 -- Mask 'from' jid as occupant jid if room is anonymous
 module:hook("muc-invite", function(event)
 	local room, stanza = event.room, event.stanza;
-	if get_whois(room) == "moderators" and room:get_default_role(room:get_affiliation(stanza.attr.to)) ~= "moderator" then
+	if get_whois(room) == "moderators" and room:get_default_role(stanza.attr.to) ~= "moderator" then
 		local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user";):get_child("invite");
 		local occupant_jid = room:get_occupant_jid(invite.attr.from);
 		if occupant_jid ~= nil then -- FIXME: This will expose real jid if inviter is not in room
diff -r 2ec517d8d43e -r 89cb461f4ec9 teal-src/prosody/plugins/muc/muc.lib.d.tl
--- a/teal-src/prosody/plugins/muc/muc.lib.d.tl	Sun Jun 07 20:32:55 2026 +0200
+++ b/teal-src/prosody/plugins/muc/muc.lib.d.tl	Tue Jun 09 20:37:27 2026 -0500
@@ -60,7 +60,7 @@
 	get_registered_jid : function (Room, nick : string) : string
 
 	-- Role methods
-	get_default_role : function (Room, Affiliation) : Role, integer
+	get_default_role : function (Room, jid : string) : Role, integer
 	get_role : function (Room, nick : string) : Role
 	may_set_role : function (Room, actor : string, Occupant, Role) : boolean
 	set_role : function (Room, actor : string, occupant_jid : string, Role, reason : string) : boolean, string, string, string

Reply via email to