@@ -30,7 +30,6 @@ import { RightPanelPhases } from '../../../stores/right-panel/RightPanelStorePha
30
30
import { Action } from "../../../dispatcher/actions" ;
31
31
import { ActionPayload } from "../../../dispatcher/payloads" ;
32
32
import RightPanelStore from "../../../stores/right-panel/RightPanelStore" ;
33
- import { useSettingValue } from "../../../hooks/useSettings" ;
34
33
import { useReadPinnedEvents , usePinnedEvents } from './PinnedMessagesCard' ;
35
34
import { showThreadPanel } from "../../../dispatcher/dispatch-actions/threads" ;
36
35
import SettingsStore from "../../../settings/SettingsStore" ;
@@ -85,9 +84,8 @@ interface IHeaderButtonProps {
85
84
}
86
85
87
86
const PinnedMessagesHeaderButton = ( { room, isHighlighted, onClick } : IHeaderButtonProps ) => {
88
- const pinningEnabled = useSettingValue ( "feature_pinning" ) ;
89
- const pinnedEvents = usePinnedEvents ( pinningEnabled && room ) ;
90
- const readPinnedEvents = useReadPinnedEvents ( pinningEnabled && room ) ;
87
+ const pinnedEvents = usePinnedEvents ( room ) ;
88
+ const readPinnedEvents = useReadPinnedEvents ( room ) ;
91
89
if ( ! pinnedEvents ?. length ) return null ;
92
90
93
91
let unreadIndicator ;
@@ -135,7 +133,7 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
135
133
RightPanelPhases . ThreadPanel ,
136
134
RightPanelPhases . ThreadView ,
137
135
] ;
138
- private threadNotificationState : ThreadsRoomNotificationState ;
136
+ private threadNotificationState : ThreadsRoomNotificationState | null ;
139
137
private globalNotificationState : SummarizedNotificationState ;
140
138
141
139
private get supportsThreadNotifications ( ) : boolean {
@@ -146,9 +144,9 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
146
144
constructor ( props : IProps ) {
147
145
super ( props , HeaderKind . Room ) ;
148
146
149
- if ( ! this . supportsThreadNotifications ) {
150
- this . threadNotificationState = RoomNotificationStateStore . instance . getThreadsRoomState ( this . props . room ) ;
151
- }
147
+ this . threadNotificationState = ! this . supportsThreadNotifications && this . props . room
148
+ ? RoomNotificationStateStore . instance . getThreadsRoomState ( this . props . room )
149
+ : null ;
152
150
this . globalNotificationState = RoomNotificationStateStore . instance . globalState ;
153
151
}
154
152
@@ -176,7 +174,7 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
176
174
private onNotificationUpdate = ( ) : void => {
177
175
let threadNotificationColor : NotificationColor ;
178
176
if ( ! this . supportsThreadNotifications ) {
179
- threadNotificationColor = this . threadNotificationState . color ;
177
+ threadNotificationColor = this . threadNotificationState ? .color ?? NotificationColor . None ;
180
178
} else {
181
179
threadNotificationColor = this . notificationColor ;
182
180
}
@@ -189,7 +187,7 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
189
187
} ;
190
188
191
189
private get notificationColor ( ) : NotificationColor {
192
- switch ( this . props . room . threadsAggregateNotificationType ) {
190
+ switch ( this . props . room ? .threadsAggregateNotificationType ) {
193
191
case NotificationCountType . Highlight :
194
192
return NotificationColor . Red ;
195
193
case NotificationCountType . Total :
@@ -263,23 +261,29 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
263
261
264
262
private onThreadsPanelClicked = ( ev : ButtonEvent ) => {
265
263
if ( RoomHeaderButtons . THREAD_PHASES . includes ( this . state . phase ) ) {
266
- RightPanelStore . instance . togglePanel ( this . props . room ?. roomId ) ;
264
+ RightPanelStore . instance . togglePanel ( this . props . room ?. roomId ?? null ) ;
267
265
} else {
268
266
showThreadPanel ( ) ;
269
267
PosthogTrackers . trackInteraction ( "WebRoomHeaderButtonsThreadsButton" , ev ) ;
270
268
}
271
269
} ;
272
270
273
271
public renderButtons ( ) {
272
+ if ( ! this . props . room ) {
273
+ return < > </ > ;
274
+ }
275
+
274
276
const rightPanelPhaseButtons : Map < RightPanelPhases , any > = new Map ( ) ;
275
277
276
- rightPanelPhaseButtons . set ( RightPanelPhases . PinnedMessages ,
277
- < PinnedMessagesHeaderButton
278
- key = "pinnedMessagesButton"
279
- room = { this . props . room }
280
- isHighlighted = { this . isPhase ( RightPanelPhases . PinnedMessages ) }
281
- onClick = { this . onPinnedMessagesClicked } /> ,
282
- ) ;
278
+ if ( SettingsStore . getValue ( "feature_pinning" ) ) {
279
+ rightPanelPhaseButtons . set ( RightPanelPhases . PinnedMessages ,
280
+ < PinnedMessagesHeaderButton
281
+ key = "pinnedMessagesButton"
282
+ room = { this . props . room }
283
+ isHighlighted = { this . isPhase ( RightPanelPhases . PinnedMessages ) }
284
+ onClick = { this . onPinnedMessagesClicked } /> ,
285
+ ) ;
286
+ }
283
287
rightPanelPhaseButtons . set ( RightPanelPhases . Timeline ,
284
288
< TimelineCardHeaderButton
285
289
key = "timelineButton"
0 commit comments