Skip to content

Commit 5cf818f

Browse files
authored
Fix spurious notifications on non-live events (matrix-org#11133)
* Fix notifier not discriminating removed and backpaginated events * Ignore events on the thread list generated timelines * Add test * tsc strict
1 parent f73fc49 commit 5cf818f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Notifier.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,11 @@ class NotifierClass {
412412
removed: boolean,
413413
data: IRoomTimelineData,
414414
): void => {
415-
if (!data.liveEvent) return; // only notify for new things, not old.
415+
if (removed) return; // only notify for new events, not removed ones
416+
if (!data.liveEvent || !!toStartOfTimeline) return; // only notify for new things, not old.
416417
if (!this.isSyncing) return; // don't alert for any messages initially
417418
if (ev.getSender() === MatrixClientPeg.safeGet().getUserId()) return;
419+
if (data.timeline.getTimelineSet().threadListType !== null) return; // Ignore events on the thread list generated timelines
418420

419421
MatrixClientPeg.safeGet().decryptEventIfNeeded(ev);
420422

test/Notifier-test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,28 @@ describe("Notifier", () => {
538538
expect(localStorage.getItem("notifications_hidden")).toBeTruthy();
539539
});
540540
});
541+
542+
describe("onEvent", () => {
543+
it("should not evaluate events from the thread list fake timeline sets", async () => {
544+
mockClient.supportsThreads.mockReturnValue(true);
545+
546+
const fn = jest.spyOn(Notifier, "evaluateEvent");
547+
548+
await testRoom.createThreadsTimelineSets();
549+
testRoom.threadsTimelineSets[0]!.addEventToTimeline(
550+
mkEvent({
551+
event: true,
552+
type: "m.room.message",
553+
user: "@user1:server",
554+
room: roomId,
555+
content: { body: "this is a thread root" },
556+
}),
557+
testRoom.threadsTimelineSets[0]!.getLiveTimeline(),
558+
false,
559+
false,
560+
);
561+
562+
expect(fn).not.toHaveBeenCalled();
563+
});
564+
});
541565
});

0 commit comments

Comments
 (0)