# HG changeset patch # User Menel # Date 1773163430 -3600 # Node ID af8577933ddf2c3efdac1237aa3764d95fedd09b # Parent 459cb2c2789b4a12fd50d5a148e39f7ce7780251 mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging diff -r 459cb2c2789b -r af8577933ddf mod_muc_restrict_attention/mod_muc_restrict_attention.lua --- a/mod_muc_restrict_attention/mod_muc_restrict_attention.lua Tue Mar 10 16:58:17 2026 +0000 +++ b/mod_muc_restrict_attention/mod_muc_restrict_attention.lua Tue Mar 10 18:23:50 2026 +0100 @@ -1,69 +1,71 @@ -module:depends"muc"; +module:depends"muc" -local restrict_by_default = module:get_option_boolean("muc_restrict_attention_from_members", true); - +local restrict_by_default = module:get_option_boolean("muc_restrict_attention_from_members", true) +local from_affiliation --need it at the end local function should_restrict_attention(room) - local restrict_attention = room._data.restrict_attention; - if restrict_attention == nil then - restrict_attention = restrict_by_default; - end - return restrict_attention; + local restrict_attention = room._data.restrict_attention + 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; + local room, form = event.room, event.form table.insert(form, { name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention", type = "boolean", - label = "Allow \"XEP-0224: Attention\" from members", + label = 'Allow "XEP-0224: Attention" from members', value = not should_restrict_attention(room), - }); -end); + }) +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"]; + 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; + room._data.restrict_attention = nil else - room._data.restrict_attention = new_restrict_attention; + room._data.restrict_attention = new_restrict_attention end if type(changed) == "table" then - changed["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = true; + changed["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = true else - event.changed = true; + event.changed = true end end -end); +end) 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 room, form, formdata = event.room, event.form, event.formdata + local allow_members_attention = not should_restrict_attention(room) table.insert(form, { name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention", type = "boolean", - }); - formdata["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = allow_members_attention; -end); + }) + formdata["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = allow_members_attention +end) local function filter_attention_tags(tag) - local xmlns = tag.attr.xmlns; + local xmlns = tag.attr.xmlns if xmlns == "urn:xmpp:attention:0" then - return nil; + module:log("info", "Stripped \"Attention\" from a message, affiliation: %s", from_affiliation) + return nil end - return tag; + return tag end module:hook("muc-occupant-groupchat", function (event) - 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 + local stanza = event.stanza + from_affiliation = event.room:get_affiliation(stanza.attr.from) + if stanza.attr.type ~= "groupchat" then return; end -- return since not relevant stanza + if from_affiliation == "admin" + or from_affiliation == "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); + or not from_affiliation then + stanza:maptags(filter_attention_tags) end -end, 9); +end, 9) --unsure what priority is sensible