2023-08-08 16:26:40 +00:00
|
|
|
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
2023-09-20 16:48:02 +00:00
|
|
|
import { localizedHelpUrl } from '../../../utils/help'
|
|
|
|
import { helpButtonSVG } from '../../../videowatch/buttons'
|
2023-09-21 15:13:28 +00:00
|
|
|
import { vivifyConfigurationChannel, getConfigurationChannelViewData } from './logic/channel'
|
2023-08-08 16:26:40 +00:00
|
|
|
// Must use require for mustache, import seems buggy.
|
|
|
|
const Mustache = require('mustache')
|
|
|
|
|
|
|
|
/**
|
2023-09-21 15:13:28 +00:00
|
|
|
* Renders the configuration settings page for a given channel,
|
|
|
|
* and set it as innerHTML to rootEl.
|
|
|
|
* The page content can be empty. In such case, the notifier will be used to display a message.
|
2023-08-08 16:26:40 +00:00
|
|
|
* @param registerClientOptions Peertube client options
|
|
|
|
* @param channelId The channel id
|
2023-09-21 15:13:28 +00:00
|
|
|
* @param rootEl The HTMLElement in which insert the generated DOM.
|
2023-08-08 16:26:40 +00:00
|
|
|
*/
|
2023-09-06 13:23:39 +00:00
|
|
|
async function renderConfigurationChannel (
|
2023-08-08 16:26:40 +00:00
|
|
|
registerClientOptions: RegisterClientOptions,
|
2023-09-21 15:13:28 +00:00
|
|
|
channelId: string,
|
|
|
|
rootEl: HTMLElement
|
|
|
|
): Promise<void> {
|
2023-08-08 16:26:40 +00:00
|
|
|
try {
|
2023-09-21 15:13:28 +00:00
|
|
|
const view = await getConfigurationChannelViewData(registerClientOptions, channelId)
|
|
|
|
await fillViewHelpButtons(registerClientOptions, view)
|
|
|
|
await fillLabels(registerClientOptions, view)
|
2023-09-20 16:48:02 +00:00
|
|
|
|
2023-09-22 11:56:48 +00:00
|
|
|
const content = Mustache.render(MUSTACHE_CONFIGURATION_CHANNEL, view) as string
|
2023-09-21 15:13:28 +00:00
|
|
|
|
|
|
|
rootEl.innerHTML = content
|
|
|
|
|
|
|
|
await vivifyConfigurationChannel(registerClientOptions, rootEl, channelId)
|
2023-08-08 16:26:40 +00:00
|
|
|
} catch (err: any) {
|
2023-09-21 15:13:28 +00:00
|
|
|
registerClientOptions.peertubeHelpers.notifier.error(err.toString())
|
|
|
|
rootEl.innerHTML = ''
|
2023-08-08 16:26:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 15:13:28 +00:00
|
|
|
async function fillViewHelpButtons (
|
|
|
|
registerClientOptions: RegisterClientOptions,
|
|
|
|
view: any
|
|
|
|
): Promise<void> {
|
2023-09-22 18:39:50 +00:00
|
|
|
const title = await registerClientOptions.peertubeHelpers.translate(LOC_ONLINE_HELP)
|
|
|
|
|
|
|
|
const button = async (page: string): Promise<string> => {
|
|
|
|
const helpUrl = await localizedHelpUrl(registerClientOptions, {
|
|
|
|
page
|
|
|
|
})
|
|
|
|
const helpIcon = helpButtonSVG()
|
|
|
|
return `<a
|
|
|
|
href="${helpUrl}"
|
|
|
|
target=_blank
|
|
|
|
title="${title}"
|
|
|
|
class="orange-button peertube-button-link"
|
|
|
|
>${helpIcon}</a>`
|
|
|
|
}
|
|
|
|
|
|
|
|
view.helpButton = await button('documentation/user/streamers/channel')
|
|
|
|
view.helpButtonBot = await button('documentation/user/streamers/bot')
|
|
|
|
view.helpButtonForbiddenWords = await button('documentation/user/streamers/bot/forbidden_words')
|
|
|
|
view.helpButtonQuotes = await button('documentation/user/streamers/bot/quotes')
|
|
|
|
view.helpButtonCommands = await button('documentation/user/streamers/bot/commands')
|
2024-02-22 13:53:41 +00:00
|
|
|
view.helpButtonSlowMode = await button('documentation/user/streamers/slow_mode')
|
2023-09-21 15:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fillLabels (
|
|
|
|
registerClientOptions: RegisterClientOptions,
|
|
|
|
view: any
|
|
|
|
): Promise<void> {
|
|
|
|
const { peertubeHelpers } = registerClientOptions
|
|
|
|
view.title = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE)
|
|
|
|
view.description = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC)
|
|
|
|
|
2024-02-13 11:49:22 +00:00
|
|
|
view.defaultSlowModeLabel = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_DEFAULT_SLOW_MODE_LABEL
|
|
|
|
)
|
|
|
|
view.defaultSlowModeDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DEFAULT_SLOW_MODE_DESC)
|
2023-09-21 15:13:28 +00:00
|
|
|
view.enableBot = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL)
|
|
|
|
view.botOptions = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE)
|
|
|
|
view.forbiddenWords = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL)
|
|
|
|
view.forbiddenWordsDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_DESC)
|
|
|
|
view.forbiddenWordsDesc2 = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_DESC2)
|
|
|
|
view.forbiddenWordsReason = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REASON_LABEL
|
|
|
|
)
|
|
|
|
view.forbiddenWordsReasonDesc = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REASON_DESC
|
|
|
|
)
|
|
|
|
view.forbiddenWordsRegexp = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REGEXP_LABEL
|
|
|
|
)
|
|
|
|
view.forbiddenWordsRegexpDesc = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REGEXP_DESC
|
|
|
|
)
|
|
|
|
view.forbiddenWordsApplyToModerators = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_APPLYTOMODERATORS_LABEL
|
|
|
|
)
|
|
|
|
view.forbiddenWordsApplyToModeratorsDesc = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_APPLYTOMODERATORS_DESC
|
|
|
|
)
|
2023-09-25 11:16:15 +00:00
|
|
|
view.forbiddenWordsComments = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_LABEL
|
|
|
|
)
|
|
|
|
view.forbiddenWordsCommentsDesc = await peertubeHelpers.translate(
|
|
|
|
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_DESC
|
|
|
|
)
|
2023-09-21 15:13:28 +00:00
|
|
|
view.quoteLabel = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_LABEL)
|
2023-09-26 12:58:59 +00:00
|
|
|
view.quoteLabel2 = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_LABEL2)
|
2023-09-21 15:13:28 +00:00
|
|
|
view.quoteDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DESC)
|
|
|
|
view.quoteDesc2 = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DESC2)
|
|
|
|
view.quoteDelayLabel = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DELAY_LABEL)
|
|
|
|
view.quoteDelayDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DELAY_DESC)
|
|
|
|
view.commandLabel = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_LABEL)
|
|
|
|
view.commandDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_DESC)
|
|
|
|
view.commandCmdLabel = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_CMD_LABEL)
|
|
|
|
view.commandCmdDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_CMD_DESC)
|
|
|
|
view.commandMessageLabel = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_MESSAGE_LABEL)
|
|
|
|
view.commandMessageDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_MESSAGE_DESC)
|
|
|
|
// view.bannedJIDs = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BANNED_JIDS_LABEL)
|
|
|
|
|
|
|
|
view.save = await peertubeHelpers.translate(LOC_SAVE)
|
|
|
|
view.cancel = await peertubeHelpers.translate(LOC_CANCEL)
|
|
|
|
view.botNickname = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_NICKNAME)
|
|
|
|
view.moreInfo = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FOR_MORE_INFO)
|
|
|
|
}
|
|
|
|
|
2023-08-08 16:26:40 +00:00
|
|
|
export {
|
2023-09-06 13:23:39 +00:00
|
|
|
renderConfigurationChannel
|
2023-08-08 16:26:40 +00:00
|
|
|
}
|