Refactoring and simplification (#122)
This commit is contained in:
parent
a1bb4788c4
commit
3f47c3c65a
@ -87,7 +87,6 @@ interface InitConverseParams {
|
|||||||
boshServiceUrl: string
|
boshServiceUrl: string
|
||||||
websocketServiceUrl: string
|
websocketServiceUrl: string
|
||||||
authenticationUrl: string
|
authenticationUrl: string
|
||||||
advancedControls: boolean
|
|
||||||
autoViewerMode: boolean
|
autoViewerMode: boolean
|
||||||
forceReadonly: boolean | 'noscroll'
|
forceReadonly: boolean | 'noscroll'
|
||||||
noScroll: boolean
|
noScroll: boolean
|
||||||
@ -101,7 +100,6 @@ window.initConverse = async function initConverse ({
|
|||||||
boshServiceUrl,
|
boshServiceUrl,
|
||||||
websocketServiceUrl,
|
websocketServiceUrl,
|
||||||
authenticationUrl,
|
authenticationUrl,
|
||||||
advancedControls,
|
|
||||||
autoViewerMode,
|
autoViewerMode,
|
||||||
forceReadonly,
|
forceReadonly,
|
||||||
theme,
|
theme,
|
||||||
@ -177,37 +175,39 @@ window.initConverse = async function initConverse ({
|
|||||||
persistent_store: 'sessionStorage',
|
persistent_store: 'sessionStorage',
|
||||||
show_images_inline: false, // for security reason, and to avoid bugs when image is larger that iframe
|
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
|
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.
|
// TODO: params.clear_messages_on_reconnection = true when muc_mam will be available.
|
||||||
|
|
||||||
let isAuthenticated: boolean = false
|
let isAuthenticated: boolean = false
|
||||||
if (authenticationUrl !== '') {
|
if (authenticationUrl === '') {
|
||||||
// We are in builtin-prosody mode.
|
throw new Error('Missing authenticationUrl')
|
||||||
// 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
|
|
||||||
|
|
||||||
const auth = await authenticatedMode(authenticationUrl)
|
// The user will never se the «trusted browser» checkbox (that allows to save credentials).
|
||||||
if (auth) {
|
// So we have to disable it
|
||||||
params.authentication = 'login'
|
// (and ensure clear_cache_on_logout is true,
|
||||||
params.auto_login = true
|
// see https://conversejs.org/docs/html/configuration.html#allow-user-trust-override).
|
||||||
params.jid = auth.jid
|
params.clear_cache_on_logout = true
|
||||||
params.password = auth.password
|
params.allow_user_trust_override = false
|
||||||
if (auth.nickname) {
|
|
||||||
params.nickname = auth.nickname
|
const auth = await authenticatedMode(authenticationUrl)
|
||||||
} else {
|
if (auth) {
|
||||||
params.muc_nickname_from_jid = true
|
params.authentication = 'login'
|
||||||
}
|
params.auto_login = true
|
||||||
// We dont need the keepalive. And I suppose it is related to some bugs when opening a previous chat window.
|
params.jid = auth.jid
|
||||||
params.keepalive = false
|
params.password = auth.password
|
||||||
isAuthenticated = true
|
if (auth.nickname) {
|
||||||
// FIXME: use params.oauth_providers?
|
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) {
|
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.
|
// 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 {
|
try {
|
||||||
window.converse.plugins.add('livechatWindowTitlePlugin', {
|
window.converse.plugins.add('livechatWindowTitlePlugin', {
|
||||||
dependencies: ['converse-muc-views'],
|
dependencies: ['converse-muc-views'],
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
boshServiceUrl: '{{BOSH_SERVICE_URL}}',
|
boshServiceUrl: '{{BOSH_SERVICE_URL}}',
|
||||||
websocketServiceUrl: '{{WS_SERVICE_URL}}',
|
websocketServiceUrl: '{{WS_SERVICE_URL}}',
|
||||||
authenticationUrl: '{{AUTHENTICATION_URL}}',
|
authenticationUrl: '{{AUTHENTICATION_URL}}',
|
||||||
advancedControls: '{{ADVANCEDCONTROLS}}' === 'true',
|
|
||||||
autoViewerMode: '{{AUTOVIEWERMODE}}' === 'true',
|
autoViewerMode: '{{AUTOVIEWERMODE}}' === 'true',
|
||||||
theme: '{{CONVERSEJS_THEME}}',
|
theme: '{{CONVERSEJS_THEME}}',
|
||||||
forceReadonly: '{{FORCEREADONLY}}' === 'noscroll' ? '{{FORCEREADONLY}}' : '{{FORCEREADONLY}}' === 'true',
|
forceReadonly: '{{FORCEREADONLY}}' === 'noscroll' ? '{{FORCEREADONLY}}' : '{{FORCEREADONLY}}' === 'true',
|
||||||
|
@ -55,8 +55,6 @@ async function initWebchatRouter (options: RegisterServerOptionsV5): Promise<Rou
|
|||||||
wsUri = wsUri !== undefined ? wsUri + 'xmpp-websocket' : ''
|
wsUri = wsUri !== undefined ? wsUri + 'xmpp-websocket' : ''
|
||||||
|
|
||||||
let room: string
|
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 autoViewerMode: boolean = false
|
||||||
let forceReadonly: 'true' | 'false' | 'noscroll' = 'false'
|
let forceReadonly: 'true' | 'false' | 'noscroll' = 'false'
|
||||||
let converseJSTheme: string = settings['converse-theme'] as string
|
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) +
|
getBaseRouterRoute(options) +
|
||||||
'api/auth'
|
'api/auth'
|
||||||
advancedControls = true
|
|
||||||
if (req.query._readonly === 'true') {
|
if (req.query._readonly === 'true') {
|
||||||
forceReadonly = 'true'
|
forceReadonly = 'true'
|
||||||
} else if (req.query._readonly === 'noscroll') {
|
} 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(/{{BOSH_SERVICE_URL}}/g, boshUri)
|
||||||
page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri)
|
page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri)
|
||||||
page = page.replace(/{{AUTHENTICATION_URL}}/g, authenticationUrl)
|
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(/{{AUTOVIEWERMODE}}/g, autoViewerMode ? 'true' : 'false')
|
||||||
page = page.replace(/{{CONVERSEJS_THEME}}/g, converseJSTheme)
|
page = page.replace(/{{CONVERSEJS_THEME}}/g, converseJSTheme)
|
||||||
page = page.replace(/{{CONVERSEJS_AUTOCOLORS}}/g, autocolorsStyles)
|
page = page.replace(/{{CONVERSEJS_AUTOCOLORS}}/g, autocolorsStyles)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user