From 16d72fb5c765b4aba9e6c8fc3bd881982c06be49 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 26 Jun 2023 11:47:03 +0100 Subject: [PATCH 1/4] Fix notifier not discriminating removed and backpaginated events --- src/Notifier.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Notifier.ts b/src/Notifier.ts index fed04dd68d2..6a04d8ed5db 100644 --- a/src/Notifier.ts +++ b/src/Notifier.ts @@ -412,7 +412,8 @@ class NotifierClass { removed: boolean, data: IRoomTimelineData, ): void => { - if (!data.liveEvent) return; // only notify for new things, not old. + if (removed) return; // only notify for new events, not removed ones + if (!data.liveEvent || !!toStartOfTimeline) return; // only notify for new things, not old. if (!this.isSyncing) return; // don't alert for any messages initially if (ev.getSender() === MatrixClientPeg.safeGet().getUserId()) return; From 872c49b74d016604ec75fcfbdc652898517fc490 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 26 Jun 2023 16:52:28 +0100 Subject: [PATCH 2/4] Ignore events on the thread list generated timelines --- src/Notifier.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Notifier.ts b/src/Notifier.ts index 6a04d8ed5db..db9a7f1b1c3 100644 --- a/src/Notifier.ts +++ b/src/Notifier.ts @@ -416,6 +416,7 @@ class NotifierClass { if (!data.liveEvent || !!toStartOfTimeline) return; // only notify for new things, not old. if (!this.isSyncing) return; // don't alert for any messages initially if (ev.getSender() === MatrixClientPeg.safeGet().getUserId()) return; + if (data.timeline.getTimelineSet().threadListType !== null) return; // Ignore events on the thread list generated timelines MatrixClientPeg.safeGet().decryptEventIfNeeded(ev); From f3ec12b07e10a5e00f985559afe3e63b330c4524 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 26 Jun 2023 17:35:24 +0100 Subject: [PATCH 3/4] Add test --- test/Notifier-test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/Notifier-test.ts b/test/Notifier-test.ts index 033360d04cc..f410c52696b 100644 --- a/test/Notifier-test.ts +++ b/test/Notifier-test.ts @@ -538,4 +538,28 @@ describe("Notifier", () => { expect(localStorage.getItem("notifications_hidden")).toBeTruthy(); }); }); + + describe("onEvent", () => { + it("should not evaluate events from the thread list fake timeline sets", async () => { + mockClient.supportsThreads.mockReturnValue(true); + + const fn = jest.spyOn(Notifier, "evaluateEvent"); + + await testRoom.createThreadsTimelineSets(); + testRoom.threadsTimelineSets[0].addEventToTimeline( + mkEvent({ + event: true, + type: "m.room.message", + user: "@user1:server", + room: roomId, + content: { body: "this is a thread root" }, + }), + testRoom.threadsTimelineSets[0].getLiveTimeline(), + false, + false, + ); + + expect(fn).not.toHaveBeenCalled(); + }); + }); }); From 5a995133d091b7f7d23bed1dfcfad0ab550c16a1 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 27 Jun 2023 10:17:26 +0100 Subject: [PATCH 4/4] tsc strict --- test/Notifier-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Notifier-test.ts b/test/Notifier-test.ts index f410c52696b..16a10db9ec1 100644 --- a/test/Notifier-test.ts +++ b/test/Notifier-test.ts @@ -546,7 +546,7 @@ describe("Notifier", () => { const fn = jest.spyOn(Notifier, "evaluateEvent"); await testRoom.createThreadsTimelineSets(); - testRoom.threadsTimelineSets[0].addEventToTimeline( + testRoom.threadsTimelineSets[0]!.addEventToTimeline( mkEvent({ event: true, type: "m.room.message", @@ -554,7 +554,7 @@ describe("Notifier", () => { room: roomId, content: { body: "this is a thread root" }, }), - testRoom.threadsTimelineSets[0].getLiveTimeline(), + testRoom.threadsTimelineSets[0]!.getLiveTimeline(), false, false, );