From 54355c0e28161c7c52d0146f2fe4c2e95254be77 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 23 Sep 2019 22:01:49 +0100 Subject: [PATCH] put the room name in the title tag should fix https://github.com/vector-im/riot-web/issues/4454 --- src/components/structures/MatrixChat.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 774ef21aff..7c791456b1 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -271,6 +271,10 @@ export default createReactClass({ this.focusComposer = false; + // object field used for tracking the status info appended to the title tag. + // we don't do it as react state as i'm scared about triggering needless react refreshes. + this.subTitleStatus = ''; + // this can technically be done anywhere but doing this here keeps all // the routing url path logic together. if (this.onAliasClick) { @@ -1297,6 +1301,7 @@ export default createReactClass({ collapsedRhs: false, currentRoomId: null, }); + this.subTitleStatus = ''; this._setPageSubtitle(); }, @@ -1312,6 +1317,7 @@ export default createReactClass({ collapsedRhs: false, currentRoomId: null, }); + this.subTitleStatus = ''; this._setPageSubtitle(); }, @@ -1706,6 +1712,7 @@ export default createReactClass({ if (this.props.onNewScreen) { this.props.onNewScreen(screen); } + this._setPageSubtitle(); }, onAliasClick: function(event, alias) { @@ -1821,7 +1828,13 @@ export default createReactClass({ }, _setPageSubtitle: function(subtitle='') { - document.title = `${SdkConfig.get().brand || 'Riot'} ${subtitle}`; + if (this.state.currentRoomId) { + const room = MatrixClientPeg.get().getRoom(this.state.currentRoomId); + if (room) { + subtitle = `| ${ room.name }`; + } + } + document.title = `${SdkConfig.get().brand || 'Riot'} ${subtitle} ${this.subTitleStatus}`; }, updateStatusIndicator: function(state, prevState) { @@ -1832,15 +1845,15 @@ export default createReactClass({ PlatformPeg.get().setNotificationCount(notifCount); } - let subtitle = ''; + this.subTitleStatus = ''; if (state === "ERROR") { - subtitle += `[${_t("Offline")}] `; + this.subTitleStatus += `[${_t("Offline")}] `; } if (notifCount > 0) { - subtitle += `[${notifCount}]`; + this.subTitleStatus += `[${notifCount}]`; } - this._setPageSubtitle(subtitle); + this._setPageSubtitle(); }, onCloseAllSettings() {