annotate mod_muc_anonymize_moderation_actions/mod_muc_anonymize_moderation_actions.lua @ 5946:bfb8d7b53954

mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
author John Livingston <git@john-livingston.fr>
date Mon, 29 Jul 2024 13:26:55 +0200
parents a316fee71bed
children
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);
5946
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
51 -- FIXME: XEP-0245 has changed.
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
52 -- urn:xmpp:message-moderate:0 requires a "by" attribute
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
53 -- urn:xmpp:message-moderate:1 do not require the "by" attribute
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
54 -- So, for now, settings the room jid, as we only implement urn:xmpp:message-moderate:0.
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
55 moderated.attr.by = room.jid;
5945
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
56 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
57 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
58
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
59 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
60 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
61 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
62 module:log("debug", "We must anonymize the moderation tombstone for stanza %s", event.stanza_id);
5946
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
63 -- FIXME: XEP-0245 has changed.
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
64 -- urn:xmpp:message-moderate:0 requires a "by" attribute
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
65 -- urn:xmpp:message-moderate:1 do not require the "by" attribute
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
66 -- So, for now, settings the room jid, as we only implement urn:xmpp:message-moderate:0.
bfb8d7b53954 mod_muc_anonymize_moderation_actions: fix XEP-0425 v0.2.1 compliance.
John Livingston <git@john-livingston.fr>
parents: 5945
diff changeset
67 moderated.attr.by = room.jid;
5945
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
68 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
69 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
70 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
71 end
a316fee71bed mod_muc_anonymize_moderation_actions: anonymize muc moderation announcements and tombstones.
John Livingston <git@john-livingston.fr>
parents: 5941
diff changeset
72
5941
d58e4c70feb2 mod_muc_anonymize_moderation_actions: first commit.
John Livingston <git@john-livingston.fr>
parents:
diff changeset
73 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
74 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
75 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
76 module:hook("muc-moderate-message", remove_moderate_actor);