Terms&Conditions (#18) WIP:

* channel terms
This commit is contained in:
John Livingston
2024-06-25 11:28:46 +02:00
parent b110456029
commit a06ef00e2a
9 changed files with 101 additions and 42 deletions

View File

@ -119,6 +119,7 @@ async function initChannelConfiguration (options: RegisterServerOptions): Promis
// 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).
// Note: no need to await here, would only degrade performances.
// FIXME: should also update livechat_muc_terms if channel has changed.
updateProsodyRoom(options, video.uuid, {
name: video.name
}).then(

View File

@ -64,6 +64,7 @@ async function updateProsodyRoom (
data: {
name?: string
slow_mode_duration?: number
livechat_muc_terms?: string
addAffiliations?: Affiliations
removeAffiliationsFor?: string[]
}
@ -92,6 +93,9 @@ async function updateProsodyRoom (
if (('slow_mode_duration' in data) && data.slow_mode_duration !== undefined) {
apiData.slow_mode_duration = data.slow_mode_duration
}
if ('livechat_muc_terms' in data) {
apiData.livechat_muc_terms = data.livechat_muc_terms ?? ''
}
if (('addAffiliations' in data) && data.addAffiliations !== undefined) {
apiData.addAffiliations = data.addAffiliations
}

View File

@ -246,7 +246,7 @@ class ProsodyConfigContent {
this.muc.add('modules_enabled', 'muc_peertubelivechat_terms')
this.muc.set('muc_terms_service_nickname', 'Peertube')
if (chatTerms) {
this.muc.set('muc_terms', new ConfigEntryValueMultiLineString(chatTerms))
this.muc.set('muc_terms_global', new ConfigEntryValueMultiLineString(chatTerms))
}
}

View File

@ -5,7 +5,7 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { RoomConf } from 'xmppjs-chat-bot'
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 { ChannelConfigurationOptions } from '../../../shared/lib/types'
import {
@ -292,10 +292,7 @@ class RoomChannel {
this.logger.info('Syncing...')
this.isWriting = true
// 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]>()
const prosodyRoomUpdates = new Map<string, Parameters<typeof updateProsodyRoom>[2]>()
try {
const data = this._serializeData() // must be atomic
@ -355,12 +352,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 on Prosody side (livechat_muc_terms, ...)
// 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, {
livechat_muc_terms: channelConfigurationOptions.terms
})
this.roomConfToUpdate.delete(roomJID)
}
@ -374,22 +371,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)
}
}
/**

View File

@ -37,6 +37,7 @@ interface RoomDefaults {
// Following fields are specific to livechat (for now), and requires a customized version for mod_muc_http_defaults.
slow_mode_duration?: number
mute_anonymous?: boolean
livechat_muc_terms?: string
}
affiliations?: Affiliations
}
@ -50,7 +51,8 @@ async function _getChannelSpecificOptions (
return {
slow_mode_duration: channelOptions.slowMode.duration,
mute_anonymous: channelOptions.mute.anonymous
mute_anonymous: channelOptions.mute.anonymous,
livechat_muc_terms: channelOptions.terms
}
}