Mercurial > prosody-modules
annotate mod_muc_restrict_attention/mod_muc_restrict_attention.lua @ 6517:3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
| author | Menel <menel@snikket.de> |
|---|---|
| date | Thu, 16 Apr 2026 12:02:18 +0200 |
| parents | 054691d29c25 |
| children | b66c93276534 |
| rev | line source |
|---|---|
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
1 module:depends"muc" |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
2 |
|
6434
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
3 local from_affiliation |
|
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
4 local from_jid |
|
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
5 local room_jid |
|
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
6 local loglevel = module:get_option_enum("muc_restrict_attention_loglevel", "debug", "info", "warn", "error") |
|
6517
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
7 local restrict_by_default = module:get_option_enum("muc_restrict_attention_by_default", "members", "participants", false, "false") |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
8 |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
9 -- ugly hack, improve it when you do for the room config option too |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
10 if restrict_by_default == "members" then |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
11 local restrict_members_by_default = true |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
12 local restrict_participants_by_default = true |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
13 elseif restrict_by_default == false |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
14 or restrict_by_default == "false" then |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
15 local restrict_members_by_default = false |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
16 local restrict_participants_by_default = false |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
17 elseif restrict_by_default == "participants" then |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
18 local restrict_members_by_default = false |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
19 local restrict_participants_by_default = true |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
20 end |
|
6434
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
21 |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
22 local function should_restrict_members(room) |
|
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
23 local restrict_members = room._data.restrict_members |
|
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
24 if restrict_members == nil then |
|
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
25 restrict_members = restrict_members_by_default |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
26 end |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
27 return restrict_members |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
28 end |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
29 |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
30 module:hook("muc-config-form", function(event) |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
31 local room, form = event.room, event.form |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
32 table.insert(form, { |
|
6429
66d7da6a9032
mod_muc_restrict_attention: change variable names to fit the new logic to allow restricting members. Adhere to stylesheet.
Menel <menel@snikket.de>
parents:
6428
diff
changeset
|
33 name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention", |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
34 type = "boolean", |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
35 label = 'Allow "XEP-0224: Attention" from members', |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
36 value = not should_restrict_members(room), |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
37 }) |
|
6447
46fe8e3bf870
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: Put the form in the right Place
Menel <menel@snikket.de>
parents:
6446
diff
changeset
|
38 end, 80-7) |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
39 |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
40 module:hook("muc-config-submitted", function(event) |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
41 local room, fields, changed = event.room, event.fields, event.changed |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
42 local new_restrict_members = not fields["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] |
|
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
43 if new_restrict_members ~= should_restrict_members(room) then |
|
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
44 if new_restrict_members == restrict_members_by_default then |
|
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
45 room._data.restrict_members = nil |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
46 else |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
47 room._data.restrict_members = new_restrict_members |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
48 end |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
49 if type(changed) == "table" then |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
50 changed["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = true |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
51 else |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
52 event.changed = true |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
53 end |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
54 end |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
55 end) |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
56 |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
57 module:hook("muc-disco#info", function (event) |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
58 local room, form, formdata = event.room, event.form, event.formdata |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
59 local allow_members_attention = not should_restrict_members(room) |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
60 table.insert(form, { |
|
6429
66d7da6a9032
mod_muc_restrict_attention: change variable names to fit the new logic to allow restricting members. Adhere to stylesheet.
Menel <menel@snikket.de>
parents:
6428
diff
changeset
|
61 name = "{xmpp:prosody.im}muc#roomconfig_allow_members_attention", |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
62 type = "boolean", |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
63 }) |
|
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
64 formdata["{xmpp:prosody.im}muc#roomconfig_allow_members_attention"] = allow_members_attention |
|
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
65 end) |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
66 |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
67 local function filter_attention_tags(tag) |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
68 local xmlns = tag.attr.xmlns |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
69 if xmlns == "urn:xmpp:attention:0" then |
|
6434
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
70 module:log(loglevel, "Stripped \"Attention\" from %q, affiliation: %q in %q", from_jid, from_affiliation, room_jid) |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
71 return nil |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
72 end |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
73 return tag |
|
6423
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
74 end |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
75 |
|
d748985de48f
mod_muc_restrict_attention: New Module based on mod_muc_restrict_media to strip Attention. Untested.
Menel <menel@snikket.de>
parents:
diff
changeset
|
76 module:hook("muc-occupant-groupchat", function (event) |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
77 local stanza = event.stanza |
|
6449
054691d29c25
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: fix trailing newline
Menel <menel@snikket.de>
parents:
6447
diff
changeset
|
78 from_affiliation = event.room:get_affiliation(stanza.attr.from) |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
79 if stanza.attr.type ~= "groupchat" |
|
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
80 or from_affiliation == "admin" |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
81 or from_affiliation == "owner" then |
|
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.
Menel <menel@snikket.de>
parents:
6423
diff
changeset
|
82 return |
|
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.
Menel <menel@snikket.de>
parents:
6423
diff
changeset
|
83 end |
|
6446
63ce1af4d099
mod_muc_restrict_attention: adjusted more variable names to reflect it works on members
Menel <menel@snikket.de>
parents:
6434
diff
changeset
|
84 if should_restrict_members(event.room) |
|
6517
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
85 or restrict_participants_by_default |
|
3d14a407307d
mod_muc_restrict_attention: Add default option for participants. Breaking change config option name.
Menel <menel@snikket.de>
parents:
6449
diff
changeset
|
86 and not from_affiliation then |
|
6434
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
87 room_jid = event.room.jid |
|
1932fd38d353
mod_muc_restrict_attention: logging configurable and to debug by default.
Menel <menel@snikket.de>
parents:
6432
diff
changeset
|
88 from_jid = event.stanza.attr.from |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
89 stanza:maptags(filter_attention_tags) |
|
6429
66d7da6a9032
mod_muc_restrict_attention: change variable names to fit the new logic to allow restricting members. Adhere to stylesheet.
Menel <menel@snikket.de>
parents:
6428
diff
changeset
|
90 end |
|
6432
af8577933ddf
mod_muc_restrict_attention/mod_muc_restrict_attention.lua: cleanup code and logging
Menel <menel@snikket.de>
parents:
6429
diff
changeset
|
91 end, 9) --unsure what priority is sensible |
