comparison mod_muc_moderation_delay/config.lib.lua @ 5938:959382fac20c

mod_muc_moderation_delay: first commit to prosody-modules.
author John Livingston <git@john-livingston.fr>
date Fri, 26 Jul 2024 15:36:05 +0200
parents
children
comparison
equal deleted inserted replaced
5937:da942a3f3660 5938:959382fac20c
1 -- SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
2 -- SPDX-License-Identifier: AGPL-3.0-only
3
4 -- Getter/Setter
5 local function get_moderation_delay(room)
6 return room._data.moderation_delay or nil;
7 end
8
9 local function set_moderation_delay(room, delay)
10 if delay == 0 then
11 delay = nil;
12 end
13 if delay ~= nil then
14 delay = assert(tonumber(delay), "Moderation delay is not a valid number");
15 if delay < 0 then
16 delay = nil;
17 end
18 end
19
20 if get_moderation_delay(room) == delay then return false; end
21
22 room._data.moderation_delay = delay;
23 return true;
24 end
25
26 -- Discovering support
27 local function add_disco_form(event)
28 table.insert(event.form, {
29 name = "muc#roominfo_moderation_delay";
30 value = "";
31 });
32 event.formdata["muc#roominfo_moderation_delay"] = get_moderation_delay(event.room);
33 end
34
35
36 -- Config form declaration
37 local function add_form_option(event)
38 table.insert(event.form, {
39 name = "muc#roomconfig_moderation_delay";
40 type = "text-single";
41 datatype = "xs:integer";
42 range_min = 0;
43 range_max = 60; -- do not allow too big values, it does not make sense.
44 label = "Moderation delay (0=disabled, any positive integer= messages will be delayed for X seconds for non-moderator participants.)";
45 -- desc = "";
46 value = get_moderation_delay(event.room);
47 });
48 end
49
50 local function config_submitted(event)
51 set_moderation_delay(event.room, event.value);
52 -- no need to 104 status, this feature is invisible for regular participants.
53 end
54
55 return {
56 set_moderation_delay = set_moderation_delay;
57 get_moderation_delay = get_moderation_delay;
58 add_disco_form = add_disco_form;
59 add_form_option = add_form_option;
60 config_submitted = config_submitted;
61 }