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

Consider the empty push rule actions array equiv to deprecated dont_notify #11155

Merged
merged 5 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/RoomNotifs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions test/RoomNotifs-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
RoomType,
KNOWN_SAFE_ROOM_VERSION,
ConditionKind,
PushRuleActionName,
IPushRules,
RelationType,
} from "matrix-js-sdk/src/matrix";
Expand Down Expand Up @@ -794,7 +793,7 @@ export function muteRoom(room: Room): void {
pattern: room.roomId,
},
],
actions: [PushRuleActionName.DontNotify],
actions: [],
},
];
}
Loading