Slow mode WIP (#192):
* default delay is configurable in channel's chat rooms options.
This commit is contained in:
parent
ee71d3f729
commit
cf179d7f72
@ -6,6 +6,7 @@
|
||||
|
||||
* Slow mode (#192):
|
||||
* new option in room configuration to set the slow mode delay (new prosody module mod_muc_slow_mode).
|
||||
* default delay is configurable in channel's chat rooms options.
|
||||
|
||||
### Minor changes and fixes
|
||||
|
||||
|
2
client/@types/global.d.ts
vendored
2
client/@types/global.d.ts
vendored
@ -44,6 +44,8 @@ declare const LOC_LIVECHAT_CONFIGURATION_DESC: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_PLEASE_SELECT: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_DEFAULT_SLOW_MODE_LABEL: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_DEFAULT_SLOW_MODE_DESC: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL: string
|
||||
|
@ -9,6 +9,25 @@
|
||||
</h1>
|
||||
<p>{{description}}</p>
|
||||
<form livechat-configuration-channel-options role="form">
|
||||
<div class="row mt-3">
|
||||
<div class="col-12 col-lg-4 col-xl-3">
|
||||
<h2>{{defaultSlowModeLabel}}</h2>
|
||||
<p>{{{defaultSlowModeDesc}}}</p>
|
||||
</div>
|
||||
<div class="col-12 col-lg-8 col-xl-9">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<input
|
||||
type="number"
|
||||
name="slow_mode_default_delay"
|
||||
min="0"
|
||||
max="1000"
|
||||
id="peertube-livechat-slow-mode-default-delay"
|
||||
value="{{channelConfiguration.configuration.slowMode.defaultDelay}}"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col-12 col-lg-4 col-xl-3">
|
||||
<h2>{{botOptions}}</h2>
|
||||
|
@ -68,6 +68,10 @@ async function fillLabels (
|
||||
view.title = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE)
|
||||
view.description = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC)
|
||||
|
||||
view.defaultSlowModeLabel = await peertubeHelpers.translate(
|
||||
LOC_LIVECHAT_CONFIGURATION_CHANNEL_DEFAULT_SLOW_MODE_LABEL
|
||||
)
|
||||
view.defaultSlowModeDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DEFAULT_SLOW_MODE_DESC)
|
||||
view.enableBot = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL)
|
||||
view.botOptions = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE)
|
||||
view.forbiddenWords = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL)
|
||||
|
@ -165,8 +165,20 @@ async function vivifyConfigurationChannel (
|
||||
|
||||
const validateData: Function = async (channelConfigurationOptions: ChannelConfigurationOptions): Promise<boolean> => {
|
||||
const botConf = channelConfigurationOptions.bot
|
||||
const slowModeDefaultDelay = channelConfigurationOptions.slowMode.defaultDelay
|
||||
const errorFieldSelectors = []
|
||||
|
||||
if (
|
||||
(typeof slowModeDefaultDelay !== 'number') ||
|
||||
isNaN(slowModeDefaultDelay) ||
|
||||
slowModeDefaultDelay < 0 ||
|
||||
slowModeDefaultDelay > 1000
|
||||
) {
|
||||
const selector = '#peertube-livechat-slow-mode-default-delay'
|
||||
errorFieldSelectors.push(selector)
|
||||
await displayError(selector, await translate(LOC_INVALID_VALUE))
|
||||
}
|
||||
|
||||
// If !bot.enabled, we don't have to validate these fields:
|
||||
// The backend will ignore those values.
|
||||
if (botConf.enabled) {
|
||||
@ -220,6 +232,9 @@ async function vivifyConfigurationChannel (
|
||||
const data = new FormData(form)
|
||||
removeDisplayedErrors()
|
||||
const channelConfigurationOptions: ChannelConfigurationOptions = {
|
||||
slowMode: {
|
||||
defaultDelay: parseInt(data.get('slow_mode_default_delay')?.toString() ?? '0')
|
||||
},
|
||||
bot: {
|
||||
enabled: data.get('bot') === '1',
|
||||
nickname: data.get('bot_nickname')?.toString() ?? '',
|
||||
|
@ -331,6 +331,14 @@ livechat_configuration_desc: "Here you can configure some advanced options for c
|
||||
livechat_configuration_please_select: "Please select bellow one of your channel, to setup its chatting options."
|
||||
livechat_configuration_channel_title: "Channel options"
|
||||
livechat_configuration_channel_desc: "You can setup here some options for this channel (moderation policies, ...)."
|
||||
livechat_configuration_channel_default_slow_mode_label: "Slow mode"
|
||||
livechat_configuration_channel_default_slow_mode_desc: |
|
||||
Default slow mode value for new chats:
|
||||
<ul>
|
||||
<li>0: slow mode disabled</li>
|
||||
<li>Any positive integer: minimum time (in seconds) between two messages from the same user (moderators are not concerned)</li>
|
||||
</ul>
|
||||
This value applies for new chat rooms. To change this value for an already existing room, you have to use the room configuration menu.
|
||||
livechat_configuration_channel_enable_bot_label: "Enable moderation bot"
|
||||
livechat_configuration_channel_bot_options_title: "Moderation bot options"
|
||||
livechat_configuration_channel_forbidden_words_label: "Forbidden words or expressions"
|
||||
|
@ -1,8 +1,13 @@
|
||||
-- Copyright (C) 2021 Kim Alvefur
|
||||
-- Copyright (C) 2024 John Livingston
|
||||
--
|
||||
-- This file is MIT licensed. Please see the
|
||||
-- COPYING file in the source package for more information.
|
||||
--
|
||||
-- This version contains a modification to take into account new config option "slow_mode_delay".
|
||||
-- This option is introduced in the Peertube livechat plugin, by mod_muc_slow_mode.
|
||||
-- There will be a XEP proposal. When done, these modifications will be submitted to the mod_muc_http_defaults maintainer.
|
||||
--
|
||||
|
||||
local http = require "net.http";
|
||||
local async = require "util.async";
|
||||
@ -104,6 +109,11 @@ local function apply_config(room, settings)
|
||||
|
||||
-- mod_muc_mam
|
||||
if type(config.archiving) == "boolean" then room._config.archiving = config.archiving; end
|
||||
|
||||
-- specific to peertube-plugin-livechat:
|
||||
if (type(config.slow_mode_delay) == "number") and config.slow_mode_delay >= 0 then
|
||||
room._data.slow_mode_delay = config.slow_mode_delay;
|
||||
end
|
||||
elseif config ~= nil then
|
||||
module:log("error", "Invalid config returned from API for %s: %q", room.jid, config);
|
||||
return nil, "format", { field = "config" };
|
||||
|
@ -23,6 +23,11 @@ async function sanitizeChannelConfigurationOptions (
|
||||
throw new Error('Invalid data.bot data type')
|
||||
}
|
||||
|
||||
const slowModeData = data.slowMode ?? { defaultDelay: 0 } // not present in livechat <= 8.2.0
|
||||
if (typeof slowModeData !== 'object') {
|
||||
throw new Error('Invalid data.slowMode data type')
|
||||
}
|
||||
|
||||
const result: ChannelConfigurationOptions = {
|
||||
bot: {
|
||||
enabled: _readBoolean(botData, 'enabled'),
|
||||
@ -31,6 +36,9 @@ async function sanitizeChannelConfigurationOptions (
|
||||
quotes: _readQuotes(botData),
|
||||
commands: _readCommands(botData)
|
||||
// TODO: bannedJIDs
|
||||
},
|
||||
slowMode: {
|
||||
defaultDelay: _readInteger(slowModeData, 'defaultDelay', 0, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ async function getChannelConfigurationOptions (
|
||||
const logger = options.peertubeHelpers.logger
|
||||
const filePath = _getFilePath(options, channelId)
|
||||
if (!fs.existsSync(filePath)) {
|
||||
logger.debug('No stored data for channel, returning default values')
|
||||
logger.debug('No stored data for channel, returning null')
|
||||
return null
|
||||
}
|
||||
const content = await fs.promises.readFile(filePath, {
|
||||
@ -42,6 +42,9 @@ function getDefaultChannelConfigurationOptions (_options: RegisterServerOptions)
|
||||
forbiddenWords: [],
|
||||
quotes: [],
|
||||
commands: []
|
||||
},
|
||||
slowMode: {
|
||||
defaultDelay: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,10 @@ import { Affiliations, getVideoAffiliations, getChannelAffiliations } from '../.
|
||||
import { fillVideoCustomFields } from '../../custom-fields'
|
||||
import { getChannelInfosById } from '../../database/channel'
|
||||
import { RoomChannel } from '../../room-channel'
|
||||
import {
|
||||
getChannelConfigurationOptions,
|
||||
getDefaultChannelConfigurationOptions
|
||||
} from '../../configuration/channel/storage'
|
||||
|
||||
// See here for description: https://modules.prosody.im/mod_muc_http_defaults.html
|
||||
interface RoomDefaults {
|
||||
@ -25,10 +29,19 @@ interface RoomDefaults {
|
||||
// historylength: number
|
||||
moderated?: boolean
|
||||
archiving?: boolean
|
||||
|
||||
// Following fields are specific to livechat (for now), and requires a customized version for mod_muc_http_defaults.
|
||||
slow_mode_delay?: number
|
||||
}
|
||||
affiliations?: Affiliations
|
||||
}
|
||||
|
||||
async function defaultSlowModeDelay (options: RegisterServerOptions, channelId: number): Promise<number> {
|
||||
const channelOptions = await getChannelConfigurationOptions(options, channelId) ??
|
||||
getDefaultChannelConfigurationOptions(options)
|
||||
return channelOptions.slowMode.defaultDelay
|
||||
}
|
||||
|
||||
/**
|
||||
* Instanciate the route for room APIs.
|
||||
* These APIs are used by Prosody to get room defaults from the Peertube server.
|
||||
@ -74,8 +87,9 @@ async function initRoomApiRouter (options: RegisterServerOptions, router: Router
|
||||
const roomDefaults: RoomDefaults = {
|
||||
config: {
|
||||
name: channelInfos.displayName,
|
||||
description: ''
|
||||
description: '',
|
||||
// subject: channelInfos.displayName
|
||||
slow_mode_delay: await defaultSlowModeDelay(options, channelId)
|
||||
},
|
||||
affiliations: affiliations
|
||||
}
|
||||
@ -126,8 +140,9 @@ async function initRoomApiRouter (options: RegisterServerOptions, router: Router
|
||||
config: {
|
||||
name: video.name,
|
||||
description: '',
|
||||
language: video.language
|
||||
language: video.language,
|
||||
// subject: video.name
|
||||
slow_mode_delay: await defaultSlowModeDelay(options, video.channelId)
|
||||
},
|
||||
affiliations: affiliations
|
||||
}
|
||||
|
@ -74,6 +74,9 @@ interface ChannelConfigurationOptions {
|
||||
}>
|
||||
// TODO: bannedJIDs: string[]
|
||||
}
|
||||
slowMode: {
|
||||
defaultDelay: number
|
||||
}
|
||||
}
|
||||
|
||||
interface ChannelConfiguration {
|
||||
|
Loading…
x
Reference in New Issue
Block a user