Mercurial > prosody-modules
annotate mod_muc_activity/mod_muc_activity.lua @ 6214:cc5c0f1dc89b
mod_muc_anonymize_moderation_actions: Fix mentioning Virtualhost for MUC, Compatibility section and License.
diff --git a/mod_muc_anonymize_moderation_actions/README.md b/mod_muc_anonymize_moderation_actions/README.md
--- a/mod_muc_anonymize_moderation_actions/README.md
+++ b/mod_muc_anonymize_moderation_actions/README.md
@@ -1,8 +1,10 @@
-<!--
-SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
-SPDX-License-Identifier: AGPL-3.0-only
--->
-# mod_muc_anonymize_moderation_actions
+---
+labels:
+- 'Stage-Alpha'
+summary: Anonymize moderator actions for participants
+---
+
+## Introduction
This modules allows to anonymize affiliation and role changes in MUC rooms.
@@ -11,13 +13,10 @@ When the feature is enabled, when a mode
This is particularly usefull to prevent some revenge when a moderator bans someone.
-This module is under AGPL-3.0 license.
-
-It was tested on Prosody 0.12.x.
## Configuration
-Just enable the module on your MUC VirtualHost.
+Just enable the module on your MUC Component.
The feature will be accessible throught the room configuration form.
You can tweak the position of the settings in the MUC configuration form using `anonymize_moderation_actions_form_position`.
@@ -26,7 +25,20 @@ This value will be passed as priority fo
By default, the field will be between muc#roomconfig_changesubject and muc#roomconfig_moderatedroom (default value is `78`).
``` lua
-VirtualHost "muc.example.com"
+Component "muc.example.com" "muc"
modules_enabled = { "muc_anonymize_moderation_actions" }
anonymize_moderation_actions_form_position = 96
```
+
+## Compatibility
+
+ ------ ----------------------
+ trunk Works as of 25-05-12
+ 0.13 Works
+ 0.12 Works
+ ------ ----------------------
+
+### License
+
+SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
+SPDX-License-Identifier: AGPL-3.0-only
| author | Menel <menel@snikket.de> |
|---|---|
| date | Mon, 12 May 2025 10:42:26 +0200 |
| parents | a0429c322454 |
| children |
| rev | line source |
|---|---|
|
6105
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
1 local os_time = os.time; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
2 local math_floor = math.floor; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
3 local store = module:open_store("muc_activity", "keyval"); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
4 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
5 local accumulator = {}; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
6 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
7 local field_var = "{urn:xmpp:muc-activity}message-activity"; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
8 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
9 module:hook("muc-room-destroyed", function (event) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
10 local jid = event.room.jid; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
11 module:log("debug", "deleting activity data for destroyed muc %s", jid); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
12 store:set_keys(jid, {}); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
13 accumulator[jid] = nil; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
14 end) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
15 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
16 module:hook("muc-occupant-groupchat", function (event) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
17 local jid = event.room.jid; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
18 if not event.room:get_persistent() then |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
19 -- we do not count stanzas in non-persistent rooms |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
20 if accumulator[jid] then |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
21 -- if we have state for the room, drop it. |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
22 store:set_keys(jid, {}); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
23 accumulator[jid] = nil; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
24 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
25 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
26 return |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
27 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
28 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
29 if event.stanza:get_child("body") == nil then |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
30 -- we do not count stanzas without body. |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
31 return |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
32 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
33 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
34 module:log("debug", "counting stanza for MUC activity in %s", jid); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
35 accumulator[jid] = (accumulator[jid] or 0) + 1; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
36 end) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
37 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
38 local function shift(data) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
39 for i = 1, 23 do |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
40 data[i] = data[i+1] |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
41 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
42 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
43 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
44 local function accumulate(data) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
45 if data == nil then |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
46 return 0; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
47 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
48 local accum = 0; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
49 for i = 1, 24 do |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
50 local v = data[i]; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
51 if v ~= nil then |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
52 accum = accum + v |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
53 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
54 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
55 return accum; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
56 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
57 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
58 module:hourly("muc-activity-shift", function () |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
59 module:log("info", "shifting MUC activity store forward by one hour"); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
60 for jid in store:users() do |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
61 local data = store:get(jid); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
62 local new = accumulator[jid] or 0; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
63 shift(data); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
64 data[24] = new; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
65 accumulator[jid] = nil; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
66 store:set(jid, data); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
67 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
68 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
69 -- All remaining entries in the accumulator are non-existent in the store, |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
70 -- otherwise they would have been removed earlier. |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
71 for jid, count in pairs(accumulator) do |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
72 store:set(jid, { [24] = count }); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
73 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
74 accumulator = {}; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
75 end) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
76 |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
77 module:hook("muc-disco#info", function(event) |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
78 local room = event.room; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
79 local jid = room.jid; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
80 if not room:get_persistent() or not room:get_public() or room:get_members_only() or room:get_password() ~= nil then |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
81 module:log("debug", "%s is not persistent or not public, not injecting message activity", jid); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
82 return; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
83 end |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
84 local count = accumulate(store:get(jid)) / 24.0; |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
85 table.insert(event.form, { name = field_var, label = "Message activity" }); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
86 event.formdata[field_var] = tostring(count); |
|
a0429c322454
mod_muc_activity: create module
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
87 end); |
