@@ -133,6 +133,7 @@ import { ConfirmSessionLockTheftView } from "./auth/ConfirmSessionLockTheftView"
133
133
import { LoginSplashView } from "./auth/LoginSplashView" ;
134
134
import { cleanUpDraftsIfRequired } from "../../DraftCleaner" ;
135
135
import { InitialCryptoSetupStore } from "../../stores/InitialCryptoSetupStore" ;
136
+ import { AppTitleContext } from "@matrix-org/react-sdk-module-api/lib/lifecycles/BrandingExtensions" ;
136
137
137
138
// legacy export
138
139
export { default as Views } from "../../Views" ;
@@ -225,18 +226,16 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
225
226
private tokenLogin ?: boolean ;
226
227
// What to focus on next component update, if anything
227
228
private focusNext : FocusNextType ;
228
- private subTitleStatus : string ;
229
229
private prevWindowWidth : number ;
230
230
231
- private readonly titleTemplate : string ;
232
- private readonly titleTemplateInRoom : string ;
233
-
234
231
private readonly loggedInView = createRef < LoggedInViewType > ( ) ;
235
232
private dispatcherRef ?: string ;
236
233
private themeWatcher ?: ThemeWatcher ;
237
234
private fontWatcher ?: FontWatcher ;
238
235
private readonly stores : SdkContextClass ;
239
236
237
+ private subtitleContext ?: { unreadNotificationCount : number , userNotificationLevel : NotificationLevel , syncState : SyncState } ;
238
+
240
239
public constructor ( props : IProps ) {
241
240
super ( props ) ;
242
241
this . stores = SdkContextClass . instance ;
@@ -280,13 +279,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
280
279
}
281
280
282
281
this . prevWindowWidth = UIStore . instance . windowWidth || 1000 ;
283
-
284
- // object field used for tracking the status info appended to the title tag.
285
- // we don't do it as react state as i'm scared about triggering needless react refreshes.
286
- this . subTitleStatus = "" ;
287
-
288
- this . titleTemplate = props . config . branding ?. title_template ?? "$brand $status" ;
289
- this . titleTemplateInRoom = props . config . branding ?. title_template_in_room ?? "$brand $status | $room_name" ;
290
282
}
291
283
292
284
/**
@@ -1112,7 +1104,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
1112
1104
}
1113
1105
this . setStateForNewView ( {
1114
1106
view : Views . WELCOME ,
1115
- currentRoomId : null ,
1116
1107
} ) ;
1117
1108
this . notifyNewScreen ( "welcome" ) ;
1118
1109
ThemeController . isLogin = true ;
@@ -1122,7 +1113,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
1122
1113
private viewLogin ( otherState ?: any ) : void {
1123
1114
this . setStateForNewView ( {
1124
1115
view : Views . LOGIN ,
1125
- currentRoomId : null ,
1126
1116
...otherState ,
1127
1117
} ) ;
1128
1118
this . notifyNewScreen ( "login" ) ;
@@ -1490,7 +1480,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
1490
1480
collapseLhs : false ,
1491
1481
currentRoomId : null ,
1492
1482
} ) ;
1493
- this . subTitleStatus = "" ;
1483
+ this . subtitleContext = undefined ;
1494
1484
this . setPageSubtitle ( ) ;
1495
1485
this . stores . onLoggedOut ( ) ;
1496
1486
}
@@ -1506,7 +1496,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
1506
1496
collapseLhs : false ,
1507
1497
currentRoomId : null ,
1508
1498
} ) ;
1509
- this . subTitleStatus = "" ;
1499
+ this . subtitleContext = undefined ;
1510
1500
this . setPageSubtitle ( ) ;
1511
1501
}
1512
1502
@@ -1958,33 +1948,56 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
1958
1948
}
1959
1949
1960
1950
private setPageSubtitle ( ) : void {
1961
- const params : {
1962
- $brand : string ;
1963
- $status : string ;
1964
- $room_name : string | undefined ;
1965
- } = {
1966
- $brand : SdkConfig . get ( ) . brand ,
1967
- $status : this . subTitleStatus ,
1968
- $room_name : undefined ,
1951
+ const extraContext = this . subtitleContext ;
1952
+ let context : AppTitleContext = {
1953
+ brand : SdkConfig . get ( ) . brand ,
1954
+ syncError : extraContext ?. syncState === SyncState . Error ,
1969
1955
} ;
1970
1956
1971
- if ( this . state . currentRoomId ) {
1972
- const client = MatrixClientPeg . get ( ) ;
1973
- const room = client ?. getRoom ( this . state . currentRoomId ) ;
1974
- if ( room ) {
1975
- params . $room_name = room . name ;
1957
+ if ( extraContext ) {
1958
+ if ( this . state . currentRoomId ) {
1959
+ const client = MatrixClientPeg . get ( ) ;
1960
+ const room = client ?. getRoom ( this . state . currentRoomId ) ;
1961
+ context = {
1962
+ ...context ,
1963
+ roomId : this . state . currentRoomId ,
1964
+ roomName : room ?. name ,
1965
+ notificationsMuted : extraContext . userNotificationLevel < NotificationLevel . Activity ,
1966
+ unreadNotificationCount : extraContext . unreadNotificationCount ,
1967
+ } ;
1976
1968
}
1977
1969
}
1978
1970
1979
- const titleTemplate = params . $room_name ? this . titleTemplateInRoom : this . titleTemplate ;
1971
+ const moduleTitle = ModuleRunner . instance . extensions . branding ?. getAppTitle ( context ) ;
1972
+ if ( moduleTitle ) {
1973
+ if ( document . title !== moduleTitle ) {
1974
+ document . title = moduleTitle ;
1975
+ }
1976
+ return ;
1977
+ }
1980
1978
1981
- const title = Object . entries ( params ) . reduce (
1982
- ( title : string , [ key , value ] ) => title . replaceAll ( key , ( value ?? "" ) . replaceAll ( "$" , "$_DLR$" ) ) ,
1983
- titleTemplate ,
1984
- ) ;
1979
+ let subtitle = "" ;
1980
+ if ( context ?. syncError ) {
1981
+ subtitle += `[${ _t ( "common|offline" ) } ] ` ;
1982
+ }
1983
+ if ( 'unreadNotificationCount' in context && context . unreadNotificationCount > 0 ) {
1984
+ subtitle += `[${ context . unreadNotificationCount } ]` ;
1985
+ } else if ( 'notificationsMuted' in context && ! context . notificationsMuted ) {
1986
+ subtitle += `*` ;
1987
+ }
1988
+
1989
+ if ( 'roomId' in context && context . roomId ) {
1990
+ if ( context . roomName ) {
1991
+ subtitle = `${ subtitle } | ${ context . roomName } ` ;
1992
+ }
1993
+ } else {
1994
+ subtitle = subtitle ;
1995
+ }
1996
+
1997
+ const title = `${ SdkConfig . get ( ) . brand } ${ subtitle } ` ;
1985
1998
1986
1999
if ( document . title !== title ) {
1987
- document . title = title . replaceAll ( "$_DLR$" , "$" ) ;
2000
+ document . title = title ;
1988
2001
}
1989
2002
}
1990
2003
@@ -1995,17 +2008,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
1995
2008
PlatformPeg . get ( ) ! . setErrorStatus ( state === SyncState . Error ) ;
1996
2009
PlatformPeg . get ( ) ! . setNotificationCount ( numUnreadRooms ) ;
1997
2010
}
1998
-
1999
- this . subTitleStatus = "" ;
2000
- if ( state === SyncState . Error ) {
2001
- this . subTitleStatus += `[${ _t ( "common|offline" ) } ] ` ;
2002
- }
2003
- if ( numUnreadRooms > 0 ) {
2004
- this . subTitleStatus += `[${ numUnreadRooms } ]` ;
2005
- } else if ( notificationState . level >= NotificationLevel . Activity ) {
2006
- this . subTitleStatus += `*` ;
2007
- }
2008
-
2011
+ this . subtitleContext = {
2012
+ syncState : state ,
2013
+ userNotificationLevel : notificationState . level ,
2014
+ unreadNotificationCount : numUnreadRooms ,
2015
+ } ;
2009
2016
this . setPageSubtitle ( ) ;
2010
2017
} ;
2011
2018
0 commit comments