diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index c9964987..e98e769c 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -1,3 +1,4 @@ +import type { ChatType } from 'shared/lib/types' const prosodySettings = ['prosody-port'] const converseSettings = ['chat-server', 'chat-room', 'chat-bosh-uri', 'chat-ws-uri'] const otherSettings: string[] = [] @@ -6,6 +7,18 @@ function register ({ registerSettingsScript }: RegisterOptions): void { registerSettingsScript({ isSettingHidden: options => { const name = options.setting.name + switch (name) { + case 'chat-type-help-disabled': + return options.formValues['chat-type'] !== ('disabled' as ChatType) + case 'chat-type-help-builtin-prosody': + return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType) + case 'chat-type-help-builtin-converse': + return options.formValues['chat-type'] !== ('builtin-converse' as ChatType) + case 'chat-type-help-external-uri': + return options.formValues['chat-type'] !== ('external-uri' as ChatType) + } + + // TODO: rewrite the code bellow. if (prosodySettings.includes(name)) { return options.formValues['chat-use-prosody'] !== true } diff --git a/server/@types/peertube.d.ts b/server/@types/peertube.d.ts index d9a78310..00fd80bd 100644 --- a/server/@types/peertube.d.ts +++ b/server/@types/peertube.d.ts @@ -4,13 +4,18 @@ interface RegisterServerHookOptions { priority?: number } +type RegisterServerSettingOptionsType = 'input' | 'input-checkbox' | 'input-password' | 'input-textarea' | +'markdown-text' | 'markdown-enhanced' | +'select' | 'html' + interface RegisterServerSettingOptions { - name: string - label: string - type: 'input' | 'input-checkbox' | 'input-password' | 'input-textarea' | 'markdown-text' | 'markdown-enhanced' + name?: string + label?: string + type: RegisterServerSettingOptionsType descriptionHTML?: string default?: string | boolean private: boolean + options?: Array<{ value: string, label: string }> } interface PluginSettingsManager { diff --git a/server/lib/migration/settings.ts b/server/lib/migration/settings.ts index 10378955..a6d9c337 100644 --- a/server/lib/migration/settings.ts +++ b/server/lib/migration/settings.ts @@ -1,5 +1,5 @@ import { pluginShortName } from '../helpers' -import type { ChatType } from '../settings' +import type { ChatType } from '../../../shared/lib/types' async function _migrateChatTypeSetting (options: RegisterServerOptions): Promise { const peertubeHelpers = options.peertubeHelpers diff --git a/server/lib/settings.ts b/server/lib/settings.ts index 26d370eb..863228c7 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -1,7 +1,6 @@ import { getBaseRouterRoute } from './helpers' import { ensureProsodyRunning, ensureProsodyNotRunning } from './prosody/ctl' - -type ChatType = 'disabled' | 'builtin-prosody' | 'builtin-converse' | 'external-uri' +import type { ChatType } from '../../shared/lib/types' function initSettings (options: RegisterServerOptions): void { const { peertubeHelpers, registerSetting, settingsManager } = options @@ -103,6 +102,66 @@ Before asking for help, please use this diagnostic tool: private: false }) + registerSetting({ + name: 'chat-type', + label: 'Webchat mode', + type: 'select', + default: 'disabled' as ChatType, + private: false, + options: [ + { value: 'disabled', label: 'Disabled' }, + { value: 'builtin-prosody', label: 'Prosody server controlled by Peertube (recommended)' }, + { value: 'builtin-converse', label: 'Connect to an existing XMPP server with ConverseJS' }, + { value: 'external-uri', label: 'Use an external webchat' } + ] as Array<{value: ChatType, label: string}>, + descriptionHTML: 'Please choose the webchat mode you want to use.' + }) + + registerSetting({ + name: 'chat-type-help-disabled', + type: 'html', + descriptionHTML: 'The chat is disabled.', + private: true + }) + registerSetting({ + name: 'chat-type-help-builtin-prosody', + type: 'html', + label: 'Prosody server controlled by Peertube (recommended)', + descriptionHTML: ` + With this mode, the Peertube server will control a local Prosody XMPP server. + Please read the documentation.`, + private: true + }) + registerSetting({ + name: 'chat-type-help-builtin-converse', + type: 'html', + label: 'Connect to an existing XMPP server with ConverseJS', + descriptionHTML: ` + With this mode, you can connect to an existing XMPP server, with anonymous authentication and rooms enabled. + Please read the + documentation.`, + private: true + }) + registerSetting({ + name: 'chat-type-help-external-uri', + type: 'html', + label: 'Use an external webchat', + descriptionHTML: ` + With this mode, you can use any external webchat that can be included in an iframe. + Please read the + documentation.`, + private: true + }) + registerSetting({ name: 'chat-use-prosody', label: 'Use builtin Prosody XMPP Server', @@ -218,6 +277,5 @@ Before asking for help, please use this diagnostic tool: } export { - ChatType, initSettings } diff --git a/shared/lib/types.ts b/shared/lib/types.ts new file mode 100644 index 00000000..f9892324 --- /dev/null +++ b/shared/lib/types.ts @@ -0,0 +1,5 @@ +type ChatType = 'disabled' | 'builtin-prosody' | 'builtin-converse' | 'external-uri' + +export { + ChatType +}