@@ -21,6 +21,7 @@ limitations under the License.
21
21
import React from "react" ;
22
22
import classNames from "classnames" ;
23
23
import { NotificationCountType , Room , RoomEvent } from "matrix-js-sdk/src/models/room" ;
24
+ import { ThreadEvent } from "matrix-js-sdk/src/models/thread" ;
24
25
import { Feature , ServerSupport } from "matrix-js-sdk/src/feature" ;
25
26
26
27
import { _t } from "../../../languageHandler" ;
@@ -44,6 +45,7 @@ import { NotificationStateEvents } from "../../../stores/notifications/Notificat
44
45
import PosthogTrackers from "../../../PosthogTrackers" ;
45
46
import { ButtonEvent } from "../elements/AccessibleButton" ;
46
47
import { MatrixClientPeg } from "../../../MatrixClientPeg" ;
48
+ import { doesRoomOrThreadHaveUnreadMessages } from "../../../Unread" ;
47
49
48
50
const ROOM_INFO_PHASES = [
49
51
RightPanelPhases . RoomSummary ,
@@ -154,7 +156,17 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
154
156
if ( ! this . supportsThreadNotifications ) {
155
157
this . threadNotificationState ?. on ( NotificationStateEvents . Update , this . onNotificationUpdate ) ;
156
158
} 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.
157
162
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 ) ;
158
170
}
159
171
this . onNotificationUpdate ( ) ;
160
172
RoomNotificationStateStore . instance . on ( UPDATE_STATUS_INDICATOR , this . onUpdateStatus ) ;
@@ -166,6 +178,13 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
166
178
this . threadNotificationState ?. off ( NotificationStateEvents . Update , this . onNotificationUpdate ) ;
167
179
} else {
168
180
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 ) ;
169
188
}
170
189
RoomNotificationStateStore . instance . off ( UPDATE_STATUS_INDICATOR , this . onUpdateStatus ) ;
171
190
}
@@ -191,9 +210,17 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
191
210
return NotificationColor . Red ;
192
211
case NotificationCountType . Total :
193
212
return NotificationColor . Grey ;
194
- default :
195
- return NotificationColor . None ;
196
213
}
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 ;
197
224
}
198
225
199
226
private onUpdateStatus = ( notificationState : SummarizedNotificationState ) : void => {
0 commit comments