Adding the chat-type field in the settings.

This commit is contained in:
John Livingston 2021-06-02 19:54:04 +02:00
parent 11d79fc611
commit 36146ee76c
5 changed files with 88 additions and 7 deletions

View File

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

View File

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

View File

@ -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<void> {
const peertubeHelpers = options.peertubeHelpers

View File

@ -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 <a
href="https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/documentation/prosody.md"
target="_blank"
>documentation.</a>`,
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
<a
href="https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/documentation/conversejs.md"
target="_blank"
>documentation</a>.`,
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
<a
href="https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/documentation/external.md"
target="_blank"
>documentation</a>.`,
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
}

5
shared/lib/types.ts Normal file
View File

@ -0,0 +1,5 @@
type ChatType = 'disabled' | 'builtin-prosody' | 'builtin-converse' | 'external-uri'
export {
ChatType
}