changeset 6428:23e3edb6f9ea

mod_muc_restrict_attention: Change logic:, always disallow unaffiliated, always allow admin and owner and make it configurable for members. Also it actually works O_o.
author Menel <menel@snikket.de>
date Tue, 10 Mar 2026 14:24:07 +0100
parents 03e46a11eac6
children 66d7da6a9032
files mod_muc_restrict_attention/README.md mod_muc_restrict_attention/mod_muc_restrict_attention.lua
diffstat 2 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_restrict_attention/README.md	Tue Mar 10 12:18:08 2026 +0100
+++ b/mod_muc_restrict_attention/README.md	Tue Mar 10 14:24:07 2026 +0100
@@ -1,13 +1,14 @@
 ---
 summary: Strip XEP-0224 Attention from unaffiliated users in rooms
 labels:
-- Stage-Alpha
+- Stage-Beta
 ...
 
 # Introduction
 
 This module adds a room configuration option to strip XEP-0224 Attention from
-unaffiliated users in MUCs.
+members in MUCs,so that only admins and higher can use it.
+It will **always** strip it from unaffiliated users in MUCs.
 
 This can prevent spam and noise in clients that don't have precautions against this in place.
 
@@ -27,15 +28,13 @@
 A default setting can be provided in the config file, defaults to true:
 
 ``` {.lua}
-muc_room_default_restrict_attention = true
-
+muc_restrict_attention_from_members = true
 ```
 
 # Todo
 
-- restrict it for Members too and also strip it from everyone per room.
-- Actually test it. Didn't find a client that allowed me to try as unaffiliated user.
+- Restrict fine tuned, per every affiliation.
 
 # Compatibility
 
-Should work with Prosody >= 13.0
+Work with Prosody >= 13.0
--- a/mod_muc_restrict_attention/mod_muc_restrict_attention.lua	Tue Mar 10 12:18:08 2026 +0100
+++ b/mod_muc_restrict_attention/mod_muc_restrict_attention.lua	Tue Mar 10 14:24:07 2026 +0100
@@ -1,6 +1,6 @@
 module:depends"muc";
 
-local restrict_by_default = module:get_option_boolean("muc_room_default_restrict_attention", true);
+local restrict_by_default = module:get_option_boolean("muc_restrict_attention_from_members", true);
 
 local function should_restrict_attention(room)
 	local restrict_attention = room._data.restrict_attention;
@@ -15,7 +15,7 @@
 	table.insert(form, {
 		name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_attention",
 		type = "boolean",
-		label = "Allow \"XEP-0224: Attention\" from non-members",
+		label = "Allow \"XEP-0224: Attention\" from members",
 		value = not should_restrict_attention(room),
 	});
 end);
@@ -58,9 +58,13 @@
 
 module:hook("muc-occupant-groupchat", function (event)
 	local stanza = event.stanza;
-	if stanza.attr.type ~= "groupchat" then return; end
-	if event.room:get_affiliation(stanza.attr.from) then return end
-	if should_restrict_attention(event.room) then
+	if stanza.attr.type ~= "groupchat" then return; end -- not relevant
+	if event.room:get_affiliation(stanza.attr.from) == 'admin'
+		or event.room:get_affiliation(stanza.attr.from) == 'owner' then
+		return
+	end
+	if should_restrict_attention(event.room)
+		or not event.room:get_affiliation(stanza.attr.from) then
 		stanza:maptags(filter_attention_tags);
-	end
-end, 20);
+ 	end
+end, 9);