annotate mod_muc_anonymize_moderation_actions/mod_muc_anonymize_moderation_actions.lua @ 5942:5ccc03c33158

mod_muc_moderation: Fix a regression. Actor occupant-id was not added under the moderated tag, but at the top level.
author John Livingston <git@john-livingston.fr>
date Fri, 26 Jul 2024 18:22:30 +0200
parents d58e4c70feb2
children a316fee71bed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5941
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
1 -- mod_muc_anonymize_moderation_actions
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
2 --
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
3 -- SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
4 -- SPDX-License-Identifier: AGPL-3.0-only
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
5
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
6 -- form_position: the position in the room config form (this value will be passed as priority for the "muc-config-form" hook).
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
7 -- By default, field will be between muc#roomconfig_changesubject and muc#roomconfig_moderatedroom
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
8 local form_position = module:get_option_number("anonymize_moderation_actions_form_position") or 80-2;
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
9
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
10 local function get_anonymize_moderation_actions(room)
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
11 return room._data.anonymize_moderation_actions or false;
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
12 end
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
13
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
14 local function set_anonymize_moderation_actions(room, anonymize_moderation_actions)
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
15 anonymize_moderation_actions = anonymize_moderation_actions and true or nil;
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
16 if get_anonymize_moderation_actions(room) == anonymize_moderation_actions then return false; end
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
17 room._data.anonymize_moderation_actions = anonymize_moderation_actions;
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
18 return true;
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
19 end
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
20
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
21 -- Config form declaration
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
22 local function add_form_option(event)
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
23 table.insert(event.form, {
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
24 name = "muc#roomconfig_anonymize_moderation_actions";
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
25 type = "boolean";
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
26 label = "Anonymize moderation actions";
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
27 desc = "When this is enabled, moderation actions will be anonymized, to avoid disclosing who is banning/kicking/… occupants.";
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
28 value = get_anonymize_moderation_actions(event.room);
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
29 });
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
30 end
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
31
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
32 local function config_submitted(event)
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
33 set_anonymize_moderation_actions(event.room, event.value);
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
34 end
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
35
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
36 local function remove_actor(event)
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
37 if (event.room and get_anonymize_moderation_actions(event.room)) then
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
38 event.actor = nil;
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
39 end
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
40 end
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
41
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
42 module:hook("muc-config-submitted/muc#roomconfig_anonymize_moderation_actions", config_submitted);
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
43 module:hook("muc-config-form", add_form_option, form_position);
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
44 module:hook("muc-broadcast-presence", remove_actor);