ConverseJS: document title set to the room name.

This commit is contained in:
John Livingston 2021-11-26 17:33:55 +01:00
parent 8f12ca0c45
commit 7f6a2cd7ee
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
2 changed files with 26 additions and 3 deletions

View File

@ -2,6 +2,9 @@
interface Window {
converse: {
initialize: (args: any) => void
plugins: {
add: (name: string, plugin: any) => void
}
}
initConverse: (args: any) => void
}
@ -141,7 +144,8 @@ window.initConverse = async function initConverse ({
},
theme: theme || 'peertube',
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
whitelisted_plugins: ['livechatWindowTitlePlugin']
}
// TODO: params.clear_messages_on_reconnection = true when muc_mam will be available.
@ -191,6 +195,25 @@ window.initConverse = async function initConverse ({
}
try {
window.converse.plugins.add('livechatWindowTitlePlugin', {
dependencies: ['converse-muc-views'],
overrides: {
ChatRoomView: {
renderHeading: function (this: any): any {
console.log('[livechatWindowTitlePlugin] updating the document title.')
try {
const title = this.model.getDisplayName()
if (document.title !== title) {
document.title = title
}
} catch (err) {
console.error('Failed updating the window title', err)
}
return this.__super__.renderHeading.apply(this, arguments)
}
}
}
})
window.converse.initialize(params)
} catch (error) {
console.error('Failed initializing converseJS', error)

View File

@ -1,10 +1,10 @@
<!DOCTYPE html>
<html class="no-js">
<head>
<title>Converse</title>
<title>Peertube LiveChat Plugin</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="Converse XMPP/Jabber Chat"/>
<meta name="description" content="Peertube LiveChat Plugin"/>
<link type="text/css" rel="stylesheet" media="screen" href="{{BASE_STATIC_URL}}conversejs/converse.min.css" />
<script type="text/javaScript" src="{{BASE_STATIC_URL}}conversejs/converse.min.js"></script>
<script type="text/javascript" src="{{BASE_STATIC_URL}}static/builtin.js"></script>