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

Commit

Permalink
Support dynamic room predecessors in leave-behaviour (#10340)
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Mar 9, 2023
1 parent f90bc40 commit 421c1b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/leave-behaviour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import LeaveSpaceDialog from "../components/views/dialogs/LeaveSpaceDialog";
import { AfterLeaveRoomPayload } from "../dispatcher/payloads/AfterLeaveRoomPayload";
import { bulkSpaceBehaviour } from "./space";
import { SdkContextClass } from "../contexts/SDKContext";
import SettingsStore from "../settings/SettingsStore";

export async function leaveRoomBehaviour(roomId: string, retry = true, spinner = true): Promise<void> {
let spinnerModal: IHandle<any> | undefined;
Expand All @@ -44,7 +45,11 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =

const cli = MatrixClientPeg.get();
let leavingAllVersions = true;
const history = cli.getRoomUpgradeHistory(roomId);
const history = cli.getRoomUpgradeHistory(
roomId,
false,
SettingsStore.getValue("feature_dynamic_room_predecessors"),
);
if (history && history.length > 0) {
const currentRoom = history[history.length - 1];
if (currentRoom.roomId !== roomId) {
Expand Down
26 changes: 26 additions & 0 deletions test/utils/leave-behaviour-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import DMRoomMap from "../../src/utils/DMRoomMap";
import SpaceStore from "../../src/stores/spaces/SpaceStore";
import { MetaSpace } from "../../src/stores/spaces";
import { ActionPayload } from "../../src/dispatcher/payloads";
import SettingsStore from "../../src/settings/SettingsStore";

describe("leaveRoomBehaviour", () => {
SdkContextClass.instance.constructEagerStores(); // Initialize RoomViewStore
Expand Down Expand Up @@ -128,4 +129,29 @@ describe("leaveRoomBehaviour", () => {
metricsTrigger: undefined,
});
});

describe("If the feature_dynamic_room_predecessors is not enabled", () => {
beforeEach(() => {
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
});

it("Passes through the dynamic predecessor setting", async () => {
await leaveRoomBehaviour(room.roomId);
expect(client.getRoomUpgradeHistory).toHaveBeenCalledWith(room.roomId, false, false);
});
});

describe("If the feature_dynamic_room_predecessors is enabled", () => {
beforeEach(() => {
// Turn on feature_dynamic_room_predecessors setting
jest.spyOn(SettingsStore, "getValue").mockImplementation(
(settingName) => settingName === "feature_dynamic_room_predecessors",
);
});

it("Passes through the dynamic predecessor setting", async () => {
await leaveRoomBehaviour(room.roomId);
expect(client.getRoomUpgradeHistory).toHaveBeenCalledWith(room.roomId, false, true);
});
});
});

0 comments on commit 421c1b9

Please sign in to comment.