Moderation configuration screen: WIP.
This commit is contained in:
		
							
								
								
									
										6
									
								
								client/@types/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								client/@types/global.d.ts
									
									
									
									
										vendored
									
									
								
							@ -31,9 +31,15 @@ declare const LOC_WEB: string
 | 
				
			|||||||
declare const LOC_CONNECT_USING_XMPP: string
 | 
					declare const LOC_CONNECT_USING_XMPP: string
 | 
				
			||||||
declare const LOC_CONNECT_USING_XMPP_HELP: string
 | 
					declare const LOC_CONNECT_USING_XMPP_HELP: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare const LOC_SAVE: string
 | 
				
			||||||
 | 
					declare const LOC_CANCEL: string
 | 
				
			||||||
declare const LOC_MENU_MODERATION_LABEL: string
 | 
					declare const LOC_MENU_MODERATION_LABEL: string
 | 
				
			||||||
declare const LOC_LIVECHAT_MODERATION_TITLE: string
 | 
					declare const LOC_LIVECHAT_MODERATION_TITLE: string
 | 
				
			||||||
declare const LOC_LIVECHAT_MODERATION_DESC: string
 | 
					declare const LOC_LIVECHAT_MODERATION_DESC: string
 | 
				
			||||||
declare const LOC_LIVECHAT_MODERATION_PLEASE_SELECT: string
 | 
					declare const LOC_LIVECHAT_MODERATION_PLEASE_SELECT: string
 | 
				
			||||||
declare const LOC_LIVECHAT_MODERATION_CHANNEL_TITLE: string
 | 
					declare const LOC_LIVECHAT_MODERATION_CHANNEL_TITLE: string
 | 
				
			||||||
declare const LOC_LIVECHAT_MODERATION_CHANNEL_DESC: string
 | 
					declare const LOC_LIVECHAT_MODERATION_CHANNEL_DESC: string
 | 
				
			||||||
 | 
					declare const LOC_LIVECHAT_MODERATION_CHANNEL_ENABLE_BOT_LABEL: string
 | 
				
			||||||
 | 
					declare const LOC_LIVECHAT_MODERATION_CHANNEL_BOT_OPTIONS_TITLE: string
 | 
				
			||||||
 | 
					declare const LOC_LIVECHAT_MODERATION_CHANNEL_FORBIDDEN_WORDS_LABEL: string
 | 
				
			||||||
 | 
					declare const LOC_LIVECHAT_MODERATION_CHANNEL_BANNED_JIDS_LABEL: string
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										29
									
								
								client/common/moderation/logic/channel.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								client/common/moderation/logic/channel.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					import type { RegisterClientOptions } from '@peertube/peertube-types/client'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Adds the front-end logic on the generated html for the channel moderation options.
 | 
				
			||||||
 | 
					 * @param clientOptions Peertube client options
 | 
				
			||||||
 | 
					 * @param rootEl The root element in which the template was rendered
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					async function vivifyModerationChannel (
 | 
				
			||||||
 | 
					  clientOptions: RegisterClientOptions,
 | 
				
			||||||
 | 
					  rootEl: HTMLElement
 | 
				
			||||||
 | 
					): Promise<void> {
 | 
				
			||||||
 | 
					  const form = rootEl.querySelector('form[livechat-moderation-channel-options]') as HTMLFormElement
 | 
				
			||||||
 | 
					  if (!form) { return }
 | 
				
			||||||
 | 
					  const enableBotCB = form.querySelector('input[name=bot]') as HTMLInputElement
 | 
				
			||||||
 | 
					  const botEnabledEl = form.querySelector('[livechat-moderation-channel-options-bot-enabled]') as HTMLElement
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const refresh: Function = () => {
 | 
				
			||||||
 | 
					    botEnabledEl.style.display = enableBotCB.checked ? 'initial' : 'none'
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  enableBotCB.onclick = () => refresh()
 | 
				
			||||||
 | 
					  form.onsubmit = () => false
 | 
				
			||||||
 | 
					  form.onreset = () => refresh()
 | 
				
			||||||
 | 
					  refresh()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export {
 | 
				
			||||||
 | 
					  vivifyModerationChannel
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
 | 
					import type { RegisterClientOptions } from '@peertube/peertube-types/client'
 | 
				
			||||||
import { renderModerationHome } from './templates/home'
 | 
					import { renderModerationHome } from './templates/home'
 | 
				
			||||||
import { renderModerationChannel } from './templates/channel'
 | 
					import { renderModerationChannel } from './templates/channel'
 | 
				
			||||||
 | 
					import { vivifyModerationChannel } from './logic/channel'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Registers stuff related to the moderation settings.
 | 
					 * Registers stuff related to the moderation settings.
 | 
				
			||||||
@ -21,7 +22,14 @@ async function registerModeration (clientOptions: RegisterClientOptions): Promis
 | 
				
			|||||||
    onMount: async ({ rootEl }) => {
 | 
					    onMount: async ({ rootEl }) => {
 | 
				
			||||||
      const urlParams = new URLSearchParams(window.location.search)
 | 
					      const urlParams = new URLSearchParams(window.location.search)
 | 
				
			||||||
      const channelId = urlParams.get('channelId') ?? ''
 | 
					      const channelId = urlParams.get('channelId') ?? ''
 | 
				
			||||||
      rootEl.innerHTML = await renderModerationChannel(clientOptions, channelId)
 | 
					      const html = await renderModerationChannel(clientOptions, channelId)
 | 
				
			||||||
 | 
					      if (!html) {
 | 
				
			||||||
 | 
					        // renderModerationChannel has already used the notifier to display an error
 | 
				
			||||||
 | 
					        rootEl.innerHTML = ''
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      rootEl.innerHTML = html
 | 
				
			||||||
 | 
					      await vivifyModerationChannel(clientOptions, rootEl)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ const Mustache = require('mustache')
 | 
				
			|||||||
async function renderModerationChannel (
 | 
					async function renderModerationChannel (
 | 
				
			||||||
  registerClientOptions: RegisterClientOptions,
 | 
					  registerClientOptions: RegisterClientOptions,
 | 
				
			||||||
  channelId: string
 | 
					  channelId: string
 | 
				
			||||||
): Promise<string> {
 | 
					): Promise<string | false> {
 | 
				
			||||||
  const { peertubeHelpers } = registerClientOptions
 | 
					  const { peertubeHelpers } = registerClientOptions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
@ -35,16 +35,52 @@ async function renderModerationChannel (
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const view = {
 | 
					    const view = {
 | 
				
			||||||
      title:
 | 
					      title: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_TITLE),
 | 
				
			||||||
        await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_TITLE) +
 | 
					      description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_DESC),
 | 
				
			||||||
        ' ' + channelModerationOptions.channel.displayName,
 | 
					      enableBot: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_ENABLE_BOT_LABEL),
 | 
				
			||||||
      description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_DESC)
 | 
					      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),
 | 
				
			||||||
 | 
					      save: await peertubeHelpers.translate(LOC_SAVE),
 | 
				
			||||||
 | 
					      cancel: await peertubeHelpers.translate(LOC_CANCEL),
 | 
				
			||||||
 | 
					      channelModerationOptions
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return Mustache.render(`
 | 
					    return Mustache.render(`
 | 
				
			||||||
      <div class="margin-content">
 | 
					      <div class="margin-content">
 | 
				
			||||||
        <h1>{{title}}</h1>
 | 
					        <h1>{{title}} {{channelModerationOptions.channel.displayName}}</h1>
 | 
				
			||||||
        <p>{{description}}</p>
 | 
					        <p>{{description}}</p>
 | 
				
			||||||
 | 
					        <form livechat-moderation-channel-options>
 | 
				
			||||||
 | 
					          <fieldset>
 | 
				
			||||||
 | 
					            <label>
 | 
				
			||||||
 | 
					              <input
 | 
				
			||||||
 | 
					                type="checkbox" name="bot"
 | 
				
			||||||
 | 
					                value="1"
 | 
				
			||||||
 | 
					                {{#channelModerationOptions.bot}} checked="checked" {{/channelModerationOptions.bot}}
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
 | 
					              {{enableBot}}
 | 
				
			||||||
 | 
					            </label>
 | 
				
			||||||
 | 
					          </fieldset>
 | 
				
			||||||
 | 
					          <fieldset livechat-moderation-channel-options-bot-enabled>
 | 
				
			||||||
 | 
					            <legend>{{botOptions}}</legend>
 | 
				
			||||||
 | 
					            <label>
 | 
				
			||||||
 | 
					              {{forbiddenWords}}
 | 
				
			||||||
 | 
					<textarea name="forbidden_words">
 | 
				
			||||||
 | 
					{{#channelModerationOptions.forbiddenWords}}{{.}}
 | 
				
			||||||
 | 
					{{/channelModerationOptions.forbiddenWords}}
 | 
				
			||||||
 | 
					</textarea>
 | 
				
			||||||
 | 
					            </label>
 | 
				
			||||||
 | 
					            <label>
 | 
				
			||||||
 | 
					              {{bannedJIDs}}
 | 
				
			||||||
 | 
					<textarea name="banned_jids">
 | 
				
			||||||
 | 
					{{#channelModerationOptions.bannedJIDs}}{{.}}
 | 
				
			||||||
 | 
					{{/channelModerationOptions.bannedJIDs}}
 | 
				
			||||||
 | 
					</textarea>
 | 
				
			||||||
 | 
					            </label>
 | 
				
			||||||
 | 
					          </fieldset>
 | 
				
			||||||
 | 
					          <input type="submit" value="{{save}}" />
 | 
				
			||||||
 | 
					          <input type="reset" value="{{cancel}}" />
 | 
				
			||||||
 | 
					        </form>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    `, view) as string
 | 
					    `, view) as string
 | 
				
			||||||
  } catch (err: any) {
 | 
					  } catch (err: any) {
 | 
				
			||||||
 | 
				
			|||||||
@ -279,9 +279,16 @@ prosody_components_list_description: |
 | 
				
			|||||||
    <li>Only use alphanumeric characters in the secret passphrase (use at least 15 characters).</li>
 | 
					    <li>Only use alphanumeric characters in the secret passphrase (use at least 15 characters).</li>
 | 
				
			||||||
  </ul>
 | 
					  </ul>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					save: "Save"
 | 
				
			||||||
 | 
					cancel: "Cancel"
 | 
				
			||||||
menu_moderation_label: "Chatrooms"
 | 
					menu_moderation_label: "Chatrooms"
 | 
				
			||||||
livechat_moderation_title: "Configure your live's chatrooms moderation policies"
 | 
					livechat_moderation_title: "Configure your live's chatrooms moderation policies"
 | 
				
			||||||
livechat_moderation_desc: "Here you can configure some advanced options for chatrooms associated to your live streams."
 | 
					livechat_moderation_desc: "Here you can configure some advanced options for chatrooms associated to your live streams."
 | 
				
			||||||
livechat_moderation_please_select: "Please select bellow one of your channel, to setup its chatting options."
 | 
					livechat_moderation_please_select: "Please select bellow one of your channel, to setup its chatting options."
 | 
				
			||||||
livechat_moderation_channel_title: "Moderation policies for channel:"
 | 
					livechat_moderation_channel_title: "Moderation policies for channel:"
 | 
				
			||||||
livechat_moderation_channel_desc: "You can setup here your moderation policies for this channel."
 | 
					livechat_moderation_channel_desc: "You can setup here your moderation policies for this channel."
 | 
				
			||||||
 | 
					livechat_moderation_channel_enable_bot_label: "Enable moderation bot"
 | 
				
			||||||
 | 
					livechat_moderation_channel_bot_options_title: "Moderation bot options"
 | 
				
			||||||
 | 
					livechat_moderation_channel_forbidden_words_label: "Forbidden words or expressions"
 | 
				
			||||||
 | 
					livechat_moderation_channel_banned_jids_label: "Banned users and patterns"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -47,7 +47,10 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise
 | 
				
			|||||||
          id: channelInfos.id,
 | 
					          id: channelInfos.id,
 | 
				
			||||||
          name: channelInfos.name,
 | 
					          name: channelInfos.name,
 | 
				
			||||||
          displayName: channelInfos.displayName
 | 
					          displayName: channelInfos.displayName
 | 
				
			||||||
        }
 | 
					        },
 | 
				
			||||||
 | 
					        bot: false,
 | 
				
			||||||
 | 
					        forbiddenWords: [],
 | 
				
			||||||
 | 
					        bannedJIDs: []
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      res.status(200)
 | 
					      res.status(200)
 | 
				
			||||||
      res.json(result)
 | 
					      res.json(result)
 | 
				
			||||||
 | 
				
			|||||||
@ -52,6 +52,9 @@ interface ChannelModerationOptions {
 | 
				
			|||||||
    name: string
 | 
					    name: string
 | 
				
			||||||
    displayName: string
 | 
					    displayName: string
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  bot: boolean
 | 
				
			||||||
 | 
					  forbiddenWords: string[]
 | 
				
			||||||
 | 
					  bannedJIDs: string[]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type {
 | 
					export type {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user