Slow mode (related to #385):

The slow mode duration on the channel option page is now a default value for new rooms. Streamers can change the value room per room in the room's configuration.
This commit is contained in:
John Livingston 2024-05-17 15:32:31 +02:00
parent da75765bdb
commit 4afc6ec4c6
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
5 changed files with 32 additions and 35 deletions

View File

@ -8,6 +8,7 @@ TODO: tag custom ConverseJS, and update build-conversejs.sh.
* #177: streamer's task/to-do lists: streamers, and their room's moderators, can handle task lists directly. This can be used to handle viewers questions, moderation actions, ... More info in the [tasks documentation](https://livingston.frama.io/peertube-plugin-livechat/fr/documentation/user/streamers/tasks/). * #177: streamer's task/to-do lists: streamers, and their room's moderators, can handle task lists directly. This can be used to handle viewers questions, moderation actions, ... More info in the [tasks documentation](https://livingston.frama.io/peertube-plugin-livechat/fr/documentation/user/streamers/tasks/).
* #385: new way of managing chat access rights. Now streamers are owner of their chat rooms. Peertube admins/moderators are not by default, so that their identities are not leaking. But they have a button to promote as chat room owner, if they need to take action. Please note that there is a migration script that will remove all Peertube admins/moderators affiliations (unless they are video/channel's owner). They can get this access back using the button. * #385: new way of managing chat access rights. Now streamers are owner of their chat rooms. Peertube admins/moderators are not by default, so that their identities are not leaking. But they have a button to promote as chat room owner, if they need to take action. Please note that there is a migration script that will remove all Peertube admins/moderators affiliations (unless they are video/channel's owner). They can get this access back using the button.
* #385: the slow mode duration on the channel option page is now a default value for new rooms. Streamers can change the value room per room in the room's configuration.
### Minor changes and fixes ### Minor changes and fixes

View File

@ -365,7 +365,7 @@ livechat_configuration_channel_title: "Channel options"
livechat_configuration_channel_desc: "You can setup here some options for this channel (moderation policies, ...)." livechat_configuration_channel_desc: "You can setup here some options for this channel (moderation policies, ...)."
livechat_configuration_channel_slow_mode_label: "Slow mode" livechat_configuration_channel_slow_mode_label: "Slow mode"
livechat_configuration_channel_slow_mode_desc: | livechat_configuration_channel_slow_mode_desc: |
Slow mode value: Slow mode default value:
<ul> <ul>
<li>0: slow mode disabled</li> <li>0: slow mode disabled</li>
<li>Any positive integer: users can send a message every X seconds (moderators are not limited)</li> <li>Any positive integer: users can send a message every X seconds (moderators are not limited)</li>

View File

@ -393,7 +393,7 @@ avatar_set_option_abstract: Abstrait
livechat_configuration_channel_slow_mode_label: Mode lent livechat_configuration_channel_slow_mode_label: Mode lent
slow_mode_info: Le mode lent est activé, les utilisateur⋅rices peuvent envoyer un slow_mode_info: Le mode lent est activé, les utilisateur⋅rices peuvent envoyer un
message toutes les %1$s secondes. message toutes les %1$s secondes.
livechat_configuration_channel_slow_mode_desc: "Valeur du mode lent:\n<ul>\n <li>0: livechat_configuration_channel_slow_mode_desc: "Valeur par défaut du mode lent:\n<ul>\n <li>0:
mode lent désactivé</li>\n <li>Tout entier positif: les utilisateur⋅rices peuvent mode lent désactivé</li>\n <li>Tout entier positif: les utilisateur⋅rices peuvent
envoyer un message toutes les X secondes (les modérateur⋅rices ne sont pas limité⋅es)</li>\n\ envoyer un message toutes les X secondes (les modérateur⋅rices ne sont pas limité⋅es)</li>\n\
</ul>\n" </ul>\n"

View File

@ -4,7 +4,6 @@ import { fillVideoCustomFields } from '../../custom-fields'
import { videoHasWebchat } from '../../../../shared/lib/video' import { videoHasWebchat } from '../../../../shared/lib/video'
import { updateProsodyRoom } from '../../prosody/api/manage-rooms' import { updateProsodyRoom } from '../../prosody/api/manage-rooms'
import { getChannelInfosById } from '../../database/channel' import { getChannelInfosById } from '../../database/channel'
import { getChannelConfigurationOptions, getDefaultChannelConfigurationOptions } from './storage'
/** /**
* Register stuffs related to channel configuration * Register stuffs related to channel configuration
@ -107,11 +106,8 @@ async function initChannelConfiguration (options: RegisterServerOptions): Promis
// FIXME: this piece of code should not be in this file (nothing to do with initChannelConfiguration, // FIXME: this piece of code should not be in this file (nothing to do with initChannelConfiguration,
// but will be more efficient to add here, as we already tested hasChat). // but will be more efficient to add here, as we already tested hasChat).
// Note: no need to await here, would only degrade performances. // Note: no need to await here, would only degrade performances.
const channelOptions = await getChannelConfigurationOptions(options, video.channelId) ??
getDefaultChannelConfigurationOptions(options)
updateProsodyRoom(options, video.uuid, { updateProsodyRoom(options, video.uuid, {
name: video.name, name: video.name
slow_mode_duration: channelOptions.slowMode.duration
}).then( }).then(
() => {}, () => {},
(err) => logger.error(err) (err) => logger.error(err)
@ -137,11 +133,8 @@ async function initChannelConfiguration (options: RegisterServerOptions): Promis
if (settings['prosody-room-type'] === 'channel') { if (settings['prosody-room-type'] === 'channel') {
const jid = 'channel.' + channel.id.toString() const jid = 'channel.' + channel.id.toString()
// Note: no need to await here, would only degrade performances. // Note: no need to await here, would only degrade performances.
const channelOptions = await getChannelConfigurationOptions(options, channel.id) ??
getDefaultChannelConfigurationOptions(options)
updateProsodyRoom(options, jid, { updateProsodyRoom(options, jid, {
name: channel.displayName, name: channel.displayName
slow_mode_duration: channelOptions.slowMode.duration
}).then( }).then(
() => {}, () => {},
(err) => logger.error(err) (err) => logger.error(err)

View File

@ -1,7 +1,7 @@
import type { RegisterServerOptions } from '@peertube/peertube-types' import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { RoomConf } from 'xmppjs-chat-bot' import type { RoomConf } from 'xmppjs-chat-bot'
import { getProsodyDomain } from '../prosody/config/domain' import { getProsodyDomain } from '../prosody/config/domain'
import { listProsodyRooms, updateProsodyRoom } from '../prosody/api/manage-rooms' import { listProsodyRooms } from '../prosody/api/manage-rooms'
import { getChannelInfosById } from '../database/channel' import { getChannelInfosById } from '../database/channel'
import { ChannelConfigurationOptions } from '../../../shared/lib/types' import { ChannelConfigurationOptions } from '../../../shared/lib/types'
import { import {
@ -288,7 +288,10 @@ class RoomChannel {
this.logger.info('Syncing...') this.logger.info('Syncing...')
this.isWriting = true this.isWriting = true
const prosodyRoomUpdates = new Map<string, Parameters<typeof updateProsodyRoom>[2]>() // Note 2024-05-15: slow_mode_duration becomes a default value.
// We dont need prosodyRoomUpdates anymore. but keeping the code commented,
// if we want to enable again a similar sync.
// const prosodyRoomUpdates = new Map<string, Parameters<typeof updateProsodyRoom>[2]>()
try { try {
const data = this._serializeData() // must be atomic const data = this._serializeData() // must be atomic
@ -348,12 +351,12 @@ class RoomChannel {
await BotConfiguration.singleton().updateRoom(roomJID, botConf) await BotConfiguration.singleton().updateRoom(roomJID, botConf)
// Now we also must update some room metadata (slow mode duration, ...) // // Now we also must update some room metadata (slow mode duration, ...)
// This can be done without waiting for the API call to finish, but we don't want to send thousands of // // This can be done without waiting for the API call to finish, but we don't want to send thousands of
// API calls at the same time. So storing data in a map, and we well launch it sequentially at the end // // API calls at the same time. So storing data in a map, and we well launch it sequentially at the end
prosodyRoomUpdates.set(roomJID, { // prosodyRoomUpdates.set(roomJID, {
slow_mode_duration: channelConfigurationOptions.slowMode.duration // slow_mode_duration: channelConfigurationOptions.slowMode.duration
}) // })
this.roomConfToUpdate.delete(roomJID) this.roomConfToUpdate.delete(roomJID)
} }
@ -367,22 +370,22 @@ class RoomChannel {
this.isWriting = false this.isWriting = false
} }
if (prosodyRoomUpdates.size) { // if (prosodyRoomUpdates.size) {
// Here we don't have to wait. // // Here we don't have to wait.
// If it fails (for example because we are turning off prosody), it is not a big deal. // // If it fails (for example because we are turning off prosody), it is not a big deal.
// Does not worth the cost to wait. // // Does not worth the cost to wait.
// eslint-disable-next-line @typescript-eslint/no-misused-promises // // eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async () => { // setTimeout(async () => {
this.logger.info('Syncing done, but still some data to send to Prosody') // this.logger.info('Syncing done, but still some data to send to Prosody')
for (const [roomJID, data] of prosodyRoomUpdates.entries()) { // for (const [roomJID, data] of prosodyRoomUpdates.entries()) {
try { // try {
await updateProsodyRoom(this.options, roomJID, data) // await updateProsodyRoom(this.options, roomJID, data)
} catch (err) { // } catch (err) {
this.logger.error(`Failed updating prosody room info: "${err as string}".`) // this.logger.error(`Failed updating prosody room info: "${err as string}".`)
} // }
} // }
}, 0) // }, 0)
} // }
} }
/** /**