2021-06-02 17:54:04 +00:00
|
|
|
import type { ChatType } from 'shared/lib/types'
|
2021-05-10 19:04:04 +00:00
|
|
|
|
2021-06-11 12:30:46 +00:00
|
|
|
interface ActionPluginSettingsParams {
|
|
|
|
npmName: string
|
|
|
|
}
|
|
|
|
|
|
|
|
function register ({ registerHook, registerSettingsScript, peertubeHelpers }: RegisterOptions): void {
|
|
|
|
function getBaseRoute (): string {
|
|
|
|
// NB: this will come with Peertube > 3.2.1 (3.3.0?)
|
|
|
|
if (peertubeHelpers.getBaseRouterRoute) {
|
|
|
|
return peertubeHelpers.getBaseRouterRoute()
|
|
|
|
}
|
|
|
|
// We are guessing the route with the correct plugin version with this trick:
|
|
|
|
const staticBase = peertubeHelpers.getBaseStaticRoute()
|
|
|
|
// we can't use '/plugins/livechat/router', because the loaded html page needs correct relative paths.
|
|
|
|
return staticBase.replace(/\/static.*$/, '/router')
|
|
|
|
}
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'action:admin-plugin-settings.init',
|
|
|
|
handler: ({ npmName }: ActionPluginSettingsParams) => {
|
|
|
|
if (npmName !== PLUGIN_CHAT_PACKAGE_NAME) {
|
|
|
|
console.log(`[peertube-plugin-livechat] Settings for ${npmName}, not ${PLUGIN_CHAT_PACKAGE_NAME}. Returning.`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log('[peertube-plugin-livechat] Initializing diagnostic button')
|
|
|
|
const diagButtons = document.querySelectorAll('.peertube-plugin-livechat-launch-diagnostic')
|
|
|
|
diagButtons.forEach(diagButton => {
|
|
|
|
if (diagButton.hasAttribute('href')) { return }
|
|
|
|
// TODO: use a modal instead of a target=_blank
|
|
|
|
diagButton.setAttribute('href', getBaseRoute() + '/settings/diagnostic')
|
|
|
|
diagButton.setAttribute('target', '_blank')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2021-06-02 10:32:00 +00:00
|
|
|
registerSettingsScript({
|
|
|
|
isSettingHidden: options => {
|
|
|
|
const name = options.setting.name
|
2021-06-02 17:54:04 +00:00
|
|
|
switch (name) {
|
|
|
|
case 'chat-type-help-disabled':
|
|
|
|
return options.formValues['chat-type'] !== ('disabled' as ChatType)
|
2021-06-03 09:46:11 +00:00
|
|
|
case 'prosody-port':
|
2021-06-22 11:23:01 +00:00
|
|
|
case 'prosody-peertube-uri':
|
2021-06-02 17:54:04 +00:00
|
|
|
case 'chat-type-help-builtin-prosody':
|
2021-07-13 15:40:29 +00:00
|
|
|
case 'prosody-advanced':
|
|
|
|
case 'prosody-c2s':
|
2021-06-02 17:54:04 +00:00
|
|
|
return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType)
|
2021-07-13 15:40:29 +00:00
|
|
|
case 'prosody-c2s-port':
|
|
|
|
return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType) || options.formValues['prosody-c2s'] === false
|
2021-06-03 09:46:11 +00:00
|
|
|
case 'chat-server':
|
|
|
|
case 'chat-room':
|
|
|
|
case 'chat-bosh-uri':
|
|
|
|
case 'chat-ws-uri':
|
2021-06-02 17:54:04 +00:00
|
|
|
case 'chat-type-help-builtin-converse':
|
|
|
|
return options.formValues['chat-type'] !== ('builtin-converse' as ChatType)
|
2021-06-03 09:46:11 +00:00
|
|
|
case 'chat-uri':
|
2021-06-02 17:54:04 +00:00
|
|
|
case 'chat-type-help-external-uri':
|
|
|
|
return options.formValues['chat-type'] !== ('external-uri' as ChatType)
|
2021-06-03 09:46:11 +00:00
|
|
|
case 'chat-style':
|
|
|
|
return options.formValues['chat-type'] === 'disabled'
|
2021-06-03 10:20:19 +00:00
|
|
|
case 'chat-only-locals-warning':
|
|
|
|
return options.formValues['chat-only-locals'] === true
|
2021-06-08 16:08:58 +00:00
|
|
|
case 'chat-per-live-video-warning':
|
|
|
|
return !(options.formValues['chat-all-lives'] === true && options.formValues['chat-per-live-video'] === true)
|
2021-06-02 17:54:04 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 10:32:00 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
2021-05-10 19:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
register
|
|
|
|
}
|