Updating slow mode duration on existing rooms when changing channel options (related to #332).
This commit is contained in:
parent
08b84899f6
commit
e67b21dd9f
@ -5,6 +5,7 @@
|
|||||||
* Fix #87: updating chat room title when video/channel title is changed.
|
* Fix #87: updating chat room title when video/channel title is changed.
|
||||||
* Updating xmppjs-chat-box version.
|
* Updating xmppjs-chat-box version.
|
||||||
* Translation updates: japanese.
|
* Translation updates: japanese.
|
||||||
|
* Updating slow mode duration on existing rooms when changing channel options (related to #332).
|
||||||
|
|
||||||
## 8.3.2
|
## 8.3.2
|
||||||
|
|
||||||
|
@ -83,6 +83,12 @@ local function update_room(event)
|
|||||||
must104 = true;
|
must104 = true;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if type(config.slow_mode_duration) == "number" then
|
||||||
|
if room._data.slow_mode_duration ~= config.slow_mode_duration then
|
||||||
|
room._data.slow_mode_duration = config.slow_mode_duration;
|
||||||
|
must104 = true;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if must104 then
|
if must104 then
|
||||||
-- we must broadcast a status 104 message, so that clients can update room info
|
-- we must broadcast a status 104 message, so that clients can update room info
|
||||||
|
@ -106,7 +106,7 @@ 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.
|
||||||
updateProsodyRoom(options, video.channelId, video.uuid, {
|
updateProsodyRoom(options, video.uuid, {
|
||||||
name: video.name
|
name: video.name
|
||||||
}).then(
|
}).then(
|
||||||
() => {},
|
() => {},
|
||||||
@ -133,7 +133,7 @@ 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.
|
||||||
updateProsodyRoom(options, channel.id, jid, {
|
updateProsodyRoom(options, jid, {
|
||||||
name: channel.displayName
|
name: channel.displayName
|
||||||
}).then(
|
}).then(
|
||||||
() => {},
|
() => {},
|
||||||
|
@ -49,17 +49,16 @@ async function listProsodyRooms (options: RegisterServerOptions): Promise<Prosod
|
|||||||
* Note: could be called without verifying that the room exists.
|
* Note: could be called without verifying that the room exists.
|
||||||
* On the Prosody side, non existing rooms will be ignored.
|
* On the Prosody side, non existing rooms will be ignored.
|
||||||
* @param options Peertube server options
|
* @param options Peertube server options
|
||||||
* @param channelId associated channelId
|
|
||||||
* @param jid Room JID (can be only the local part, or the local + domain)
|
* @param jid Room JID (can be only the local part, or the local + domain)
|
||||||
* @param data Data to update
|
* @param data Data to update. Note: will only try to update data that are given.
|
||||||
* @returns true if success
|
* @returns true if success
|
||||||
*/
|
*/
|
||||||
async function updateProsodyRoom (
|
async function updateProsodyRoom (
|
||||||
options: RegisterServerOptions,
|
options: RegisterServerOptions,
|
||||||
channelId: number | string,
|
|
||||||
jid: string,
|
jid: string,
|
||||||
data: {
|
data: {
|
||||||
name: string
|
name?: string
|
||||||
|
slow_mode_duration?: number
|
||||||
}
|
}
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const logger = options.peertubeHelpers.logger
|
const logger = options.peertubeHelpers.logger
|
||||||
@ -78,8 +77,13 @@ async function updateProsodyRoom (
|
|||||||
// Requesting on localhost, because currentProsody.host does not always resolves correctly (docker use case, ...)
|
// Requesting on localhost, because currentProsody.host does not always resolves correctly (docker use case, ...)
|
||||||
const apiUrl = `http://localhost:${currentProsody.port}/peertubelivechat_manage_rooms/update-room`
|
const apiUrl = `http://localhost:${currentProsody.port}/peertubelivechat_manage_rooms/update-room`
|
||||||
const apiData = {
|
const apiData = {
|
||||||
jid,
|
jid
|
||||||
name: data.name
|
} as any
|
||||||
|
if ('name' in data) {
|
||||||
|
apiData.name = data.name
|
||||||
|
}
|
||||||
|
if ('slow_mode_duration' in data) {
|
||||||
|
apiData.slow_mode_duration = data.slow_mode_duration
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug('Calling update room API on url: ' + apiUrl + ', with data: ' + JSON.stringify(apiData))
|
logger.debug('Calling update room API on url: ' + apiUrl + ', with data: ' + JSON.stringify(apiData))
|
||||||
|
@ -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 } from '../prosody/api/manage-rooms'
|
import { listProsodyRooms, updateProsodyRoom } 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 {
|
||||||
@ -287,6 +287,9 @@ 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]>()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = this._serializeData() // must be atomic
|
const data = this._serializeData() // must be atomic
|
||||||
this.needSync = false // Note: must be done atomicly with the read
|
this.needSync = false // Note: must be done atomicly with the read
|
||||||
@ -344,6 +347,14 @@ 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, ...)
|
||||||
|
// 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.defaultDuration
|
||||||
|
})
|
||||||
|
|
||||||
this.roomConfToUpdate.delete(roomJID)
|
this.roomConfToUpdate.delete(roomJID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,6 +366,23 @@ class RoomChannel {
|
|||||||
} finally {
|
} finally {
|
||||||
this.isWriting = false
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user