@@ -21,6 +21,7 @@ limitations under the License.
2121import React from "react" ;
2222import classNames from "classnames" ;
2323import { NotificationCountType , Room , RoomEvent } from "matrix-js-sdk/src/models/room" ;
24+ import { ThreadEvent } from "matrix-js-sdk/src/models/thread" ;
2425import { Feature , ServerSupport } from "matrix-js-sdk/src/feature" ;
2526
2627import { _t } from "../../../languageHandler" ;
@@ -44,6 +45,7 @@ import { NotificationStateEvents } from "../../../stores/notifications/Notificat
4445import PosthogTrackers from "../../../PosthogTrackers" ;
4546import { ButtonEvent } from "../elements/AccessibleButton" ;
4647import { MatrixClientPeg } from "../../../MatrixClientPeg" ;
48+ import { doesRoomOrThreadHaveUnreadMessages } from "../../../Unread" ;
4749
4850const ROOM_INFO_PHASES = [
4951 RightPanelPhases . RoomSummary ,
@@ -154,7 +156,17 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
154156 if ( ! this . supportsThreadNotifications ) {
155157 this . threadNotificationState ?. on ( NotificationStateEvents . Update , this . onNotificationUpdate ) ;
156158 } else {
159+ // Notification badge may change if the notification counts from the
160+ // server change, if a new thread is created or updated, or if a
161+ // receipt is sent in the thread.
157162 this . props . room ?. on ( RoomEvent . UnreadNotifications , this . onNotificationUpdate ) ;
163+ this . props . room ?. on ( RoomEvent . Receipt , this . onNotificationUpdate ) ;
164+ this . props . room ?. on ( RoomEvent . Timeline , this . onNotificationUpdate ) ;
165+ this . props . room ?. on ( RoomEvent . Redaction , this . onNotificationUpdate ) ;
166+ this . props . room ?. on ( RoomEvent . LocalEchoUpdated , this . onNotificationUpdate ) ;
167+ this . props . room ?. on ( RoomEvent . MyMembership , this . onNotificationUpdate ) ;
168+ this . props . room ?. on ( ThreadEvent . New , this . onNotificationUpdate ) ;
169+ this . props . room ?. on ( ThreadEvent . Update , this . onNotificationUpdate ) ;
158170 }
159171 this . onNotificationUpdate ( ) ;
160172 RoomNotificationStateStore . instance . on ( UPDATE_STATUS_INDICATOR , this . onUpdateStatus ) ;
@@ -166,6 +178,13 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
166178 this . threadNotificationState ?. off ( NotificationStateEvents . Update , this . onNotificationUpdate ) ;
167179 } else {
168180 this . props . room ?. off ( RoomEvent . UnreadNotifications , this . onNotificationUpdate ) ;
181+ this . props . room ?. off ( RoomEvent . Receipt , this . onNotificationUpdate ) ;
182+ this . props . room ?. off ( RoomEvent . Timeline , this . onNotificationUpdate ) ;
183+ this . props . room ?. off ( RoomEvent . Redaction , this . onNotificationUpdate ) ;
184+ this . props . room ?. off ( RoomEvent . LocalEchoUpdated , this . onNotificationUpdate ) ;
185+ this . props . room ?. off ( RoomEvent . MyMembership , this . onNotificationUpdate ) ;
186+ this . props . room ?. off ( ThreadEvent . New , this . onNotificationUpdate ) ;
187+ this . props . room ?. off ( ThreadEvent . Update , this . onNotificationUpdate ) ;
169188 }
170189 RoomNotificationStateStore . instance . off ( UPDATE_STATUS_INDICATOR , this . onUpdateStatus ) ;
171190 }
@@ -191,9 +210,17 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
191210 return NotificationColor . Red ;
192211 case NotificationCountType . Total :
193212 return NotificationColor . Grey ;
194- default :
195- return NotificationColor . None ;
196213 }
214+ // We don't have any notified messages, but we might have unread messages. Let's
215+ // find out.
216+ for ( const thread of this . props . room ! . getThreads ( ) ) {
217+ // If the current thread has unread messages, we're done.
218+ if ( doesRoomOrThreadHaveUnreadMessages ( thread ) ) {
219+ return NotificationColor . Bold ;
220+ }
221+ }
222+ // Otherwise, no notification color.
223+ return NotificationColor . None ;
197224 }
198225
199226 private onUpdateStatus = ( notificationState : SummarizedNotificationState ) : void => {
0 commit comments