Mercurial > prosody-modules
changeset 6432:af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
| author | Menel <menel@snikket.de> |
|---|---|
| date | Tue, 10 Mar 2026 18:23:50 +0100 |
| parents | 459cb2c2789b |
| children | 9a89cb9810a7 |
| files | mod_muc_restrict_attention/mod_muc_restrict_attention.lua |
| diffstat | 1 files changed, 36 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- 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
