Re-add creation of room by visiting the URL

Creates an unencrypted room if you land on an old-style simple URL
forn a room that doesn't exist.
This commit is contained in:
David Baker
2023-10-10 13:30:11 +01:00
parent 7ab69435e5
commit 8b9027da01
+22
View File
@@ -20,10 +20,12 @@ import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { SyncState } from "matrix-js-sdk/src/sync"; import { SyncState } from "matrix-js-sdk/src/sync";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession"; import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
import { MatrixError } from "matrix-js-sdk";
import type { Room } from "matrix-js-sdk/src/models/room"; import type { Room } from "matrix-js-sdk/src/models/room";
import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall"; import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall";
import { useEnableE2EE } from "../settings/useSetting"; import { useEnableE2EE } from "../settings/useSetting";
import { createRoom, isLocalRoomId, roomNameFromRoomId } from "../matrix-utils";
export type GroupCallLoaded = { export type GroupCallLoaded = {
kind: "loaded"; kind: "loaded";
@@ -69,6 +71,7 @@ export const useLoadGroupCall = (
// Also, we explicitly look up the room alias here. We previously just tried to // Also, we explicitly look up the room alias here. We previously just tried to
// join anyway but the js-sdk recreates the room if you pass the alias for a // join anyway but the js-sdk recreates the room if you pass the alias for a
// room you're already joined to (which it probably ought not to). // room you're already joined to (which it probably ought not to).
try {
const lookupResult = await client.getRoomIdForAlias( const lookupResult = await client.getRoomIdForAlias(
roomIdOrAlias.toLowerCase() roomIdOrAlias.toLowerCase()
); );
@@ -84,6 +87,25 @@ export const useLoadGroupCall = (
`Already in room ${lookupResult.room_id}, not rejoining.` `Already in room ${lookupResult.room_id}, not rejoining.`
); );
} }
} catch (e) {
if (
isLocalRoomId(roomIdOrAlias, client) &&
(e as MatrixError).errcode === "M_NOT_FOUND"
) {
// legacy path: create an unencrypted room if the user lands on a URL for a room that
// doesn't exist
const result = await createRoom(
client,
roomNameFromRoomId(roomIdOrAlias),
false
);
await client.waitUntilRoomReadyForGroupCalls(result.roomId);
return client.getRoom(result.roomId)!;
}
throw e;
}
} else { } else {
// room IDs we just try to join by their ID, which will not work in the // room IDs we just try to join by their ID, which will not work in the
// general case without providing some servers to join via. We could provide // general case without providing some servers to join via. We could provide