@@ -33,9 +33,13 @@ import { useSettingValue } from "../../../hooks/useSettings";
3333import { useReadPinnedEvents , usePinnedEvents } from './PinnedMessagesCard' ;
3434import { showThreadPanel } from "../../../dispatcher/dispatch-actions/threads" ;
3535import SettingsStore from "../../../settings/SettingsStore" ;
36- import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore" ;
36+ import {
37+ RoomNotificationStateStore ,
38+ UPDATE_STATUS_INDICATOR ,
39+ } from "../../../stores/notifications/RoomNotificationStateStore" ;
3740import { NotificationColor } from "../../../stores/notifications/NotificationColor" ;
3841import { ThreadsRoomNotificationState } from "../../../stores/notifications/ThreadsRoomNotificationState" ;
42+ import { SummarizedNotificationState } from "../../../stores/notifications/SummarizedNotificationState" ;
3943import { NotificationStateEvents } from "../../../stores/notifications/NotificationState" ;
4044import PosthogTrackers from "../../../PosthogTrackers" ;
4145import { ButtonEvent } from "../elements/AccessibleButton" ;
@@ -130,29 +134,42 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
130134 RightPanelPhases . ThreadView ,
131135 ] ;
132136 private threadNotificationState : ThreadsRoomNotificationState ;
137+ private globalNotificationState : SummarizedNotificationState ;
133138
134139 constructor ( props : IProps ) {
135140 super ( props , HeaderKind . Room ) ;
136141
137142 this . threadNotificationState = RoomNotificationStateStore . instance . getThreadsRoomState ( this . props . room ) ;
143+ this . globalNotificationState = RoomNotificationStateStore . instance . globalState ;
138144 }
139145
140146 public componentDidMount ( ) : void {
141147 super . componentDidMount ( ) ;
142148 this . threadNotificationState . on ( NotificationStateEvents . Update , this . onThreadNotification ) ;
149+ RoomNotificationStateStore . instance . on ( UPDATE_STATUS_INDICATOR , this . onUpdateStatus ) ;
143150 }
144151
145152 public componentWillUnmount ( ) : void {
146153 super . componentWillUnmount ( ) ;
147154 this . threadNotificationState . off ( NotificationStateEvents . Update , this . onThreadNotification ) ;
155+ RoomNotificationStateStore . instance . off ( UPDATE_STATUS_INDICATOR , this . onUpdateStatus ) ;
148156 }
149157
150158 private onThreadNotification = ( ) : void => {
159+ // XXX: why don't we read from this.state.threadNotificationColor in the render methods?
151160 this . setState ( {
152161 threadNotificationColor : this . threadNotificationState . color ,
153162 } ) ;
154163 } ;
155164
165+ private onUpdateStatus = ( notificationState : SummarizedNotificationState ) : void => {
166+ // XXX: why don't we read from this.state.globalNotificationCount in the render methods?
167+ this . globalNotificationState = notificationState ;
168+ this . setState ( {
169+ globalNotificationColor : notificationState . color ,
170+ } ) ;
171+ } ;
172+
156173 protected onAction ( payload : ActionPayload ) {
157174 if ( payload . action === Action . ViewUser ) {
158175 if ( payload . member ) {
@@ -254,7 +271,12 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
254271 title = { _t ( 'Notifications' ) }
255272 isHighlighted = { this . isPhase ( RightPanelPhases . NotificationPanel ) }
256273 onClick = { this . onNotificationsClicked }
257- /> ,
274+ isUnread = { this . globalNotificationState . color === NotificationColor . Red }
275+ >
276+ { this . globalNotificationState . color === NotificationColor . Red ?
277+ < UnreadIndicator color = { this . globalNotificationState . color } /> :
278+ null }
279+ </ HeaderButton > ,
258280 ) ;
259281 rightPanelPhaseButtons . set ( RightPanelPhases . RoomSummary ,
260282 < HeaderButton
@@ -269,7 +291,7 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
269291 return < >
270292 {
271293 Array . from ( rightPanelPhaseButtons . keys ( ) ) . map ( ( phase ) =>
272- ( this . props . excludedRightPanelPhaseButtons . includes ( phase )
294+ ( this . props . excludedRightPanelPhaseButtons ? .includes ( phase )
273295 ? null
274296 : rightPanelPhaseButtons . get ( phase ) ) )
275297 }
0 commit comments