Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix spurious notifications on non-live events (#11133)
Browse files Browse the repository at this point in the history
* Fix notifier not discriminating removed and backpaginated events

* Ignore events on the thread list generated timelines

* Add test

* tsc strict
  • Loading branch information
t3chguy authored Jun 27, 2023
1 parent f73fc49 commit 5cf818f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ 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;
if (data.timeline.getTimelineSet().threadListType !== null) return; // Ignore events on the thread list generated timelines

MatrixClientPeg.safeGet().decryptEventIfNeeded(ev);

Expand Down
24 changes: 24 additions & 0 deletions test/Notifier-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

0 comments on commit 5cf818f

Please sign in to comment.