Auto viewer mode (WIP).
This commit is contained in:
parent
69380bd8e4
commit
9a4608863b
@ -82,6 +82,7 @@ interface InitConverseParams {
|
|||||||
websocketServiceUrl: string
|
websocketServiceUrl: string
|
||||||
authenticationUrl: string
|
authenticationUrl: string
|
||||||
advancedControls: boolean
|
advancedControls: boolean
|
||||||
|
autoViewerMode: boolean
|
||||||
forceReadonly: boolean | 'noscroll'
|
forceReadonly: boolean | 'noscroll'
|
||||||
noScroll: boolean
|
noScroll: boolean
|
||||||
theme: string
|
theme: string
|
||||||
@ -94,6 +95,7 @@ window.initConverse = async function initConverse ({
|
|||||||
websocketServiceUrl,
|
websocketServiceUrl,
|
||||||
authenticationUrl,
|
authenticationUrl,
|
||||||
advancedControls,
|
advancedControls,
|
||||||
|
autoViewerMode,
|
||||||
forceReadonly,
|
forceReadonly,
|
||||||
theme
|
theme
|
||||||
}: InitConverseParams) {
|
}: InitConverseParams) {
|
||||||
@ -155,7 +157,7 @@ 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']
|
whitelisted_plugins: ['livechatWindowTitlePlugin', 'livechatViewerModePlugin']
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
@ -229,6 +231,44 @@ window.initConverse = async function initConverse ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (autoViewerMode && !isAuthenticated) {
|
||||||
|
window.converse.plugins.add('livechatViewerModePlugin', {
|
||||||
|
dependencies: ['converse-muc', 'converse-muc-views'],
|
||||||
|
initialize: function () {
|
||||||
|
const _converse = this._converse
|
||||||
|
const getDefaultMUCNickname = _converse.getDefaultMUCNickname
|
||||||
|
if (!getDefaultMUCNickname) {
|
||||||
|
console.error('[livechatViewerModePlugin] getDefaultMUCNickname is not initialized.')
|
||||||
|
} else {
|
||||||
|
Object.assign(_converse, {
|
||||||
|
getDefaultMUCNickname: function (this: any): any {
|
||||||
|
return getDefaultMUCNickname.apply(this, arguments) ?? 'Anonymous ' + (new Date()).getTime().toString()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_converse.api.settings.update({
|
||||||
|
livechat_viewer_mode: true
|
||||||
|
})
|
||||||
|
|
||||||
|
function refreshViewerMode (canChat: boolean): void {
|
||||||
|
console.log('[livechatViewerModePlugin] refreshViewerMode: ' + (canChat ? 'off' : 'on'))
|
||||||
|
if (canChat) {
|
||||||
|
body?.setAttribute('livechat-viewer-mode', 'off')
|
||||||
|
} else {
|
||||||
|
body?.setAttribute('livechat-viewer-mode', 'on')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_converse.api.listen.on('livechatViewerModeSetNickname', () => refreshViewerMode(true))
|
||||||
|
_converse.api.listen.on('chatRoomInitialized', function (this: any, model: any): void {
|
||||||
|
const nick = model?.get ? model.get('nick') : ''
|
||||||
|
refreshViewerMode(nick && !/^Anonymous /.test(nick))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
window.converse.initialize(params)
|
window.converse.initialize(params)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed initializing converseJS', error)
|
console.error('Failed initializing converseJS', error)
|
||||||
|
@ -36,3 +36,18 @@ body.livechat-readonly.livechat-noscroll {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Viewer mode
|
||||||
|
.livechat-viewer-mode-nick {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
body[livechat-viewer-mode="on"] {
|
||||||
|
.livechat-viewer-mode-nick {
|
||||||
|
display: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
.livechat-viewer-mode-panel {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
40
conversejs/custom/templates/muc-bottom-panel.js
Normal file
40
conversejs/custom/templates/muc-bottom-panel.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { __ } from 'i18n'
|
||||||
|
import { _converse, api } from '@converse/headless/core'
|
||||||
|
import { html } from 'lit'
|
||||||
|
import tplMucBottomPanel from '../../src/plugins/muc-views/templates/muc-bottom-panel.js'
|
||||||
|
|
||||||
|
async function setNickname (ev, model) {
|
||||||
|
ev.preventDefault()
|
||||||
|
const nick = ev.target.nick.value.trim()
|
||||||
|
nick && await model.setNickname(nick)
|
||||||
|
_converse.api.trigger('livechatViewerModeSetNickname')
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (o) => {
|
||||||
|
if (api.settings.get('livechat_viewer_mode')) {
|
||||||
|
const model = o.model
|
||||||
|
const i18nNickname = __('Nickname')
|
||||||
|
const i18nJoin = __('Enter groupchat')
|
||||||
|
return html`
|
||||||
|
<div class="livechat-viewer-mode-nick chatroom-form-container muc-nickname-form"
|
||||||
|
@submit=${ev => setNickname(ev, model)}>
|
||||||
|
<form class="converse-form chatroom-form converse-centered-form">
|
||||||
|
<fieldset class="form-group">
|
||||||
|
<input type="text"
|
||||||
|
required="required"
|
||||||
|
name="nick"
|
||||||
|
value=""
|
||||||
|
class="form-control"
|
||||||
|
placeholder="${i18nNickname}"/>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset class="form-group">
|
||||||
|
<input type="submit" class="btn btn-primary" name="join" value="${i18nJoin}"/>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<span class="livechat-viewer-mode-panel">
|
||||||
|
${tplMucBottomPanel(o)}
|
||||||
|
</span>`
|
||||||
|
}
|
||||||
|
return tplMucBottomPanel(o)
|
||||||
|
}
|
@ -7,8 +7,7 @@ module.exports = merge(prod, {
|
|||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js'],
|
extensions: ['.js'],
|
||||||
alias: {
|
alias: {
|
||||||
// To override a template, use this syntax:
|
'./templates/muc-bottom-panel.js': path.resolve('custom/templates/muc-bottom-panel.js'),
|
||||||
// 'templates/muc_sidebar.js': path.resolve(__dirname, 'custom/templates/muc_sidebar.js')
|
|
||||||
'../../templates/background_logo.js$': path.resolve(__dirname, 'custom/templates/background_logo.js'),
|
'../../templates/background_logo.js$': path.resolve(__dirname, 'custom/templates/background_logo.js'),
|
||||||
'shared/styles/index.scss$': path.resolve(__dirname, 'custom/shared/styles/livechat.scss')
|
'shared/styles/index.scss$': path.resolve(__dirname, 'custom/shared/styles/livechat.scss')
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
websocketServiceUrl: '{{WS_SERVICE_URL}}',
|
websocketServiceUrl: '{{WS_SERVICE_URL}}',
|
||||||
authenticationUrl: '{{AUTHENTICATION_URL}}',
|
authenticationUrl: '{{AUTHENTICATION_URL}}',
|
||||||
advancedControls: '{{ADVANCEDCONTROLS}}' === 'true',
|
advancedControls: '{{ADVANCEDCONTROLS}}' === 'true',
|
||||||
|
autoViewerMode: '{{AUTOVIEWERMODE}}' === 'true',
|
||||||
theme: '{{CONVERSEJS_THEME}}',
|
theme: '{{CONVERSEJS_THEME}}',
|
||||||
forceReadonly: '{{FORCEREADONLY}}' === 'noscroll' ? '{{FORCEREADONLY}}' : '{{FORCEREADONLY}}' === 'true'
|
forceReadonly: '{{FORCEREADONLY}}' === 'noscroll' ? '{{FORCEREADONLY}}' : '{{FORCEREADONLY}}' === 'true'
|
||||||
})
|
})
|
||||||
|
@ -52,7 +52,8 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
|||||||
let boshUri: string
|
let boshUri: string
|
||||||
let wsUri: string
|
let wsUri: string
|
||||||
let authenticationUrl: string = ''
|
let authenticationUrl: string = ''
|
||||||
let advancedControls: boolean = false
|
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 forceReadonly: 'true' | 'false' | 'noscroll' = 'false'
|
||||||
let converseJSTheme: string = settings['converse-theme'] as string
|
let converseJSTheme: string = settings['converse-theme'] as string
|
||||||
if (!/^\w+$/.test(converseJSTheme)) {
|
if (!/^\w+$/.test(converseJSTheme)) {
|
||||||
@ -90,6 +91,8 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
|||||||
forceReadonly = 'true'
|
forceReadonly = 'true'
|
||||||
} else if (req.query._readonly === 'noscroll') {
|
} else if (req.query._readonly === 'noscroll') {
|
||||||
forceReadonly = 'noscroll'
|
forceReadonly = 'noscroll'
|
||||||
|
} else {
|
||||||
|
autoViewerMode = true // auto join the chat in viewer mode, if not logged in
|
||||||
}
|
}
|
||||||
} else if (chatType === 'builtin-converse') {
|
} else if (chatType === 'builtin-converse') {
|
||||||
if (!settings['chat-server']) {
|
if (!settings['chat-server']) {
|
||||||
@ -210,6 +213,7 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
|||||||
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(/{{ADVANCEDCONTROLS}}/g, advancedControls ? '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)
|
||||||
page = page.replace(/{{FORCEREADONLY}}/g, forceReadonly)
|
page = page.replace(/{{FORCEREADONLY}}/g, forceReadonly)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user