Skip to content

Commit 5b6bebc

Browse files
author
Germain
authored
Do not calculate highlight notifs for threads unknown to the room (#2957)
1 parent 7b5e137 commit 5b6bebc

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

spec/unit/notifications.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ describe("fixNotificationCountOnDecryption", () => {
141141
expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight)).toBe(0);
142142
});
143143

144+
it("does not calculate for threads unknown to the room", () => {
145+
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 0);
146+
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight, 0);
147+
148+
const unknownThreadEvent = mkEvent({
149+
type: EventType.RoomMessage,
150+
content: {
151+
"m.relates_to": {
152+
rel_type: RelationType.Thread,
153+
event_id: "$unknownthread",
154+
},
155+
"msgtype": MsgType.Text,
156+
"body": "Thread reply",
157+
},
158+
event: true,
159+
});
160+
161+
fixNotificationCountOnDecryption(mockClient, unknownThreadEvent);
162+
163+
expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total)).toBe(0);
164+
expect(room.getThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight)).toBe(0);
165+
});
166+
144167
it("emits events", () => {
145168
const cb = jest.fn();
146169
room.on(RoomEvent.UnreadNotifications, cb);

src/client.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9297,9 +9297,21 @@ export function fixNotificationCountOnDecryption(cli: MatrixClient, event: Matri
92979297
if (oldHighlight !== newHighlight || currentCount > 0) {
92989298
// TODO: Handle mentions received while the client is offline
92999299
// See also https://github.com/vector-im/element-web/issues/9069
9300-
const hasReadEvent = isThreadEvent
9301-
? room.getThread(event.threadRootId)?.hasUserReadEvent(cli.getUserId()!, event.getId()!)
9302-
: room.hasUserReadEvent(cli.getUserId()!, event.getId()!);
9300+
let hasReadEvent;
9301+
if (isThreadEvent) {
9302+
const thread = room.getThread(event.threadRootId);
9303+
hasReadEvent = thread
9304+
? thread.hasUserReadEvent(cli.getUserId()!, event.getId()!)
9305+
// If the thread object does not exist in the room yet, we don't
9306+
// want to calculate notification for this event yet. We have not
9307+
// restored the read receipts yet and can't accurately calculate
9308+
// highlight notifications at this stage.
9309+
//
9310+
// This issue can likely go away when MSC3874 is implemented
9311+
: true;
9312+
} else {
9313+
hasReadEvent = room.hasUserReadEvent(cli.getUserId()!, event.getId()!);
9314+
}
93039315

93049316
if (!hasReadEvent) {
93059317
let newCount = currentCount;

0 commit comments

Comments
 (0)