annotate mod_muc_anonymize_moderation_actions/mod_muc_anonymize_moderation_actions.lua @ 5945:a316fee71bed

mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
author John Livingston <git@john-livingston.fr>
date Mon, 29 Jul 2024 13:11:43 +0200
parents d58e4c70feb2
children bfb8d7b53954
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
5945
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
42 local function remove_moderate_actor(event)
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
43 local room, announcement, tombstone = event.room, event.announcement, event.tombstone;
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
44 if not get_anonymize_moderation_actions(room) then
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
45 return;
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
46 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
47
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
48 local moderated = announcement:find("{urn:xmpp:fasten:0}apply-to/{urn:xmpp:message-moderate:0}moderated");
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
49 if moderated then
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
50 module:log("debug", "We must anonymize the moderation announcement for stanza %s", event.stanza_id);
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
51 moderated.attr.by = nil;
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
52 moderated:remove_children("occupant-id", "urn:xmpp:occupant-id:0");
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
53 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
54
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
55 if tombstone then
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
56 local moderated = tombstone:get_child("moderated", "urn:xmpp:message-moderate:0");
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
57 if moderated then
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
58 module:log("debug", "We must anonymize the moderation tombstone for stanza %s", event.stanza_id);
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
59 moderated.attr.by = nil;
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
60 moderated:remove_children("occupant-id", "urn:xmpp:occupant-id:0");
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
61 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
62 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
63 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
64
5941
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
65 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
66 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
67 module:hook("muc-broadcast-presence", remove_actor);
5945
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
68 module:hook("muc-moderate-message", remove_moderate_actor);