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 prosodySettings = ['prosody-port']
const converseSettings = ['chat-server', 'chat-room', 'chat-bosh-uri', 'chat-ws-uri'] const converseSettings = ['chat-server', 'chat-room', 'chat-bosh-uri', 'chat-ws-uri']
const otherSettings: string[] = [] const otherSettings: string[] = []
@ -6,6 +7,18 @@ function register ({ registerSettingsScript }: RegisterOptions): void {
registerSettingsScript({ registerSettingsScript({
isSettingHidden: options => { isSettingHidden: options => {
const name = options.setting.name 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)) { if (prosodySettings.includes(name)) {
return options.formValues['chat-use-prosody'] !== true return options.formValues['chat-use-prosody'] !== true
} }

View File

@ -4,13 +4,18 @@ interface RegisterServerHookOptions {
priority?: number priority?: number
} }
type RegisterServerSettingOptionsType = 'input' | 'input-checkbox' | 'input-password' | 'input-textarea' |
'markdown-text' | 'markdown-enhanced' |
'select' | 'html'
interface RegisterServerSettingOptions { interface RegisterServerSettingOptions {
name: string name?: string
label: string label?: string
type: 'input' | 'input-checkbox' | 'input-password' | 'input-textarea' | 'markdown-text' | 'markdown-enhanced' type: RegisterServerSettingOptionsType
descriptionHTML?: string descriptionHTML?: string
default?: string | boolean default?: string | boolean
private: boolean private: boolean
options?: Array<{ value: string, label: string }>
} }
interface PluginSettingsManager { interface PluginSettingsManager {

View File

@ -1,5 +1,5 @@
import { pluginShortName } from '../helpers' import { pluginShortName } from '../helpers'
import type { ChatType } from '../settings' import type { ChatType } from '../../../shared/lib/types'
async function _migrateChatTypeSetting (options: RegisterServerOptions): Promise<void> { async function _migrateChatTypeSetting (options: RegisterServerOptions): Promise<void> {
const peertubeHelpers = options.peertubeHelpers const peertubeHelpers = options.peertubeHelpers

View File

@ -1,7 +1,6 @@
import { getBaseRouterRoute } from './helpers' import { getBaseRouterRoute } from './helpers'
import { ensureProsodyRunning, ensureProsodyNotRunning } from './prosody/ctl' import { ensureProsodyRunning, ensureProsodyNotRunning } from './prosody/ctl'
import type { ChatType } from '../../shared/lib/types'
type ChatType = 'disabled' | 'builtin-prosody' | 'builtin-converse' | 'external-uri'
function initSettings (options: RegisterServerOptions): void { function initSettings (options: RegisterServerOptions): void {
const { peertubeHelpers, registerSetting, settingsManager } = options const { peertubeHelpers, registerSetting, settingsManager } = options
@ -103,6 +102,66 @@ Before asking for help, please use this diagnostic tool:
private: false 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({ registerSetting({
name: 'chat-use-prosody', name: 'chat-use-prosody',
label: 'Use builtin Prosody XMPP Server', label: 'Use builtin Prosody XMPP Server',
@ -218,6 +277,5 @@ Before asking for help, please use this diagnostic tool:
} }
export { export {
ChatType,
initSettings 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
}