Skip to content

Commit 53a45a3

Browse files
author
Germain
authored
Fix highlight notifications increasing when total notification is zero (#2937)
1 parent fa2eeac commit 53a45a3

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

spec/unit/notifications.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ describe("fixNotificationCountOnDecryption", () => {
114114

115115
fixNotificationCountOnDecryption(mockClient, event);
116116

117-
expect(room.getRoomUnreadNotificationCount(NotificationCountType.Total)).toBe(0);
118-
expect(room.getRoomUnreadNotificationCount(NotificationCountType.Highlight)).toBe(0);
117+
expect(room.getRoomUnreadNotificationCount(NotificationCountType.Total)).toBe(1);
118+
expect(room.getRoomUnreadNotificationCount(NotificationCountType.Highlight)).toBe(1);
119119
});
120120

121121
it("changes the thread count to highlight on decryption", () => {

src/client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9379,15 +9379,14 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri
93799379

93809380
const isThreadEvent = !!event.threadRootId && !event.isThreadRoot;
93819381

9382-
const totalCount = room.getUnreadCountForEventContext(NotificationCountType.Total, event);
93839382
const currentCount = room.getUnreadCountForEventContext(NotificationCountType.Highlight, event);
93849383

93859384
// Ensure the unread counts are kept up to date if the event is encrypted
93869385
// We also want to make sure that the notification count goes up if we already
93879386
// have encrypted events to avoid other code from resetting 'highlight' to zero.
93889387
const oldHighlight = !!oldActions?.tweaks?.highlight;
93899388
const newHighlight = !!actions?.tweaks?.highlight;
9390-
if ((oldHighlight !== newHighlight || currentCount > 0) && totalCount > 0) {
9389+
if (oldHighlight !== newHighlight || currentCount > 0) {
93919390
// TODO: Handle mentions received while the client is offline
93929391
// See also https://github.com/vector-im/element-web/issues/9069
93939392
const hasReadEvent = isThreadEvent

src/models/room.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
16961696
Array.from(this.threads)
16971697
.forEach(([, thread]) => {
16981698
if (thread.length === 0) return;
1699-
const currentUserParticipated = thread.events.some(event => {
1699+
const currentUserParticipated = thread.timeline.some(event => {
17001700
return event.getSender() === this.client.getUserId();
17011701
});
17021702
if (filterType !== ThreadFilterType.My || currentUserParticipated) {

src/models/thread.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
8282
* A reference to all the events ID at the bottom of the threads
8383
*/
8484
public readonly timelineSet: EventTimelineSet;
85+
public timeline: MatrixEvent[] = [];
8586

8687
private _currentUserParticipated = false;
8788

@@ -186,7 +187,7 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
186187
private onRedaction = async (event: MatrixEvent): Promise<void> => {
187188
if (event.threadRootId !== this.id) return; // ignore redactions for other timelines
188189
if (this.replyCount <= 0) {
189-
for (const threadEvent of this.events) {
190+
for (const threadEvent of this.timeline) {
190191
this.clearEventMetadata(threadEvent);
191192
}
192193
this.lastEvent = this.rootEvent;
@@ -233,6 +234,7 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
233234
roomState: this.roomState,
234235
},
235236
);
237+
this.timeline = this.events;
236238
}
237239
}
238240

@@ -292,6 +294,7 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
292294
this.setEventMetadata(event);
293295
await this.fetchEditsWhereNeeded(event);
294296
}
297+
this.timeline = this.events;
295298
}
296299

297300
private getRootEventBundledRelationship(rootEvent = this.rootEvent): IThreadBundledRelationship | undefined {
@@ -403,8 +406,8 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
403406
* Return last reply to the thread, if known.
404407
*/
405408
public lastReply(matches: (ev: MatrixEvent) => boolean = (): boolean => true): MatrixEvent | null {
406-
for (let i = this.events.length - 1; i >= 0; i--) {
407-
const event = this.events[i];
409+
for (let i = this.timeline.length - 1; i >= 0; i--) {
410+
const event = this.timeline[i];
408411
if (matches(event)) {
409412
return event;
410413
}
@@ -452,10 +455,6 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
452455
return this.timelineSet;
453456
}
454457

455-
public get timeline(): MatrixEvent[] {
456-
return this.events;
457-
}
458-
459458
public addReceipt(event: MatrixEvent, synthetic: boolean): void {
460459
throw new Error("Unsupported function on the thread model");
461460
}

0 commit comments

Comments
 (0)