Fix room joining over federation not specifying vias or using aliases (#30641)
* Fix room joining over federation not specifying vias or using aliases Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Be consistent with viaServers Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Simplify modules Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Only consider canAskToJoin on 403 as per spec Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove unused helper which I only just added =( Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1b4a979b6c
commit
8fa3d7e4b7
@@ -5,37 +5,35 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import * as navigator from "../../../src/utils/permalinks/navigator";
|
||||
import { NavigationApi } from "../../../src/modules/Navigation.ts";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import defaultDispatcher from "../../../src/dispatcher/dispatcher.ts";
|
||||
|
||||
describe("NavigationApi", () => {
|
||||
const api = new NavigationApi();
|
||||
|
||||
describe("toMatrixToLink", () => {
|
||||
it("should call navigateToPermalink with the correct parameters", async () => {
|
||||
const link = "https://matrix.to/#/!roomId:server.com";
|
||||
it.each([
|
||||
["roomId", "https://matrix.to/#/!roomId:server.com"],
|
||||
["roomAlias", "https://matrix.to/#/#alias:server.com"],
|
||||
["user", "https://matrix.to/#/@user:server.com"],
|
||||
])("should call navigateToPermalink with the correct parameters for %s", async (_type, link) => {
|
||||
const spy = jest.spyOn(navigator, "navigateToPermalink");
|
||||
|
||||
await api.toMatrixToLink(link);
|
||||
expect(spy).toHaveBeenCalledWith(link);
|
||||
});
|
||||
|
||||
it("should resolve the room alias to a room id when join=true", async () => {
|
||||
const cli = stubClient();
|
||||
mocked(cli.getRoomIdForAlias).mockResolvedValue({ room_id: "!roomId:server.com", servers: [] });
|
||||
|
||||
const link = "https://matrix.to/#/#alias:server.com";
|
||||
it("should set auto_join to true when join=true", async () => {
|
||||
const link = "https://matrix.to/#/#alias:server.com?via=server.com";
|
||||
const spy = jest.spyOn(defaultDispatcher, "dispatch");
|
||||
|
||||
await api.toMatrixToLink(link, true);
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: "join_room",
|
||||
roomId: "!roomId:server.com",
|
||||
action: "view_room",
|
||||
room_alias: "#alias:server.com",
|
||||
auto_join: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -24,6 +24,7 @@ import defaultDispatcher from "../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../src/dispatcher/actions";
|
||||
import WidgetStore, { type IApp } from "../../../src/stores/WidgetStore";
|
||||
import { Container, WidgetLayoutStore } from "../../../src/stores/widgets/WidgetLayoutStore";
|
||||
import * as navigator from "../../../src/utils/permalinks/navigator.ts";
|
||||
|
||||
describe("ProxiedApiModule", () => {
|
||||
afterEach(() => {
|
||||
@@ -361,4 +362,30 @@ describe("ProxiedApiModule", () => {
|
||||
expect(WidgetLayoutStore.instance.moveToContainer).toHaveBeenCalledWith(room, app, Container.Top);
|
||||
});
|
||||
});
|
||||
|
||||
describe("navigatePermalink", () => {
|
||||
const api = new ProxiedModuleApi();
|
||||
|
||||
it("should call navigateToPermalink with the correct parameters", async () => {
|
||||
const link = "https://matrix.to/#/!roomId:server.com";
|
||||
const spy = jest.spyOn(navigator, "navigateToPermalink");
|
||||
|
||||
await api.navigatePermalink(link);
|
||||
expect(spy).toHaveBeenCalledWith(link);
|
||||
});
|
||||
|
||||
it("should set auto_join to true when join=true", async () => {
|
||||
const link = "https://matrix.to/#/#alias:server.com";
|
||||
const spy = jest.spyOn(defaultDispatcher, "dispatch");
|
||||
|
||||
await api.navigatePermalink(link, true);
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: "view_room",
|
||||
room_alias: "#alias:server.com",
|
||||
auto_join: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,6 +43,7 @@ import { type IApp } from "../../../src/utils/WidgetUtils-types";
|
||||
import { CallStore } from "../../../src/stores/CallStore";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import MediaDeviceHandler, { MediaDeviceKindEnum } from "../../../src/MediaDeviceHandler";
|
||||
import { storeRoomAliasInCache } from "../../../src/RoomAliasCache.ts";
|
||||
|
||||
jest.mock("../../../src/Modal");
|
||||
|
||||
@@ -211,6 +212,22 @@ describe("RoomViewStore", function () {
|
||||
expect(roomViewStore.isJoining()).toBe(true);
|
||||
});
|
||||
|
||||
it("can be used to view a room by alias with auto_join", async () => {
|
||||
const alias = "#alias12345:server";
|
||||
storeRoomAliasInCache(alias, roomId, ["server1"]);
|
||||
dis.dispatch({ action: Action.ViewRoom, room_alias: alias, auto_join: true }, true);
|
||||
await expect(untilDispatch(Action.ViewRoom, dis)).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
action: Action.ViewRoom,
|
||||
room_id: roomId,
|
||||
auto_join: true,
|
||||
}),
|
||||
);
|
||||
await untilDispatch(Action.JoinRoomReady, dis);
|
||||
expect(mockClient.joinRoom).toHaveBeenCalledWith(alias, { viaServers: ["server1"] });
|
||||
expect(roomViewStore.isJoining()).toBe(true);
|
||||
});
|
||||
|
||||
it("can auto-join a room", async () => {
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId, auto_join: true });
|
||||
await untilDispatch(Action.JoinRoomReady, dis);
|
||||
@@ -422,8 +439,8 @@ describe("RoomViewStore", function () {
|
||||
});
|
||||
|
||||
describe("Action.JoinRoom", () => {
|
||||
it("dispatches Action.JoinRoomError and Action.AskToJoin when the join fails", async () => {
|
||||
const err = new MatrixError();
|
||||
it("dispatches Action.JoinRoomError and Action.AskToJoin when the join fails with 403", async () => {
|
||||
const err = new MatrixError({}, 403);
|
||||
|
||||
jest.spyOn(dis, "dispatch");
|
||||
jest.spyOn(mockClient, "joinRoom").mockRejectedValueOnce(err);
|
||||
|
||||
@@ -41,6 +41,7 @@ import RoomListStore from "../../../src/stores/room-list/RoomListStore";
|
||||
import { DefaultTagID } from "../../../src/stores/room-list/models";
|
||||
import { RoomNotificationStateStore } from "../../../src/stores/notifications/RoomNotificationStateStore";
|
||||
import { NotificationLevel } from "../../../src/stores/notifications/NotificationLevel";
|
||||
import { storeRoomAliasInCache } from "../../../src/RoomAliasCache.ts";
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
@@ -1217,6 +1218,15 @@ describe("SpaceStore", () => {
|
||||
viewRoom(room1);
|
||||
expect(store.activeSpace).toBe(MetaSpace.Home);
|
||||
});
|
||||
|
||||
it("should check alias cache if switching to a room by alias", async () => {
|
||||
viewRoom(room2);
|
||||
storeRoomAliasInCache("#alias:server", room3, []);
|
||||
|
||||
store.setActiveSpace(space2, false);
|
||||
defaultDispatcher.dispatch({ action: Action.ViewRoom, room_alias: "#alias:server" }, true);
|
||||
expect(store.activeSpace).toBe(space1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("traverseSpace", () => {
|
||||
|
||||
Reference in New Issue
Block a user