From 07ab2a80ed71e025ed2bc40e3490cb0b071f0e69 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 10 May 2021 21:04:04 +0200 Subject: [PATCH] Settings: hide unnecessary settings depending on webchat mode (requires Peertube 3.2.0). --- CHANGELOG.md | 1 + client/@types/peertube.d.ts | 17 ++++++++++++++ client/admin-plugin-client-plugin.ts | 33 ++++++++++++++++++++++++++++ package.json | 6 +++++ webpack.config.js | 3 ++- 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 client/admin-plugin-client-plugin.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index b0345d5e..42d98346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Don't display webchat when viewing a playlist (requires Peertube 3.2.0). * Better default values for settings. +* Settings: hide unnecessary settings depending on webchat mode (requires Peertube 3.2.0). ### Fixes diff --git a/client/@types/peertube.d.ts b/client/@types/peertube.d.ts index 05f60b61..6af56384 100644 --- a/client/@types/peertube.d.ts +++ b/client/@types/peertube.d.ts @@ -29,9 +29,26 @@ interface RegisterClientHelpers { translate: (toTranslate: string) => Promise } +interface RegisterClientFormFieldOptions { + name: string + label: string + type: 'input' | 'input-checkbox' | 'input-password' | 'input-textarea' | 'markdown-text' | 'markdown-enhanced' + descriptionHTML?: string + default?: string | boolean + private: boolean +} +interface RegisterClientSettingsScript { + isSettingHidden: (options: { + setting: RegisterClientFormFieldOptions + formValues: { [name: string]: any } + }) => boolean +} + interface RegisterOptions { registerHook: (options: RegisterClientHookOptions) => void peertubeHelpers: RegisterClientHelpers + // registerSettingsScript comes with Peertube 3.2.0. + registerSettingsScript?: (options: RegisterClientSettingsScript) => void } interface Video { diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts new file mode 100644 index 00000000..ceedbf42 --- /dev/null +++ b/client/admin-plugin-client-plugin.ts @@ -0,0 +1,33 @@ +const prosodySettings = ['prosody-port'] +const converseSettings = ['chat-server', 'chat-room', 'chat-bosh-uri', 'chat-ws-uri'] +const otherSettings: string[] = [] + +function register ({ registerSettingsScript }: RegisterOptions): void { + if (registerSettingsScript) { + registerSettingsScript({ + isSettingHidden: options => { + const name = options.setting.name + if (prosodySettings.includes(name)) { + return options.formValues['chat-use-prosody'] !== true + } + if (name === 'chat-use-builtin') { + return options.formValues['chat-use-prosody'] === true + } + if (converseSettings.includes(name)) { + return options.formValues['chat-use-builtin'] !== true || options.formValues['chat-use-prosody'] === true + } + if (name === 'chat-uri') { + return options.formValues['chat-use-prosody'] === true || options.formValues['chat-use-builtin'] === true + } + if (otherSettings.includes(name)) { + return options.formValues['chat-use-builtin'] === true || options.formValues['chat-use-prosody'] === true + } + return false + } + }) + } +} + +export { + register +} diff --git a/package.json b/package.json index 429d21cd..f2a909bb 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,12 @@ "scopes": [ "common" ] + }, + { + "script": "dist/client/admin-plugin-client-plugin.js", + "scopes": [ + "admin-plugin" + ] } ], "css": [ diff --git a/webpack.config.js b/webpack.config.js index 1362d4a9..e7811923 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,8 @@ const packagejson = require('./package.json') const clientFiles = [ 'common-client-plugin', - 'videowatch-client-plugin' + 'videowatch-client-plugin', + 'admin-plugin-client-plugin' ] let config = clientFiles.map(f => ({