Skip to content

Commit 209f5bd

Browse files
authored
Consider the empty push rule actions array equiv to deprecated dont_notify (matrix-org#11155)
* Consider the empty push rule actions array equiv to deprecated dont_notify * Switch primary tests to empty actions, add test for dont_notify * strict types
1 parent 6836a5f commit 209f5bd

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/RoomNotifs.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ function isRuleRoomMuteRuleForRoomId(roomId: string, rule: IPushRule): boolean {
219219
}
220220

221221
function isMuteRule(rule: IPushRule): boolean {
222-
return rule.actions.length === 1 && rule.actions[0] === PushRuleActionName.DontNotify;
222+
// DontNotify is equivalent to the empty actions array
223+
return (
224+
rule.actions.length === 0 || (rule.actions.length === 1 && rule.actions[0] === PushRuleActionName.DontNotify)
225+
);
223226
}
224227

225228
export function determineUnreadState(

test/RoomNotifs-test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ describe("RoomNotifs test", () => {
6464
expect(getRoomNotifsState(client, room.roomId)).toBe(RoomNotifState.Mute);
6565
});
6666

67+
it("getRoomNotifsState handles mute state for legacy DontNotify action", () => {
68+
const room = mkRoom(client, "!roomId:server");
69+
muteRoom(room);
70+
client.pushRules!.global.override![0]!.actions = [PushRuleActionName.DontNotify];
71+
expect(getRoomNotifsState(client, room.roomId)).toBe(RoomNotifState.Mute);
72+
});
73+
6774
it("getRoomNotifsState handles mentions only", () => {
6875
(client as any).getRoomPushRule = () => ({
6976
rule_id: "!roomId:server",

test/test-utils/test-utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
RoomType,
3535
KNOWN_SAFE_ROOM_VERSION,
3636
ConditionKind,
37-
PushRuleActionName,
3837
IPushRules,
3938
RelationType,
4039
} from "matrix-js-sdk/src/matrix";
@@ -796,7 +795,7 @@ export function muteRoom(room: Room): void {
796795
pattern: room.roomId,
797796
},
798797
],
799-
actions: [PushRuleActionName.DontNotify],
798+
actions: [],
800799
},
801800
];
802801
}

0 commit comments

Comments
 (0)