Naming:
* changing delay by duration for slow mode options * better labels
This commit is contained in:
parent
1e876ec43c
commit
3d9237624d
@ -5,8 +5,8 @@
|
||||
### New features
|
||||
|
||||
* 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.
|
||||
* new option in room configuration to set the slow mode duration (new prosody module mod_muc_slow_mode).
|
||||
* default duration is configurable in channel's chat rooms options.
|
||||
* backend rejects messages when the slow mode is not respected.
|
||||
* frontend: display an infobox when slow mode is active.
|
||||
|
||||
|
@ -19,11 +19,11 @@
|
||||
<label>
|
||||
<input
|
||||
type="number"
|
||||
name="slow_mode_default_delay"
|
||||
name="slow_mode_default_duration"
|
||||
min="0"
|
||||
max="1000"
|
||||
id="peertube-livechat-slow-mode-default-delay"
|
||||
value="{{channelConfiguration.configuration.slowMode.defaultDelay}}"
|
||||
id="peertube-livechat-slow-mode-default-duration"
|
||||
value="{{channelConfiguration.configuration.slowMode.defaultDuration}}"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
@ -165,16 +165,16 @@ async function vivifyConfigurationChannel (
|
||||
|
||||
const validateData: Function = async (channelConfigurationOptions: ChannelConfigurationOptions): Promise<boolean> => {
|
||||
const botConf = channelConfigurationOptions.bot
|
||||
const slowModeDefaultDelay = channelConfigurationOptions.slowMode.defaultDelay
|
||||
const slowModeDefaultDuration = channelConfigurationOptions.slowMode.defaultDuration
|
||||
const errorFieldSelectors = []
|
||||
|
||||
if (
|
||||
(typeof slowModeDefaultDelay !== 'number') ||
|
||||
isNaN(slowModeDefaultDelay) ||
|
||||
slowModeDefaultDelay < 0 ||
|
||||
slowModeDefaultDelay > 1000
|
||||
(typeof slowModeDefaultDuration !== 'number') ||
|
||||
isNaN(slowModeDefaultDuration) ||
|
||||
slowModeDefaultDuration < 0 ||
|
||||
slowModeDefaultDuration > 1000
|
||||
) {
|
||||
const selector = '#peertube-livechat-slow-mode-default-delay'
|
||||
const selector = '#peertube-livechat-slow-mode-default-duration'
|
||||
errorFieldSelectors.push(selector)
|
||||
await displayError(selector, await translate(LOC_INVALID_VALUE))
|
||||
}
|
||||
@ -233,7 +233,7 @@ async function vivifyConfigurationChannel (
|
||||
removeDisplayedErrors()
|
||||
const channelConfigurationOptions: ChannelConfigurationOptions = {
|
||||
slowMode: {
|
||||
defaultDelay: parseInt(data.get('slow_mode_default_delay')?.toString() ?? '0')
|
||||
defaultDuration: parseInt(data.get('slow_mode_default_duration')?.toString() ?? '0')
|
||||
},
|
||||
bot: {
|
||||
enabled: data.get('bot') === '1',
|
||||
|
@ -28,20 +28,20 @@ class SlowMode extends CustomElement {
|
||||
this.model = _converse.chatboxes.get(this.jid)
|
||||
await this.model.initialized
|
||||
|
||||
this.listenTo(this.model.config, 'change:slow_mode_delay', () => {
|
||||
this.listenTo(this.model.config, 'change:slow_mode_duration', () => {
|
||||
this.requestUpdate()
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
if (!(parseInt(this.model.config.get('slow_mode_delay')) > 0)) { // This includes NaN, for which ">0"===false
|
||||
if (!(parseInt(this.model.config.get('slow_mode_duration')) > 0)) { // This includes NaN, for which ">0"===false
|
||||
return html``
|
||||
}
|
||||
return html`
|
||||
<converse-icon class="fa fa-info-circle" size="1.2em"></converse-icon>
|
||||
${__(
|
||||
'Slow mode is enabled, you have to wait %1$s seconds between two messages.',
|
||||
this.model.config.get('slow_mode_delay')
|
||||
'Slow mode is enabled, users can send a message every %1$s seconds.',
|
||||
this.model.config.get('slow_mode_duration')
|
||||
)}`
|
||||
}
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ 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>
|
||||
<li>Any positive integer: users can send a message every X seconds (moderators are not limited)</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"
|
||||
@ -388,4 +388,4 @@ livechat_configuration_channel_bot_nickname: "Bot nickname"
|
||||
|
||||
invalid_value: "Invalid value."
|
||||
|
||||
slow_mode_info: "Slow mode is enabled, you have to wait 10 seconds between two messages."
|
||||
slow_mode_info: "Slow mode is enabled, users can send a message every %1$s seconds."
|
||||
|
@ -4,7 +4,7 @@
|
||||
-- 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 version contains a modification to take into account new config option "slow_mode_duration".
|
||||
-- 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.
|
||||
--
|
||||
@ -111,8 +111,8 @@ local function apply_config(room, settings)
|
||||
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;
|
||||
if (type(config.slow_mode_duration) == "number") and config.slow_mode_duration >= 0 then
|
||||
room._data.slow_mode_duration = config.slow_mode_duration;
|
||||
end
|
||||
elseif config ~= nil then
|
||||
module:log("error", "Invalid config returned from API for %s: %q", room.jid, config);
|
||||
|
@ -12,12 +12,12 @@ Just enable the module on your MUC component.
|
||||
The feature will be accessible throught the room configuration form.
|
||||
|
||||
Depending on your application, it is possible that the slow mode is more important than other fields (for example for a video streaming service).
|
||||
The position in the room config form can be changed be setting the option `slow_mode_delay_form_position`.
|
||||
The position in the room config form can be changed be setting the option `slow_mode_duration_form_position`.
|
||||
This value will be passed as priority for the "muc-config-form" hook.
|
||||
By default, the field will be between muc#roomconfig_changesubject and muc#roomconfig_moderatedroom.
|
||||
|
||||
``` lua
|
||||
VirtualHost "muc.example.com"
|
||||
modules_enabled = { "muc_slow_mode" }
|
||||
slow_mode_delay_form_position = 96
|
||||
slow_mode_duration_form_position = 96
|
||||
```
|
||||
|
@ -28,34 +28,34 @@ local xmlns_muc = "http://jabber.org/protocol/muc";
|
||||
-- Depending on your application, it is possible that the slow mode is more important than other fields (for example for a video streaming service).
|
||||
-- So there is an option to change this.
|
||||
-- By default, field will be between muc#roomconfig_changesubject and muc#roomconfig_moderatedroom
|
||||
local form_position = module:get_option_number("slow_mode_delay_form_position") or 80-2;
|
||||
local form_position = module:get_option_number("slow_mode_duration_form_position") or 80-2;
|
||||
|
||||
-- Getter/Setter
|
||||
local function get_slow_mode_delay(room)
|
||||
return room._data.slow_mode_delay or 0;
|
||||
local function get_slow_mode_duration(room)
|
||||
return room._data.slow_mode_duration 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");
|
||||
local function set_slow_mode_duration(room, duration)
|
||||
if duration then
|
||||
duration = assert(tonumber(duration), "Slow mode duration is not a valid number");
|
||||
end
|
||||
if delay and delay < 0 then
|
||||
delay = 0;
|
||||
if duration and duration < 0 then
|
||||
duration = 0;
|
||||
end
|
||||
|
||||
if get_slow_mode_delay(room) == delay then return false; end
|
||||
if get_slow_mode_duration(room) == duration then return false; end
|
||||
|
||||
room._data.slow_mode_delay = delay;
|
||||
room._data.slow_mode_duration = duration;
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Discovering support
|
||||
local function add_disco_form(event)
|
||||
table.insert(event.form, {
|
||||
name = "muc#roominfo_slow_mode_delay";
|
||||
name = "muc#roominfo_slow_mode_duration";
|
||||
value = "";
|
||||
});
|
||||
event.formdata["muc#roominfo_slow_mode_delay"] = get_slow_mode_delay(event.room);
|
||||
event.formdata["muc#roominfo_slow_mode_duration"] = get_slow_mode_duration(event.room);
|
||||
end
|
||||
|
||||
module:hook("muc-disco#info", add_disco_form);
|
||||
@ -63,17 +63,17 @@ module:hook("muc-disco#info", add_disco_form);
|
||||
-- Config form declaration
|
||||
local function add_form_option(event)
|
||||
table.insert(event.form, {
|
||||
name = "muc#roomconfig_slow_mode_delay";
|
||||
name = "muc#roomconfig_slow_mode_duration";
|
||||
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);
|
||||
label = "Slow Mode (0=disabled, any positive integer= users can send a message every X seconds.)";
|
||||
-- desc = "";
|
||||
value = get_slow_mode_duration(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
|
||||
module:hook("muc-config-submitted/muc#roomconfig_slow_mode_duration", function(event)
|
||||
if set_slow_mode_duration(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
|
||||
@ -86,8 +86,8 @@ function handle_groupchat(event)
|
||||
local origin, stanza = event.origin, event.stanza;
|
||||
local room = event.room;
|
||||
|
||||
local delay = get_slow_mode_delay(room) or 0;
|
||||
if delay <= 0 then
|
||||
local duration = get_slow_mode_duration(room) or 0;
|
||||
if duration <= 0 then
|
||||
-- no slow mode for this room
|
||||
-- module:log("debug", "No slow mode for this room");
|
||||
return;
|
||||
@ -119,14 +119,14 @@ function handle_groupchat(event)
|
||||
local previous = room.slow_mode_last_messages[actor_jid];
|
||||
-- module:log(
|
||||
-- "debug",
|
||||
-- "Last message for user %s was at %s, now is %s, delay is %s, now - previous is %s",
|
||||
-- "Last message for user %s was at %s, now is %s, duration is %s, now - previous is %s",
|
||||
-- actor_jid,
|
||||
-- previous or 0,
|
||||
-- now,
|
||||
-- delay,
|
||||
-- duration,
|
||||
-- (now - (previous or 0))
|
||||
-- );
|
||||
if ((not previous) or (now - previous > delay)) then
|
||||
if ((not previous) or (now - previous > duration)) then
|
||||
-- module:log("debug", "Message accepted");
|
||||
room.slow_mode_last_messages[actor_jid] = now;
|
||||
return;
|
||||
@ -139,7 +139,7 @@ function handle_groupchat(event)
|
||||
"wait",
|
||||
-- error_condition = 'policy-violation' (see RFC 6120 Defined Error Conditions https://xmpp.org/rfcs/rfc6120.html#stanzas-error-conditions)
|
||||
"policy-violation",
|
||||
"You have exceeded the limit imposed by the slow mode in this room. You have to wait " .. delay .. " seconds between messages. Please try again later"
|
||||
"You have exceeded the limit imposed by the slow mode in this room. You have to wait " .. duration .. " seconds between messages. Please try again later"
|
||||
);
|
||||
|
||||
-- Note: following commented lines were inspired by mod_muc_limits, but it seems it is not required.
|
||||
|
@ -23,7 +23,10 @@ async function sanitizeChannelConfigurationOptions (
|
||||
throw new Error('Invalid data.bot data type')
|
||||
}
|
||||
|
||||
const slowModeData = data.slowMode ?? { defaultDelay: 0 } // not present in livechat <= 8.2.0
|
||||
// slowMode not present in livechat <= 8.2.0:
|
||||
const slowModeData = data.slowMode ?? {}
|
||||
slowModeData.defaultDuration ??= 0
|
||||
|
||||
if (typeof slowModeData !== 'object') {
|
||||
throw new Error('Invalid data.slowMode data type')
|
||||
}
|
||||
@ -38,7 +41,7 @@ async function sanitizeChannelConfigurationOptions (
|
||||
// TODO: bannedJIDs
|
||||
},
|
||||
slowMode: {
|
||||
defaultDelay: _readInteger(slowModeData, 'defaultDelay', 0, 1000)
|
||||
defaultDuration: _readInteger(slowModeData, 'defaultDuration', 0, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ function getDefaultChannelConfigurationOptions (_options: RegisterServerOptions)
|
||||
commands: []
|
||||
},
|
||||
slowMode: {
|
||||
defaultDelay: 0
|
||||
defaultDuration: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ class ProsodyConfigContent {
|
||||
this.muc.set('muc_room_default_history_length', 20)
|
||||
|
||||
this.muc.add('modules_enabled', 'muc_slow_mode')
|
||||
this.muc.add('slow_mode_delay_form_position', 120)
|
||||
this.muc.add('slow_mode_duration_form_position', 120)
|
||||
}
|
||||
|
||||
useAnonymous (autoBanIP: boolean): void {
|
||||
|
@ -31,15 +31,15 @@ interface RoomDefaults {
|
||||
archiving?: boolean
|
||||
|
||||
// Following fields are specific to livechat (for now), and requires a customized version for mod_muc_http_defaults.
|
||||
slow_mode_delay?: number
|
||||
slow_mode_duration?: number
|
||||
}
|
||||
affiliations?: Affiliations
|
||||
}
|
||||
|
||||
async function defaultSlowModeDelay (options: RegisterServerOptions, channelId: number): Promise<number> {
|
||||
async function defaultSlowModeDuration (options: RegisterServerOptions, channelId: number): Promise<number> {
|
||||
const channelOptions = await getChannelConfigurationOptions(options, channelId) ??
|
||||
getDefaultChannelConfigurationOptions(options)
|
||||
return channelOptions.slowMode.defaultDelay
|
||||
return channelOptions.slowMode.defaultDuration
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +89,7 @@ async function initRoomApiRouter (options: RegisterServerOptions, router: Router
|
||||
name: channelInfos.displayName,
|
||||
description: '',
|
||||
// subject: channelInfos.displayName
|
||||
slow_mode_delay: await defaultSlowModeDelay(options, channelId)
|
||||
slow_mode_duration: await defaultSlowModeDuration(options, channelId)
|
||||
},
|
||||
affiliations: affiliations
|
||||
}
|
||||
@ -142,7 +142,7 @@ async function initRoomApiRouter (options: RegisterServerOptions, router: Router
|
||||
description: '',
|
||||
language: video.language,
|
||||
// subject: video.name
|
||||
slow_mode_delay: await defaultSlowModeDelay(options, video.channelId)
|
||||
slow_mode_duration: await defaultSlowModeDuration(options, video.channelId)
|
||||
},
|
||||
affiliations: affiliations
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ interface ChannelConfigurationOptions {
|
||||
// TODO: bannedJIDs: string[]
|
||||
}
|
||||
slowMode: {
|
||||
defaultDelay: number
|
||||
defaultDuration: number
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user