changeset 6446:63ce1af4d099

mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
author Menel <menel@snikket.de>
date Wed, 11 Mar 2026 08:55:15 +0100
parents 54e84ec12c82
children 46fe8e3bf870
files mod_muc_restrict_attention/README.md mod_muc_restrict_attention/mod_muc_restrict_attention.lua
diffstat 2 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_restrict_attention/README.md	Wed Mar 11 00:42:57 2026 +0100
+++ b/mod_muc_restrict_attention/README.md	Wed Mar 11 08:55:15 2026 +0100
@@ -6,7 +6,7 @@
 
 # Introduction
 
-This module strips *XEP-0224 Attention* in rooms.
+This module strips [XEP-0224 Attention] for certain affiliations in rooms.
 It adds a room configuration option to strip it from members, so that only admins and higher can use it.
 A default setting for all rooms can be set in the config file. This can be overwritten per room.
 With this module loaded, unaffiliated users won't ever be allowed to use *Attention*.
@@ -26,8 +26,8 @@
 
 ## Settings
 
-A default setting can be provided in the config file, **defaults to true**
-A loglevel can be set (debug, info, warn, error)
+A default setting can be provided in the config file, defaults to *true*.
+A loglevel can be set (debug, info, warn, error).
 Defaults to *debug*: 
 
 ``` {.lua}
--- a/mod_muc_restrict_attention/mod_muc_restrict_attention.lua	Wed Mar 11 00:42:57 2026 +0100
+++ b/mod_muc_restrict_attention/mod_muc_restrict_attention.lua	Wed Mar 11 08:55:15 2026 +0100
@@ -3,15 +3,15 @@
 local from_affiliation
 local from_jid
 local room_jid
-local restrict_by_default = module:get_option_boolean("muc_restrict_attention_from_members", true)
+local restrict_members_by_default = module:get_option_boolean("muc_restrict_attention_from_members", true)
 local loglevel = module:get_option_enum("muc_restrict_attention_loglevel", "debug", "info", "warn", "error")
 
-local function should_restrict_attention(room)
-	local restrict_attention = room._data.restrict_attention
-	if restrict_attention == nil then
-		restrict_attention = restrict_by_default
+local function should_restrict_members(room)
+	local restrict_members = room._data.restrict_members
+	if restrict_members == nil then
+		restrict_members = restrict_members_by_default
 	end
-	return restrict_attention
+	return restrict_members
 end
 
 module:hook("muc-config-form", function(event)
@@ -20,18 +20,18 @@
 		name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention",
 		type = "boolean",
 		label = 'Allow "XEP-0224: Attention" from members',
-		value = not should_restrict_attention(room),
+		value = not should_restrict_members(room),
 	})
 end)
 
 module:hook("muc-config-submitted", function(event)
 	local room, fields, changed = event.room, event.fields, event.changed
-	local new_restrict_attention = not fields["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"]
-	if new_restrict_attention ~= should_restrict_attention(room) then
-		if new_restrict_attention == restrict_by_default then
-			room._data.restrict_attention = nil
+	local new_restrict_members = not fields["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"]
+	if new_restrict_members ~= should_restrict_members(room) then
+		if new_restrict_members == restrict_members_by_default then
+			room._data.restrict_members = nil
 		else
-			room._data.restrict_attention = new_restrict_attention
+			room._data.restrict_members = new_restrict_members
 		end
 		if type(changed) == "table" then
 			changed["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = true
@@ -43,7 +43,7 @@
 
 module:hook("muc-disco#info", function (event)
 	local room, form, formdata = event.room, event.form, event.formdata
-	local allow_members_attention = not should_restrict_attention(room)
+	local allow_members_attention = not should_restrict_members(room)
 	table.insert(form, {
 		name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention",
 		type = "boolean",
@@ -63,12 +63,12 @@
 module:hook("muc-occupant-groupchat", function (event)
 	local stanza = event.stanza
 	from_affiliation = event.room:get_affiliation(stanza.attr.from) 
-	if stanza.attr.type ~= "groupchat" then return; end 
-	if from_affiliation == "admin"
+	if stanza.attr.type ~= "groupchat"
+	or from_affiliation == "admin"
 	or from_affiliation == "owner" then
 		return
 	end
-	if should_restrict_attention(event.room)
+	if should_restrict_members(event.room)
 	or not from_affiliation then
 		room_jid = event.room.jid
 		from_jid = event.stanza.attr.from