Room list: remove direct usage of the old rls in rls v3 (#32692)

* refactor: move `DefaultTagID` and `TagID` to rls v3

Move the enum and type in rls v3 and update imports

* refactor: move `getChangedOverrideRoomMutePushRules` from rls to rls v3

* refactor: replace `VisiblityProvider` by `isRoomVisible` and move it to rls v3
This commit is contained in:
Florian Duros
2026-03-03 20:25:20 +01:00
committed by GitHub
parent 49dffe83cc
commit 93dc9fedc8
69 changed files with 203 additions and 214 deletions
@@ -20,14 +20,14 @@ import { AlphabeticSorter } from "../../../../src/stores/room-list-v3/skip-list/
import dispatcher from "../../../../src/dispatcher/dispatcher";
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
import { MetaSpace, UPDATE_SELECTED_SPACE } from "../../../../src/stores/spaces";
import { DefaultTagID } from "../../../../src/stores/room-list/models";
import { DefaultTagID } from "../../../../src/stores/room-list-v3/skip-list/tag";
import { FilterKey } from "../../../../src/stores/room-list-v3/skip-list/filters";
import { RoomNotificationStateStore } from "../../../../src/stores/notifications/RoomNotificationStateStore";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { SortingAlgorithm } from "../../../../src/stores/room-list-v3/skip-list/sorters";
import SettingsStore from "../../../../src/settings/SettingsStore";
import * as utils from "../../../../src/utils/notifications";
import * as roomMute from "../../../../src/stores/room-list/utils/roomMute";
import * as utilsRLS from "../../../../src/stores/room-list-v3/utils.ts";
import { Action } from "../../../../src/dispatcher/actions";
import { SettingLevel } from "../../../../src/settings/SettingLevel.ts";
@@ -852,7 +852,7 @@ describe("RoomListStoreV3", () => {
// Let's say that muted room 64 becomes un-muted.
const unmutedRoom = rooms[64];
jest.spyOn(roomMute, "getChangedOverrideRoomMutePushRules").mockImplementation(() => [unmutedRoom.roomId]);
jest.spyOn(utilsRLS, "getChangedOverrideRoomMutePushRules").mockImplementation(() => [unmutedRoom.roomId]);
client.getRoom = jest.fn().mockReturnValue(unmutedRoom);
const payload = {
action: "MatrixActions.accountData",
@@ -0,0 +1,58 @@
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { mocked } from "jest-mock";
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
import { RoomListCustomisations } from "../../../../src/customisations/RoomList";
import { isRoomVisible } from "../../../../src/stores/room-list-v3/isRoomVisible";
import { createTestClient, mkRoom, mkSpace } from "../../../test-utils";
import { LOCAL_ROOM_ID_PREFIX, LocalRoom } from "../../../../src/models/LocalRoom";
jest.mock("../../../../src/customisations/RoomList", () => ({
RoomListCustomisations: {
isRoomVisible: jest.fn(),
},
}));
describe("isRoomVisible", () => {
let matrixClient: MatrixClient;
beforeEach(() => {
matrixClient = createTestClient();
});
it("should return false without room", () => {
expect(isRoomVisible()).toBe(false);
});
it("should return false for a space room", () => {
const room = mkSpace(matrixClient, "space-room");
expect(isRoomVisible(room)).toBe(false);
});
it("should return false for a local room", () => {
const room = new LocalRoom(LOCAL_ROOM_ID_PREFIX + "test", createTestClient(), "@test:example.com");
room.isSpaceRoom = () => false;
expect(isRoomVisible(room)).toBe(false);
});
it("should return false if visibility customisation returns false", () => {
mocked(RoomListCustomisations.isRoomVisible!).mockReturnValue(false);
const room = mkRoom(matrixClient, "test-room");
expect(isRoomVisible(room)).toBe(false);
expect(RoomListCustomisations.isRoomVisible!).toHaveBeenCalledWith(room);
});
it("should return true if visibility customisation returns true", () => {
mocked(RoomListCustomisations.isRoomVisible!).mockReturnValue(true);
const room = mkRoom(matrixClient, "test-room");
expect(isRoomVisible(room)).toBe(true);
expect(RoomListCustomisations.isRoomVisible).toHaveBeenCalledWith(room);
});
});
@@ -11,7 +11,7 @@ import { stubClient } from "../../../../../test-utils";
import { getMockedRooms } from "../getMockedRooms";
import { CallStore } from "../../../../../../src/stores/CallStore";
import type { Call } from "../../../../../../src/models/Call";
import { DefaultTagID } from "../../../../../../src/stores/room-list/models";
import { DefaultTagID } from "../../../../../../src/stores/room-list-v3/skip-list/tag";
import { RoomNotificationStateStore } from "../../../../../../src/stores/notifications/RoomNotificationStateStore";
import type { RoomNotificationState } from "../../../../../../src/stores/notifications/RoomNotificationState";
import * as utils from "../../../../../../src/utils/notifications";
@@ -0,0 +1,88 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2023 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { ConditionKind, EventType, type IPushRule, MatrixEvent, PushRuleActionName } from "matrix-js-sdk/src/matrix";
import { getChangedOverrideRoomMutePushRules } from "../../../../src/stores/room-list-v3/utils";
import { DEFAULT_PUSH_RULES, getDefaultRuleWithKind, makePushRule } from "../../../test-utils/pushRules";
describe("getChangedOverrideRoomMutePushRules()", () => {
const makePushRulesEvent = (overrideRules: IPushRule[] = []): MatrixEvent => {
return new MatrixEvent({
type: EventType.PushRules,
content: {
global: {
...DEFAULT_PUSH_RULES.global,
override: overrideRules,
},
},
});
};
it("returns undefined when dispatched action is not accountData", () => {
const action = { action: "MatrixActions.Event.decrypted", event: new MatrixEvent({}) };
expect(getChangedOverrideRoomMutePushRules(action)).toBeUndefined();
});
it("returns undefined when dispatched action is not pushrules", () => {
const action = { action: "MatrixActions.accountData", event: new MatrixEvent({ type: "not-push-rules" }) };
expect(getChangedOverrideRoomMutePushRules(action)).toBeUndefined();
});
it("returns undefined when actions event is falsy", () => {
const action = { action: "MatrixActions.accountData" };
expect(getChangedOverrideRoomMutePushRules(action)).toBeUndefined();
});
it("returns undefined when actions previousEvent is falsy", () => {
const pushRulesEvent = makePushRulesEvent();
const action = { action: "MatrixActions.accountData", event: pushRulesEvent };
expect(getChangedOverrideRoomMutePushRules(action)).toBeUndefined();
});
it("filters out non-room specific rules", () => {
// an override rule that exists in default rules
const { rule } = getDefaultRuleWithKind(".m.rule.contains_display_name");
const updatedRule = {
...rule,
actions: [PushRuleActionName.DontNotify],
enabled: false,
};
const previousEvent = makePushRulesEvent([rule]);
const pushRulesEvent = makePushRulesEvent([updatedRule]);
const action = { action: "MatrixActions.accountData", event: pushRulesEvent, previousEvent: previousEvent };
// contains_display_name changed, but is not room-specific
expect(getChangedOverrideRoomMutePushRules(action)).toEqual([]);
});
it("returns ruleIds for added room rules", () => {
const roomId1 = "!room1:server.org";
const rule = makePushRule(roomId1, {
actions: [PushRuleActionName.DontNotify],
conditions: [{ kind: ConditionKind.EventMatch, key: "room_id", pattern: roomId1 }],
});
const previousEvent = makePushRulesEvent();
const pushRulesEvent = makePushRulesEvent([rule]);
const action = { action: "MatrixActions.accountData", event: pushRulesEvent, previousEvent: previousEvent };
// contains_display_name changed, but is not room-specific
expect(getChangedOverrideRoomMutePushRules(action)).toEqual([rule.rule_id]);
});
it("returns ruleIds for removed room rules", () => {
const roomId1 = "!room1:server.org";
const rule = makePushRule(roomId1, {
actions: [PushRuleActionName.DontNotify],
conditions: [{ kind: ConditionKind.EventMatch, key: "room_id", pattern: roomId1 }],
});
const previousEvent = makePushRulesEvent([rule]);
const pushRulesEvent = makePushRulesEvent();
const action = { action: "MatrixActions.accountData", event: pushRulesEvent, previousEvent: previousEvent };
// contains_display_name changed, but is not room-specific
expect(getChangedOverrideRoomMutePushRules(action)).toEqual([rule.rule_id]);
});
});