Renaming 'moderation' pages to 'configuration'.
This commit is contained in:
@ -1,23 +1,23 @@
|
||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||
import type { ChannelModerationOptions } from 'shared/lib/types'
|
||||
import type { ChannelConfigurationOptions } from 'shared/lib/types'
|
||||
import { getBaseRoute } from '../../../videowatch/uri'
|
||||
|
||||
/**
|
||||
* Adds the front-end logic on the generated html for the channel moderation options.
|
||||
* Adds the front-end logic on the generated html for the channel configuration options.
|
||||
* @param clientOptions Peertube client options
|
||||
* @param rootEl The root element in which the template was rendered
|
||||
*/
|
||||
async function vivifyModerationChannel (
|
||||
async function vivifyConfigurationChannel (
|
||||
clientOptions: RegisterClientOptions,
|
||||
rootEl: HTMLElement,
|
||||
channelId: string
|
||||
): Promise<void> {
|
||||
const form = rootEl.querySelector('form[livechat-moderation-channel-options]') as HTMLFormElement
|
||||
const form = rootEl.querySelector('form[livechat-configuration-channel-options]') as HTMLFormElement
|
||||
if (!form) { return }
|
||||
const labelSaved = await clientOptions.peertubeHelpers.translate(LOC_SUCCESSFULLY_SAVED)
|
||||
const labelError = await clientOptions.peertubeHelpers.translate(LOC_ERROR)
|
||||
const enableBotCB = form.querySelector('input[name=bot]') as HTMLInputElement
|
||||
const botEnabledEl = form.querySelector('[livechat-moderation-channel-options-bot-enabled]') as HTMLElement
|
||||
const botEnabledEl = form.querySelector('[livechat-configuration-channel-options-bot-enabled]') as HTMLElement
|
||||
|
||||
const refresh: Function = () => {
|
||||
botEnabledEl.style.display = enableBotCB.checked ? 'initial' : 'none'
|
||||
@ -25,7 +25,7 @@ async function vivifyModerationChannel (
|
||||
|
||||
const submitForm: Function = async () => {
|
||||
const data = new FormData(form)
|
||||
const channelModerationOptions: ChannelModerationOptions = {
|
||||
const channelConfigurationOptions: ChannelConfigurationOptions = {
|
||||
bot: data.get('bot') === '1',
|
||||
bannedJIDs: (data.get('banned_jids')?.toString() ?? '').split(/\r?\n|\r|\n/g),
|
||||
forbiddenWords: (data.get('forbidden_words')?.toString() ?? '').split(/\r?\n|\r|\n/g)
|
||||
@ -35,16 +35,16 @@ async function vivifyModerationChannel (
|
||||
headers['content-type'] = 'application/json;charset=UTF-8'
|
||||
|
||||
const response = await fetch(
|
||||
getBaseRoute(clientOptions) + '/api/moderation/channel/' + encodeURIComponent(channelId),
|
||||
getBaseRoute(clientOptions) + '/api/configuration/channel/' + encodeURIComponent(channelId),
|
||||
{
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(channelModerationOptions)
|
||||
body: JSON.stringify(channelConfigurationOptions)
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to save moderation options.')
|
||||
throw new Error('Failed to save configuration options.')
|
||||
}
|
||||
}
|
||||
const toggleSubmit: Function = (disabled: boolean) => {
|
||||
@ -80,5 +80,5 @@ async function vivifyModerationChannel (
|
||||
}
|
||||
|
||||
export {
|
||||
vivifyModerationChannel
|
||||
vivifyConfigurationChannel
|
||||
}
|
@ -1,42 +1,42 @@
|
||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||
import { renderModerationHome } from './templates/home'
|
||||
import { renderModerationChannel } from './templates/channel'
|
||||
import { vivifyModerationChannel } from './logic/channel'
|
||||
import { renderConfigurationHome } from './templates/home'
|
||||
import { renderConfigurationChannel } from './templates/channel'
|
||||
import { vivifyConfigurationChannel } from './logic/channel'
|
||||
|
||||
/**
|
||||
* Registers stuff related to the moderation settings.
|
||||
* Registers stuff related to the user's configuration pages.
|
||||
* @param clientOptions Peertube client options
|
||||
*/
|
||||
async function registerModeration (clientOptions: RegisterClientOptions): Promise<void> {
|
||||
async function registerConfiguration (clientOptions: RegisterClientOptions): Promise<void> {
|
||||
const { peertubeHelpers, registerClientRoute, registerHook } = clientOptions
|
||||
|
||||
registerClientRoute({
|
||||
route: 'livechat/moderation',
|
||||
route: 'livechat/configuration',
|
||||
onMount: async ({ rootEl }) => {
|
||||
rootEl.innerHTML = await renderModerationHome(clientOptions)
|
||||
rootEl.innerHTML = await renderConfigurationHome(clientOptions)
|
||||
}
|
||||
})
|
||||
|
||||
registerClientRoute({
|
||||
route: 'livechat/moderation/channel',
|
||||
route: 'livechat/configuration/channel',
|
||||
onMount: async ({ rootEl }) => {
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const channelId = urlParams.get('channelId') ?? ''
|
||||
const html = await renderModerationChannel(clientOptions, channelId)
|
||||
const html = await renderConfigurationChannel(clientOptions, channelId)
|
||||
if (!html) {
|
||||
// renderModerationChannel has already used the notifier to display an error
|
||||
// renderConfigurationChannel has already used the notifier to display an error
|
||||
rootEl.innerHTML = ''
|
||||
return
|
||||
}
|
||||
rootEl.innerHTML = html
|
||||
await vivifyModerationChannel(clientOptions, rootEl, channelId)
|
||||
await vivifyConfigurationChannel(clientOptions, rootEl, channelId)
|
||||
}
|
||||
})
|
||||
|
||||
registerHook({
|
||||
target: 'filter:left-menu.links.create.result',
|
||||
handler: async (links: any) => {
|
||||
// Adding the links to livechat/moderation for logged users.
|
||||
// Adding the links to livechat/configuration for logged users.
|
||||
if (!peertubeHelpers.isLoggedIn()) { return links }
|
||||
|
||||
if (!Array.isArray(links)) { return links }
|
||||
@ -52,11 +52,11 @@ async function registerModeration (clientOptions: RegisterClientOptions): Promis
|
||||
if (!myLibraryLinks) { return links }
|
||||
if (!Array.isArray(myLibraryLinks.links)) { return links }
|
||||
|
||||
const label = await peertubeHelpers.translate(LOC_MENU_MODERATION_LABEL)
|
||||
const label = await peertubeHelpers.translate(LOC_MENU_CONFIGURATION_LABEL)
|
||||
myLibraryLinks.links.push({
|
||||
label,
|
||||
shortLabel: label,
|
||||
path: '/p/livechat/moderation',
|
||||
path: '/p/livechat/configuration',
|
||||
icon: 'live'
|
||||
})
|
||||
return links
|
||||
@ -65,5 +65,5 @@ async function registerModeration (clientOptions: RegisterClientOptions): Promis
|
||||
}
|
||||
|
||||
export {
|
||||
registerModeration
|
||||
registerConfiguration
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||
import type { ChannelModeration } from 'shared/lib/types'
|
||||
import type { ChannelConfiguration } from 'shared/lib/types'
|
||||
import { getBaseRoute } from '../../../videowatch/uri'
|
||||
// Must use require for mustache, import seems buggy.
|
||||
const Mustache = require('mustache')
|
||||
|
||||
/**
|
||||
* Renders the moderation settings page for a given channel.
|
||||
* Renders the configuration settings page for a given channel.
|
||||
* @param registerClientOptions Peertube client options
|
||||
* @param channelId The channel id
|
||||
* @returns The page content
|
||||
*/
|
||||
async function renderModerationChannel (
|
||||
async function renderConfigurationChannel (
|
||||
registerClientOptions: RegisterClientOptions,
|
||||
channelId: string
|
||||
): Promise<string | false> {
|
||||
@ -22,63 +22,65 @@ async function renderModerationChannel (
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
getBaseRoute(registerClientOptions) + '/api/moderation/channel/' + encodeURIComponent(channelId),
|
||||
getBaseRoute(registerClientOptions) + '/api/configuration/channel/' + encodeURIComponent(channelId),
|
||||
{
|
||||
method: 'GET',
|
||||
headers: peertubeHelpers.getAuthHeader()
|
||||
}
|
||||
)
|
||||
if (!response.ok) {
|
||||
throw new Error('Can\'t get channel moderation options.')
|
||||
throw new Error('Can\'t get channel configuration options.')
|
||||
}
|
||||
const channelModeration: ChannelModeration = await (response).json()
|
||||
const channelConfiguration: ChannelConfiguration = await (response).json()
|
||||
|
||||
// Basic testing that channelModeration has the correct format
|
||||
if ((typeof channelModeration !== 'object') || !channelModeration.channel) {
|
||||
throw new Error('Invalid channel moderation options.')
|
||||
// Basic testing that channelConfiguration has the correct format
|
||||
if ((typeof channelConfiguration !== 'object') || !channelConfiguration.channel) {
|
||||
throw new Error('Invalid channel configuration options.')
|
||||
}
|
||||
|
||||
const view = {
|
||||
title: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_TITLE),
|
||||
description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_DESC),
|
||||
enableBot: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_ENABLE_BOT_LABEL),
|
||||
botOptions: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_BOT_OPTIONS_TITLE),
|
||||
forbiddenWords: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_FORBIDDEN_WORDS_LABEL),
|
||||
bannedJIDs: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_BANNED_JIDS_LABEL),
|
||||
title: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE),
|
||||
description: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC),
|
||||
enableBot: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL),
|
||||
botOptions: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE),
|
||||
forbiddenWords: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL),
|
||||
bannedJIDs: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BANNED_JIDS_LABEL),
|
||||
save: await peertubeHelpers.translate(LOC_SAVE),
|
||||
cancel: await peertubeHelpers.translate(LOC_CANCEL),
|
||||
channelModeration
|
||||
channelConfiguration
|
||||
}
|
||||
|
||||
return Mustache.render(`
|
||||
<div class="margin-content">
|
||||
<h1>{{title}} {{channelModeration.channel.displayName}}</h1>
|
||||
<h1>{{title}} {{channelConfiguration.channel.displayName}}</h1>
|
||||
<p>{{description}}</p>
|
||||
<form livechat-moderation-channel-options>
|
||||
<form livechat-configuration-channel-options>
|
||||
<fieldset>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox" name="bot"
|
||||
value="1"
|
||||
{{#channelModeration.moderation.bot}} checked="checked" {{/channelModeration.moderation.bot}}
|
||||
{{#channelConfiguration.configuration.bot}}
|
||||
checked="checked"
|
||||
{{/channelConfiguration.configuration.bot}}
|
||||
/>
|
||||
{{enableBot}}
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset livechat-moderation-channel-options-bot-enabled>
|
||||
<fieldset livechat-configuration-channel-options-bot-enabled>
|
||||
<legend>{{botOptions}}</legend>
|
||||
<label>
|
||||
{{forbiddenWords}}
|
||||
<textarea name="forbidden_words">
|
||||
{{#channelModeration.moderation.forbiddenWords}}{{.}}
|
||||
{{/channelModeration.moderation.forbiddenWords}}
|
||||
{{#channelConfiguration.configuration.forbiddenWords}}{{.}}
|
||||
{{/channelConfiguration.configuration.forbiddenWords}}
|
||||
</textarea>
|
||||
</label>
|
||||
<label>
|
||||
{{bannedJIDs}}
|
||||
<textarea name="banned_jids">
|
||||
{{#channelModeration.moderation.bannedJIDs}}{{.}}
|
||||
{{/channelModeration.moderation.bannedJIDs}}
|
||||
{{#channelConfiguration.configuration.bannedJIDs}}{{.}}
|
||||
{{/channelConfiguration.configuration.bannedJIDs}}
|
||||
</textarea>
|
||||
</label>
|
||||
</fieldset>
|
||||
@ -94,5 +96,5 @@ async function renderModerationChannel (
|
||||
}
|
||||
|
||||
export {
|
||||
renderModerationChannel
|
||||
renderConfigurationChannel
|
||||
}
|
@ -3,11 +3,11 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||
const Mustache = require('mustache')
|
||||
|
||||
/**
|
||||
* Renders the livechat moderation setup home page.
|
||||
* Renders the livechat configuration setup home page.
|
||||
* @param registerClientOptions Peertube client options
|
||||
* @returns The page content
|
||||
*/
|
||||
async function renderModerationHome (registerClientOptions: RegisterClientOptions): Promise<string> {
|
||||
async function renderConfigurationHome (registerClientOptions: RegisterClientOptions): Promise<string> {
|
||||
const { peertubeHelpers } = registerClientOptions
|
||||
|
||||
try {
|
||||
@ -29,13 +29,13 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption
|
||||
}
|
||||
|
||||
for (const channel of channels.data) {
|
||||
channel.livechatModerationUri = '/p/livechat/moderation/channel?channelId=' + encodeURIComponent(channel.id)
|
||||
channel.livechatConfigurationUri = '/p/livechat/configuration/channel?channelId=' + encodeURIComponent(channel.id)
|
||||
}
|
||||
|
||||
const view = {
|
||||
title: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_TITLE),
|
||||
description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_DESC),
|
||||
please_select: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_PLEASE_SELECT),
|
||||
title: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_TITLE),
|
||||
description: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_DESC),
|
||||
please_select: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_PLEASE_SELECT),
|
||||
channels: channels.data
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption
|
||||
<ul>
|
||||
{{#channels}}
|
||||
<li>
|
||||
<a href="{{livechatModerationUri}}">
|
||||
<a href="{{livechatConfigurationUri}}">
|
||||
{{displayName}}
|
||||
</a>
|
||||
</li>
|
||||
@ -62,5 +62,5 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption
|
||||
}
|
||||
|
||||
export {
|
||||
renderModerationHome
|
||||
renderConfigurationHome
|
||||
}
|
Reference in New Issue
Block a user