diff --git a/CHANGELOG.md b/CHANGELOG.md index bc6cd734..f7c5903f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## 8.3.0 (Not Released Yet) +### New features + +* Slow mode (#192): + * new option in room configuration to set the slow mode delay (new prosody module mod_muc_slow_mode). + ### Minor changes and fixes * Fix ConverseJS build: translations were missing, and only english was available. diff --git a/prosody-modules/mod_muc_slow_mode/README.md b/prosody-modules/mod_muc_slow_mode/README.md new file mode 100644 index 00000000..7705824b --- /dev/null +++ b/prosody-modules/mod_muc_slow_mode/README.md @@ -0,0 +1,7 @@ +# mod_muc_slow_mode + +This module is a custom module that allows slow mode for MUC rooms. + +This module is part of peertube-plugin-livechat, and is under the same LICENSE. + +There will probably be a XEP proposal for this module behaviour. When done, this module will be published in the prosody-modules repository. diff --git a/prosody-modules/mod_muc_slow_mode/mod_muc_slow_mode.lua b/prosody-modules/mod_muc_slow_mode/mod_muc_slow_mode.lua new file mode 100644 index 00000000..7471a510 --- /dev/null +++ b/prosody-modules/mod_muc_slow_mode/mod_muc_slow_mode.lua @@ -0,0 +1,62 @@ +-- mod_muc_slow_mode +-- +-- Copyright (C) 2024 John Livingston +-- +-- This file is AGPL-v3 licensed. +-- Please see the Peertube livechat plugin copyright information. +-- https://livingston.frama.io/peertube-plugin-livechat/credits/ +-- +-- Implements: XEP-????: MUC Slow Mode (XEP to come). +-- +-- Imports + +-- Plugin dependencies +local mod_muc = module:depends "muc"; + +-- Getter/Setter +local function get_slow_mode_delay(room) + return room._data.slow_mode_delay or 0; +end + +local function set_slow_mode_delay(room, delay) + if delay then + delay = assert(tonumber(delay), "Slow mode delay is not a valid number"); + end + if delay and delay < 0 then + delay = 0; + end + room._data.slow_mode_delay = delay; + return true; +end + +-- Discovering support +local function add_disco_form(event) + table.insert(event.room, { + name = "muc#roomconfig_slow_mode_delay"; + value = ""; + }); + event.formdata["muc#roomconfig_slow_mode_delay"] = get_slow_mode_delay(event.room); +end + +module:hook("mub-disco#info", add_disco_form); + +-- Config form declaration +local function add_form_option(event) + table.insert(event.form, { + name = "muc#roomconfig_slow_mode_delay"; + type = "text-single"; + datatype = "xs:integer"; + label = "Slow Mode (0=disabled, any positive integer= minimal delay in seconds between two messages from the same user)"; + desc = "Minimal delay, in seconds, between two messages for the same user in the room. If value is set to 0, the slow mode is not active."; + value = get_slow_mode_delay(event.room); + }); +end + +module:hook("muc-config-submitted/muc#roomconfig_slow_mode_delay", function(event) + if set_slow_mode_delay(event.room, event.value) then + -- status 104 = configuration change: Inform occupants that a non-privacy-related room configuration change has occurred + event.status_codes["104"] = true; + end +end); + +module:hook("muc-config-form", add_form_option, 100-4); diff --git a/server/lib/prosody/config/content.ts b/server/lib/prosody/config/content.ts index 5acc5ecf..60a134ba 100644 --- a/server/lib/prosody/config/content.ts +++ b/server/lib/prosody/config/content.ts @@ -205,6 +205,8 @@ class ProsodyConfigContent { this.muc.set('muc_room_default_public_jids', false) this.muc.set('muc_room_default_change_subject', false) this.muc.set('muc_room_default_history_length', 20) + + this.muc.add('modules_enabled', 'muc_slow_mode') } useAnonymous (autoBanIP: boolean): void {