From 7a545949670642243aafac792c7421cfa3e0886c Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 9 Jul 2024 16:15:07 +0200 Subject: [PATCH] Moderation delay WIP (#132): * default channel value for moderation delay --- CHANGELOG.md | 2 +- client/@types/global.d.ts | 3 ++ .../templates/channel-configuration.ts | 35 +++++++++++++++++++ .../configuration/services/channel-details.ts | 14 ++++++++ languages/en.yml | 8 +++++ ...mod_http_peertubelivechat_manage_rooms.lua | 5 +++ .../mod_muc_http_defaults.lua | 8 ++++- server/lib/configuration/channel/sanitize.ts | 6 ++++ server/lib/configuration/channel/storage.ts | 3 ++ server/lib/prosody/api/manage-rooms.ts | 4 +++ server/lib/routers/api/room.ts | 4 ++- shared/lib/types.ts | 3 ++ 12 files changed, 92 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea344e6b..68887ddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## ??? (Not Released Yet) +## 10.3.0 (Not Released Yet) ### Minor changes and fixes diff --git a/client/@types/global.d.ts b/client/@types/global.d.ts index 890ad8ab..ecc2d9be 100644 --- a/client/@types/global.d.ts +++ b/client/@types/global.d.ts @@ -130,3 +130,6 @@ declare const LOC_TOKEN_DEFAULT_LABEL: string declare const LOC_TOKEN_ACTION_REVOKE_CONFIRM: string declare const LOC_POLL_VOTE_OK: string + +declare const LOC_MODERATION_DELAY: string +declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_MODERATION_DELAY_DESC: string diff --git a/client/common/configuration/elements/templates/channel-configuration.ts b/client/common/configuration/elements/templates/channel-configuration.ts index 23dcee40..69878f95 100644 --- a/client/common/configuration/elements/templates/channel-configuration.ts +++ b/client/common/configuration/elements/templates/channel-configuration.ts @@ -219,6 +219,41 @@ export function tplChannelConfiguration (el: ChannelConfigurationElement): Templ ${el.renderFeedback('peertube-livechat-slowmode-duration-feedback', 'slowMode.duration')} + + +
+ + ${el.renderFeedback('peertube-livechat-moderation-delay-feedback', 'moderation.delay')} +
+ 60 + ) { + propertiesError['moderation.delay'].push(ValidationErrorType.NotInRange) + } + // If !bot.enabled, we don't have to validate these fields: // The backend will ignore those values. if (botConf.enabled) { diff --git a/languages/en.yml b/languages/en.yml index 08e9aaab..0b0b3083 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -579,3 +579,11 @@ poll_is_over: This poll is now over. poll_choice_invalid: This choice is not valid. poll_anonymous_vote_ok: Your vote is taken into account. Votes are anonymous, they will not be shown to other participants. poll_vote_ok: Your vote has been taking into account, the counters will be updated in a moment. + +moderation_delay: Moderation delay +livechat_configuration_channel_moderation_delay_desc: | + Moderation delay default value: + diff --git a/prosody-modules/mod_http_peertubelivechat_manage_rooms/mod_http_peertubelivechat_manage_rooms.lua b/prosody-modules/mod_http_peertubelivechat_manage_rooms/mod_http_peertubelivechat_manage_rooms.lua index ae3f1e18..86eeae15 100644 --- a/prosody-modules/mod_http_peertubelivechat_manage_rooms/mod_http_peertubelivechat_manage_rooms.lua +++ b/prosody-modules/mod_http_peertubelivechat_manage_rooms/mod_http_peertubelivechat_manage_rooms.lua @@ -97,6 +97,11 @@ local function update_room(event) must104 = true; end end + if type(config.moderation_delay) == "number" then + if room._data.moderation_delay ~= config.moderation_delay then + room._data.moderation_delay = config.moderation_delay; + end + end if (type(config.livechat_muc_terms) == "string") then -- to easily detect if the value is given or not, we consider that the caller passes "" when terms must be deleted. if set_muc_terms then diff --git a/prosody-modules/mod_muc_http_defaults/mod_muc_http_defaults.lua b/prosody-modules/mod_muc_http_defaults/mod_muc_http_defaults.lua index cbb94992..1a217671 100644 --- a/prosody-modules/mod_muc_http_defaults/mod_muc_http_defaults.lua +++ b/prosody-modules/mod_muc_http_defaults/mod_muc_http_defaults.lua @@ -7,10 +7,13 @@ -- This version contains a modification to take into account new config options: -- * "slow_mode_duration" -- * "mute_anonymous" +-- * "moderation_delay" -- These options are introduced in the Peertube livechat plugin. -- -- The "slow_mode_duration" comes with mod_muc_slow_mode. -- There will be a XEP proposal for this one. When done, these modifications will be submitted to the mod_muc_http_defaults maintainer. +-- +-- The "moderation_delay" comes with mod_muc_moderation_delay -- local http = require "net.http"; @@ -116,7 +119,10 @@ local function apply_config(room, settings) -- specific to peertube-plugin-livechat: if (type(config.slow_mode_duration) == "number") and config.slow_mode_duration >= 0 then - room._data.slow_mode_duration = config.slow_mode_duration; + room._data.slow_mode_duration = config.slow_mode_duration; + end + if (type(config.moderation_delay) == "number") and config.moderation_delay >= 0 then + room._data.moderation_delay = config.moderation_delay; end if (type(config.mute_anonymous) == "boolean") then room._data.x_peertubelivechat_mute_anonymous = config.mute_anonymous; diff --git a/server/lib/configuration/channel/sanitize.ts b/server/lib/configuration/channel/sanitize.ts index 1167263f..3aa45480 100644 --- a/server/lib/configuration/channel/sanitize.ts +++ b/server/lib/configuration/channel/sanitize.ts @@ -36,6 +36,9 @@ async function sanitizeChannelConfigurationOptions ( throw new Error('Invalid data.slowMode data type') } + const moderationData = data.moderation ?? {} // comes with livechat 10.3.0 + moderationData.delay ??= 0 + // mute not present in livechat <= 10.2.0 const mute = data.mute ?? {} mute.anonymous ??= false @@ -68,6 +71,9 @@ async function sanitizeChannelConfigurationOptions ( }, mute: { anonymous: _readBoolean(mute, 'anonymous') + }, + moderation: { + delay: _readInteger(moderationData, 'delay', 0, 60) } } if (terms !== undefined) { diff --git a/server/lib/configuration/channel/storage.ts b/server/lib/configuration/channel/storage.ts index 1c6c4ce3..d5dbdf90 100644 --- a/server/lib/configuration/channel/storage.ts +++ b/server/lib/configuration/channel/storage.ts @@ -53,6 +53,9 @@ function getDefaultChannelConfigurationOptions (_options: RegisterServerOptions) mute: { anonymous: false }, + moderation: { + delay: 0 + }, terms: undefined } } diff --git a/server/lib/prosody/api/manage-rooms.ts b/server/lib/prosody/api/manage-rooms.ts index 61e65bd8..064608d5 100644 --- a/server/lib/prosody/api/manage-rooms.ts +++ b/server/lib/prosody/api/manage-rooms.ts @@ -64,6 +64,7 @@ async function updateProsodyRoom ( data: { name?: string slow_mode_duration?: number + moderation_delay?: number livechat_muc_terms?: string addAffiliations?: Affiliations removeAffiliationsFor?: string[] @@ -93,6 +94,9 @@ async function updateProsodyRoom ( if (('slow_mode_duration' in data) && data.slow_mode_duration !== undefined) { apiData.slow_mode_duration = data.slow_mode_duration } + if (('moderation_delay' in data) && data.moderation_delay !== undefined) { + apiData.moderation_delay = data.moderation_delay + } if ('livechat_muc_terms' in data) { apiData.livechat_muc_terms = data.livechat_muc_terms ?? '' } diff --git a/server/lib/routers/api/room.ts b/server/lib/routers/api/room.ts index 11dc10a6..ec2d0da8 100644 --- a/server/lib/routers/api/room.ts +++ b/server/lib/routers/api/room.ts @@ -38,6 +38,7 @@ interface RoomDefaults { slow_mode_duration?: number mute_anonymous?: boolean livechat_muc_terms?: string + moderation_delay?: number } affiliations?: Affiliations } @@ -52,7 +53,8 @@ async function _getChannelSpecificOptions ( return { slow_mode_duration: channelOptions.slowMode.duration, mute_anonymous: channelOptions.mute.anonymous, - livechat_muc_terms: channelOptions.terms + livechat_muc_terms: channelOptions.terms, + moderation_delay: channelOptions.moderation.delay } } diff --git a/shared/lib/types.ts b/shared/lib/types.ts index 20ff605e..a827efb7 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -107,6 +107,9 @@ interface ChannelConfigurationOptions { // nonFollowers: boolean (or a number of seconds?) } terms?: string // comes with Livechat 10.2.0 + moderation: { // comes with Livechat 10.3.0 + delay: number + } } interface ChannelForbiddenWords {