@@ -30,7 +30,6 @@ import { RightPanelPhases } from '../../../stores/right-panel/RightPanelStorePha
3030import { Action } from "../../../dispatcher/actions" ;
3131import { ActionPayload } from "../../../dispatcher/payloads" ;
3232import RightPanelStore from "../../../stores/right-panel/RightPanelStore" ;
33- import { useSettingValue } from "../../../hooks/useSettings" ;
3433import { useReadPinnedEvents , usePinnedEvents } from './PinnedMessagesCard' ;
3534import { showThreadPanel } from "../../../dispatcher/dispatch-actions/threads" ;
3635import SettingsStore from "../../../settings/SettingsStore" ;
@@ -85,9 +84,8 @@ interface IHeaderButtonProps {
8584}
8685
8786const 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 ) ;
9189 if ( ! pinnedEvents ?. length ) return null ;
9290
9391 let unreadIndicator ;
@@ -135,7 +133,7 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
135133 RightPanelPhases . ThreadPanel ,
136134 RightPanelPhases . ThreadView ,
137135 ] ;
138- private threadNotificationState : ThreadsRoomNotificationState ;
136+ private threadNotificationState : ThreadsRoomNotificationState | null ;
139137 private globalNotificationState : SummarizedNotificationState ;
140138
141139 private get supportsThreadNotifications ( ) : boolean {
@@ -146,9 +144,9 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
146144 constructor ( props : IProps ) {
147145 super ( props , HeaderKind . Room ) ;
148146
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 ;
152150 this . globalNotificationState = RoomNotificationStateStore . instance . globalState ;
153151 }
154152
@@ -176,7 +174,7 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
176174 private onNotificationUpdate = ( ) : void => {
177175 let threadNotificationColor : NotificationColor ;
178176 if ( ! this . supportsThreadNotifications ) {
179- threadNotificationColor = this . threadNotificationState . color ;
177+ threadNotificationColor = this . threadNotificationState ? .color ?? NotificationColor . None ;
180178 } else {
181179 threadNotificationColor = this . notificationColor ;
182180 }
@@ -189,7 +187,7 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
189187 } ;
190188
191189 private get notificationColor ( ) : NotificationColor {
192- switch ( this . props . room . threadsAggregateNotificationType ) {
190+ switch ( this . props . room ? .threadsAggregateNotificationType ) {
193191 case NotificationCountType . Highlight :
194192 return NotificationColor . Red ;
195193 case NotificationCountType . Total :
@@ -263,23 +261,29 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
263261
264262 private onThreadsPanelClicked = ( ev : ButtonEvent ) => {
265263 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 ) ;
267265 } else {
268266 showThreadPanel ( ) ;
269267 PosthogTrackers . trackInteraction ( "WebRoomHeaderButtonsThreadsButton" , ev ) ;
270268 }
271269 } ;
272270
273271 public renderButtons ( ) {
272+ if ( ! this . props . room ) {
273+ return < > </ > ;
274+ }
275+
274276 const rightPanelPhaseButtons : Map < RightPanelPhases , any > = new Map ( ) ;
275277
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+ }
283287 rightPanelPhaseButtons . set ( RightPanelPhases . Timeline ,
284288 < TimelineCardHeaderButton
285289 key = "timelineButton"
0 commit comments