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
5 changed files with 32 additions and 35 deletions

View File

@ -1,7 +1,7 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { RoomConf } from 'xmppjs-chat-bot'
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 { ChannelConfigurationOptions } from '../../../shared/lib/types'
import {
@ -288,7 +288,10 @@ class RoomChannel {
this.logger.info('Syncing...')
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 {
const data = this._serializeData() // must be atomic
@ -348,12 +351,12 @@ class RoomChannel {
await BotConfiguration.singleton().updateRoom(roomJID, botConf)
// 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
// API calls at the same time. So storing data in a map, and we well launch it sequentially at the end
prosodyRoomUpdates.set(roomJID, {
slow_mode_duration: channelConfigurationOptions.slowMode.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
// // API calls at the same time. So storing data in a map, and we well launch it sequentially at the end
// prosodyRoomUpdates.set(roomJID, {
// slow_mode_duration: channelConfigurationOptions.slowMode.duration
// })
this.roomConfToUpdate.delete(roomJID)
}
@ -367,22 +370,22 @@ class RoomChannel {
this.isWriting = false
}
if (prosodyRoomUpdates.size) {
// Here we don't have to wait.
// If it fails (for example because we are turning off prosody), it is not a big deal.
// Does not worth the cost to wait.
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async () => {
this.logger.info('Syncing done, but still some data to send to Prosody')
for (const [roomJID, data] of prosodyRoomUpdates.entries()) {
try {
await updateProsodyRoom(this.options, roomJID, data)
} catch (err) {
this.logger.error(`Failed updating prosody room info: "${err as string}".`)
}
}
}, 0)
}
// if (prosodyRoomUpdates.size) {
// // Here we don't have to wait.
// // If it fails (for example because we are turning off prosody), it is not a big deal.
// // Does not worth the cost to wait.
// // eslint-disable-next-line @typescript-eslint/no-misused-promises
// setTimeout(async () => {
// this.logger.info('Syncing done, but still some data to send to Prosody')
// for (const [roomJID, data] of prosodyRoomUpdates.entries()) {
// try {
// await updateProsodyRoom(this.options, roomJID, data)
// } catch (err) {
// this.logger.error(`Failed updating prosody room info: "${err as string}".`)
// }
// }
// }, 0)
// }
}
/**