Comparison

mod_muc_anonymize_moderation_actions/mod_muc_anonymize_moderation_actions.lua @ 5969:d58e4c70feb2

mod_muc_anonymize_moderation_actions: first commit.
author John Livingston <git@john-livingston.fr>
date Fri, 26 Jul 2024 17:07:05 +0200
child 5973:a316fee71bed
comparison
equal deleted inserted replaced
5968:83787415fc8d 5969:d58e4c70feb2
1 -- mod_muc_anonymize_moderation_actions
2 --
3 -- SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
4 -- SPDX-License-Identifier: AGPL-3.0-only
5
6 -- form_position: the position in the room config form (this value will be passed as priority for the "muc-config-form" hook).
7 -- By default, field will be between muc#roomconfig_changesubject and muc#roomconfig_moderatedroom
8 local form_position = module:get_option_number("anonymize_moderation_actions_form_position") or 80-2;
9
10 local function get_anonymize_moderation_actions(room)
11 return room._data.anonymize_moderation_actions or false;
12 end
13
14 local function set_anonymize_moderation_actions(room, anonymize_moderation_actions)
15 anonymize_moderation_actions = anonymize_moderation_actions and true or nil;
16 if get_anonymize_moderation_actions(room) == anonymize_moderation_actions then return false; end
17 room._data.anonymize_moderation_actions = anonymize_moderation_actions;
18 return true;
19 end
20
21 -- Config form declaration
22 local function add_form_option(event)
23 table.insert(event.form, {
24 name = "muc#roomconfig_anonymize_moderation_actions";
25 type = "boolean";
26 label = "Anonymize moderation actions";
27 desc = "When this is enabled, moderation actions will be anonymized, to avoid disclosing who is banning/kicking/… occupants.";
28 value = get_anonymize_moderation_actions(event.room);
29 });
30 end
31
32 local function config_submitted(event)
33 set_anonymize_moderation_actions(event.room, event.value);
34 end
35
36 local function remove_actor(event)
37 if (event.room and get_anonymize_moderation_actions(event.room)) then
38 event.actor = nil;
39 end
40 end
41
42 module:hook("muc-config-submitted/muc#roomconfig_anonymize_moderation_actions", config_submitted);
43 module:hook("muc-config-form", add_form_option, form_position);
44 module:hook("muc-broadcast-presence", remove_actor);