From 1e4313c9a0096c7749354aaa88b501166f678b6b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 28 Jun 2023 11:17:40 +0100 Subject: [PATCH 1/3] Consider the empty push rule actions array equiv to deprecated dont_notify --- src/RoomNotifs.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/RoomNotifs.ts b/src/RoomNotifs.ts index c484d68f182..c1f94cd71c0 100644 --- a/src/RoomNotifs.ts +++ b/src/RoomNotifs.ts @@ -219,7 +219,10 @@ function isRuleRoomMuteRuleForRoomId(roomId: string, rule: IPushRule): boolean { } function isMuteRule(rule: IPushRule): boolean { - return rule.actions.length === 1 && rule.actions[0] === PushRuleActionName.DontNotify; + // DontNotify is equivalent to the empty actions array + return ( + rule.actions.length === 0 || (rule.actions.length === 1 && rule.actions[0] === PushRuleActionName.DontNotify) + ); } export function determineUnreadState( From 7006f27782d618bc2b183a49b9621f3b97edb00a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 28 Jun 2023 12:33:21 +0100 Subject: [PATCH 2/3] Switch primary tests to empty actions, add test for dont_notify --- test/RoomNotifs-test.ts | 7 +++++++ test/test-utils/test-utils.ts | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/RoomNotifs-test.ts b/test/RoomNotifs-test.ts index e80e943e3c4..6e07bc060d0 100644 --- a/test/RoomNotifs-test.ts +++ b/test/RoomNotifs-test.ts @@ -64,6 +64,13 @@ describe("RoomNotifs test", () => { expect(getRoomNotifsState(client, room.roomId)).toBe(RoomNotifState.Mute); }); + it("getRoomNotifsState handles mute state for legacy DontNotify action", () => { + const room = mkRoom(client, "!roomId:server"); + muteRoom(room); + client.pushRules.global.override[0]!.actions = [PushRuleActionName.DontNotify]; + expect(getRoomNotifsState(client, room.roomId)).toBe(RoomNotifState.Mute); + }); + it("getRoomNotifsState handles mentions only", () => { (client as any).getRoomPushRule = () => ({ rule_id: "!roomId:server", diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index 3451f17a59b..f76f84f2e0d 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -34,7 +34,6 @@ import { RoomType, KNOWN_SAFE_ROOM_VERSION, ConditionKind, - PushRuleActionName, IPushRules, RelationType, } from "matrix-js-sdk/src/matrix"; @@ -794,7 +793,7 @@ export function muteRoom(room: Room): void { pattern: room.roomId, }, ], - actions: [PushRuleActionName.DontNotify], + actions: [], }, ]; } From 1916cea1bef54c2e79e6dae666ce95d5fa19ed33 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 28 Jun 2023 12:40:58 +0100 Subject: [PATCH 3/3] strict types --- test/RoomNotifs-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/RoomNotifs-test.ts b/test/RoomNotifs-test.ts index 6e07bc060d0..505de622bcd 100644 --- a/test/RoomNotifs-test.ts +++ b/test/RoomNotifs-test.ts @@ -67,7 +67,7 @@ describe("RoomNotifs test", () => { it("getRoomNotifsState handles mute state for legacy DontNotify action", () => { const room = mkRoom(client, "!roomId:server"); muteRoom(room); - client.pushRules.global.override[0]!.actions = [PushRuleActionName.DontNotify]; + client.pushRules!.global.override![0]!.actions = [PushRuleActionName.DontNotify]; expect(getRoomNotifsState(client, room.roomId)).toBe(RoomNotifState.Mute); });