Settings: hide unnecessary settings depending on webchat mode (requires Peertube 3.2.0).

This commit is contained in:
John Livingston 2021-05-10 21:04:04 +02:00
parent df5f8e0f73
commit 07ab2a80ed
5 changed files with 59 additions and 1 deletions

View File

@ -6,6 +6,7 @@
* Don't display webchat when viewing a playlist (requires Peertube 3.2.0). * Don't display webchat when viewing a playlist (requires Peertube 3.2.0).
* Better default values for settings. * Better default values for settings.
* Settings: hide unnecessary settings depending on webchat mode (requires Peertube 3.2.0).
### Fixes ### Fixes

View File

@ -29,9 +29,26 @@ interface RegisterClientHelpers {
translate: (toTranslate: string) => Promise<string> translate: (toTranslate: string) => Promise<string>
} }
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 { interface RegisterOptions {
registerHook: (options: RegisterClientHookOptions) => void registerHook: (options: RegisterClientHookOptions) => void
peertubeHelpers: RegisterClientHelpers peertubeHelpers: RegisterClientHelpers
// registerSettingsScript comes with Peertube 3.2.0.
registerSettingsScript?: (options: RegisterClientSettingsScript) => void
} }
interface Video { interface Video {

View File

@ -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
}

View File

@ -16,6 +16,12 @@
"scopes": [ "scopes": [
"common" "common"
] ]
},
{
"script": "dist/client/admin-plugin-client-plugin.js",
"scopes": [
"admin-plugin"
]
} }
], ],
"css": [ "css": [

View File

@ -7,7 +7,8 @@ const packagejson = require('./package.json')
const clientFiles = [ const clientFiles = [
'common-client-plugin', 'common-client-plugin',
'videowatch-client-plugin' 'videowatch-client-plugin',
'admin-plugin-client-plugin'
] ]
let config = clientFiles.map(f => ({ let config = clientFiles.map(f => ({