Fix reconnection when logged in.

This commit is contained in:
John Livingston 2024-04-18 11:23:28 +02:00
parent b0085dbf45
commit 28936ed84b
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC

View File

@ -30,12 +30,14 @@ export const livechatViewerModePlugin = {
}) })
} }
function refreshViewerMode (canChat: boolean): void { function refreshViewerMode (canChat: boolean | null): void {
console.log('[livechatViewerModePlugin] refreshViewerMode: ' + (canChat ? 'off' : 'on')) console.log('[livechatViewerModePlugin] refreshViewerMode: ' + (canChat ? 'off' : 'on'))
if (canChat) { if (canChat === null) {
document.querySelector('body')?.setAttribute('livechat-viewer-mode', 'off') document.body.removeAttribute('livechat-viewer-mode')
} else if (canChat) {
document.body.setAttribute('livechat-viewer-mode', 'off')
} else { } else {
document.querySelector('body')?.setAttribute('livechat-viewer-mode', 'on') document.body.setAttribute('livechat-viewer-mode', 'on')
} }
} }
@ -44,6 +46,7 @@ export const livechatViewerModePlugin = {
_converse.ChatRoomOccupants.prototype.on('change:nick', (data: any, nick: string) => { _converse.ChatRoomOccupants.prototype.on('change:nick', (data: any, nick: string) => {
try { try {
if (!_converse.api.settings.get('livechat_enable_viewer_mode')) { if (!_converse.api.settings.get('livechat_enable_viewer_mode')) {
refreshViewerMode(null)
return return
} }
// On nick change, if the user is_me, storing the new nickname // On nick change, if the user is_me, storing the new nickname
@ -59,6 +62,7 @@ export const livechatViewerModePlugin = {
_converse.api.listen.on('chatRoomInitialized', function (this: any, model: any): void { _converse.api.listen.on('chatRoomInitialized', function (this: any, model: any): void {
if (!_converse.api.settings.get('livechat_enable_viewer_mode')) { if (!_converse.api.settings.get('livechat_enable_viewer_mode')) {
refreshViewerMode(null)
return return
} }
// When room is initialized, if user has chosen a nickname, set viewermode to off. // When room is initialized, if user has chosen a nickname, set viewermode to off.