Refactoring and simplification (#122)

This commit is contained in:
John Livingston 2023-01-11 18:05:18 +01:00
parent a1bb4788c4
commit 3f47c3c65a
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
3 changed files with 27 additions and 48 deletions

View File

@ -87,7 +87,6 @@ interface InitConverseParams {
boshServiceUrl: string
websocketServiceUrl: string
authenticationUrl: string
advancedControls: boolean
autoViewerMode: boolean
forceReadonly: boolean | 'noscroll'
noScroll: boolean
@ -101,7 +100,6 @@ window.initConverse = async function initConverse ({
boshServiceUrl,
websocketServiceUrl,
authenticationUrl,
advancedControls,
autoViewerMode,
forceReadonly,
theme,
@ -177,37 +175,39 @@ window.initConverse = async function initConverse ({
persistent_store: 'sessionStorage',
show_images_inline: false, // for security reason, and to avoid bugs when image is larger that iframe
render_media: false, // for security reason, and to avoid bugs when image is larger that iframe
whitelisted_plugins: ['livechatWindowTitlePlugin', 'livechatViewerModePlugin', 'livechatDisconnectOnUnloadPlugin']
whitelisted_plugins: ['livechatWindowTitlePlugin', 'livechatViewerModePlugin', 'livechatDisconnectOnUnloadPlugin'],
show_retraction_warning: false // No need to use this warning (except if we open to external clients?)
}
// TODO: params.clear_messages_on_reconnection = true when muc_mam will be available.
let isAuthenticated: boolean = false
if (authenticationUrl !== '') {
// We are in builtin-prosody mode.
// So the user will never se the «trusted browser» checkbox.
// So we have to disable it
// (and ensure clear_cache_on_logout is true,
// see https://conversejs.org/docs/html/configuration.html#allow-user-trust-override).
params.clear_cache_on_logout = true
params.allow_user_trust_override = false
if (authenticationUrl === '') {
throw new Error('Missing authenticationUrl')
}
const auth = await authenticatedMode(authenticationUrl)
if (auth) {
params.authentication = 'login'
params.auto_login = true
params.jid = auth.jid
params.password = auth.password
if (auth.nickname) {
params.nickname = auth.nickname
} else {
params.muc_nickname_from_jid = true
}
// We dont need the keepalive. And I suppose it is related to some bugs when opening a previous chat window.
params.keepalive = false
isAuthenticated = true
// FIXME: use params.oauth_providers?
// The user will never se the «trusted browser» checkbox (that allows to save credentials).
// So we have to disable it
// (and ensure clear_cache_on_logout is true,
// see https://conversejs.org/docs/html/configuration.html#allow-user-trust-override).
params.clear_cache_on_logout = true
params.allow_user_trust_override = false
const auth = await authenticatedMode(authenticationUrl)
if (auth) {
params.authentication = 'login'
params.auto_login = true
params.jid = auth.jid
params.password = auth.password
if (auth.nickname) {
params.nickname = auth.nickname
} else {
params.muc_nickname_from_jid = true
}
// We dont need the keepalive. And I suppose it is related to some bugs when opening a previous chat window.
params.keepalive = false
isAuthenticated = true
// FIXME: use params.oauth_providers?
}
if (!isAuthenticated) {
@ -221,22 +221,6 @@ window.initConverse = async function initConverse ({
// params.muc_show_logs_before_join = true => displays muc history on top of nickname form. But it's not updated.
}
if (advancedControls) {
// with the builtin prosody, no need to use this warning (except if we open to external clients?)
params.show_retraction_warning = false
} else {
// These params are for externals XMPP servers.
// NB: because we dont know if external servers have authentication mecanism,
// we disable all moderation functionnality.
// This is also done for backward compatibility with older installations.
params.muc_disable_slash_commands = [
'admin', 'ban', 'clear', 'deop', 'destroy', 'kick',
'member', 'modtools', 'mute', 'op', 'owner', 'register',
'revoke', 'subject', 'topic', 'voice'
]
params.modtools_disable_assign = true
}
try {
window.converse.plugins.add('livechatWindowTitlePlugin', {
dependencies: ['converse-muc-views'],

View File

@ -21,7 +21,6 @@
boshServiceUrl: '{{BOSH_SERVICE_URL}}',
websocketServiceUrl: '{{WS_SERVICE_URL}}',
authenticationUrl: '{{AUTHENTICATION_URL}}',
advancedControls: '{{ADVANCEDCONTROLS}}' === 'true',
autoViewerMode: '{{AUTOVIEWERMODE}}' === 'true',
theme: '{{CONVERSEJS_THEME}}',
forceReadonly: '{{FORCEREADONLY}}' === 'noscroll' ? '{{FORCEREADONLY}}' : '{{FORCEREADONLY}}' === 'true',

View File

@ -55,8 +55,6 @@ async function initWebchatRouter (options: RegisterServerOptionsV5): Promise<Rou
wsUri = wsUri !== undefined ? wsUri + 'xmpp-websocket' : ''
let room: string
let authenticationUrl: string = ''
let advancedControls: boolean = false // auto join the chat in viewer mode, if not logged in
let autoViewerMode: boolean = false
let forceReadonly: 'true' | 'false' | 'noscroll' = 'false'
let converseJSTheme: string = settings['converse-theme'] as string
@ -86,10 +84,9 @@ async function initWebchatRouter (options: RegisterServerOptionsV5): Promise<Rou
}
}
authenticationUrl = options.peertubeHelpers.config.getWebserverUrl() +
const authenticationUrl = options.peertubeHelpers.config.getWebserverUrl() +
getBaseRouterRoute(options) +
'api/auth'
advancedControls = true
if (req.query._readonly === 'true') {
forceReadonly = 'true'
} else if (req.query._readonly === 'noscroll') {
@ -202,7 +199,6 @@ async function initWebchatRouter (options: RegisterServerOptionsV5): Promise<Rou
page = page.replace(/{{BOSH_SERVICE_URL}}/g, boshUri)
page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri)
page = page.replace(/{{AUTHENTICATION_URL}}/g, authenticationUrl)
page = page.replace(/{{ADVANCEDCONTROLS}}/g, advancedControls ? 'true' : 'false')
page = page.replace(/{{AUTOVIEWERMODE}}/g, autoViewerMode ? 'true' : 'false')
page = page.replace(/{{CONVERSEJS_THEME}}/g, converseJSTheme)
page = page.replace(/{{CONVERSEJS_AUTOCOLORS}}/g, autocolorsStyles)