Mercurial > prosody-modules
changeset 6429:66d7da6a9032
mod_muc_restrict_attention: change variable names to fit the new logic to allow restricting members. Adhere to stylesheet.
| author | Menel <menel@snikket.de> |
|---|---|
| date | Tue, 10 Mar 2026 15:38:39 +0100 |
| parents | 23e3edb6f9ea |
| children | cf5f0a20e16a |
| files | mod_muc_restrict_attention/README.md mod_muc_restrict_attention/mod_muc_restrict_attention.lua |
| diffstat | 2 files changed, 17 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_muc_restrict_attention/README.md Tue Mar 10 14:24:07 2026 +0100 +++ b/mod_muc_restrict_attention/README.md Tue Mar 10 15:38:39 2026 +0100 @@ -6,9 +6,10 @@ # Introduction -This module adds a room configuration option to strip XEP-0224 Attention from -members in MUCs,so that only admins and higher can use it. -It will **always** strip it from unaffiliated users in MUCs. +This module strips *XEP-0224 Attention* 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*. This can prevent spam and noise in clients that don't have precautions against this in place. @@ -25,7 +26,7 @@ ## Settings -A default setting can be provided in the config file, defaults to true: +A default setting can be provided in the config file, **defaults to true**: ``` {.lua} muc_restrict_attention_from_members = true
--- a/mod_muc_restrict_attention/mod_muc_restrict_attention.lua Tue Mar 10 14:24:07 2026 +0100 +++ b/mod_muc_restrict_attention/mod_muc_restrict_attention.lua Tue Mar 10 15:38:39 2026 +0100 @@ -4,16 +4,16 @@ local function should_restrict_attention(room) local restrict_attention = room._data.restrict_attention; - if restrict_attention == nil then - restrict_attention = restrict_by_default; - end + if restrict_attention == nil then + restrict_attention = restrict_by_default; + end return restrict_attention; end module:hook("muc-config-form", function(event) local room, form = event.room, event.form; table.insert(form, { - name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_attention", + name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention", type = "boolean", label = "Allow \"XEP-0224: Attention\" from members", value = not should_restrict_attention(room), @@ -22,7 +22,7 @@ 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_unaffiliated_attention"]; + 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; @@ -30,7 +30,7 @@ room._data.restrict_attention = new_restrict_attention; end if type(changed) == "table" then - changed["{xmpp:prosody.im}muc#roomconfig_unaffiliated_attention"] = true; + changed["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = true; else event.changed = true; end @@ -39,13 +39,12 @@ module:hook("muc-disco#info", function (event) local room, form, formdata = event.room, event.form, event.formdata; - - local allow_unaffiliated_attention = not should_restrict_attention(room); + local allow_members_attention = not should_restrict_attention(room); table.insert(form, { - name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_attention", + name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention", type = "boolean", }); - formdata["{xmpp:prosody.im}muc#roomconfig_unaffiliated_attention"] = allow_unaffiliated_attention; + formdata["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = allow_members_attention; end); local function filter_attention_tags(tag) @@ -60,11 +59,11 @@ local stanza = event.stanza; 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 + 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 + or not event.room:get_affiliation(stanza.attr.from) then stanza:maptags(filter_attention_tags); - end + end end, 9);
