Fix room creation
The room alias is not part of the spec. Synapse returns it anyway, but it's not part of the js-sdk types. We don't really need the server to tell us what the alias is, so just generate it locally instead.
This commit is contained in:
parent
9edc1acc90
commit
2cf40ff0b8
3 changed files with 15 additions and 8 deletions
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useState, useCallback } from "react";
|
import React, { useState, useCallback } from "react";
|
||||||
import { createRoom, roomAliasFromRoomName } from "../matrix-utils";
|
import { createRoom, roomAliasLocalpartFromRoomName } from "../matrix-utils";
|
||||||
import { useGroupCallRooms } from "./useGroupCallRooms";
|
import { useGroupCallRooms } from "./useGroupCallRooms";
|
||||||
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
|
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
|
||||||
import commonStyles from "./common.module.css";
|
import commonStyles from "./common.module.css";
|
||||||
|
|
@ -56,7 +56,7 @@ export function RegisteredView({ client }) {
|
||||||
|
|
||||||
submit().catch((error) => {
|
submit().catch((error) => {
|
||||||
if (error.errcode === "M_ROOM_IN_USE") {
|
if (error.errcode === "M_ROOM_IN_USE") {
|
||||||
setExistingRoomId(roomAliasFromRoomName(roomName));
|
setExistingRoomId(roomAliasLocalpartFromRoomName(roomName));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setError(undefined);
|
setError(undefined);
|
||||||
modalState.open();
|
modalState.open();
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import { useHistory } from "react-router-dom";
|
||||||
import { FieldRow, InputField, ErrorMessage } from "../input/Input";
|
import { FieldRow, InputField, ErrorMessage } from "../input/Input";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||||
import { createRoom, roomAliasFromRoomName } from "../matrix-utils";
|
import { createRoom, roomAliasLocalpartFromRoomName } from "../matrix-utils";
|
||||||
import { useInteractiveRegistration } from "../auth/useInteractiveRegistration";
|
import { useInteractiveRegistration } from "../auth/useInteractiveRegistration";
|
||||||
import { useModalTriggerState } from "../Modal";
|
import { useModalTriggerState } from "../Modal";
|
||||||
import { JoinExistingCallModal } from "./JoinExistingCallModal";
|
import { JoinExistingCallModal } from "./JoinExistingCallModal";
|
||||||
|
|
@ -75,7 +75,7 @@ export function UnauthenticatedView() {
|
||||||
if (error.errcode === "M_ROOM_IN_USE") {
|
if (error.errcode === "M_ROOM_IN_USE") {
|
||||||
setOnFinished(() => () => {
|
setOnFinished(() => () => {
|
||||||
setClient(client, session);
|
setClient(client, session);
|
||||||
const aliasLocalpart = roomAliasFromRoomName(roomName);
|
const aliasLocalpart = roomAliasLocalpartFromRoomName(roomName);
|
||||||
const [, serverName] = client.getUserId().split(":");
|
const [, serverName] = client.getUserId().split(":");
|
||||||
history.push(`/room/#${aliasLocalpart}:${serverName}`);
|
history.push(`/room/#${aliasLocalpart}:${serverName}`);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ export async function initClient(
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function roomAliasFromRoomName(roomName: string): string {
|
export function roomAliasLocalpartFromRoomName(roomName: string): string {
|
||||||
return roomName
|
return roomName
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/\s/g, "-")
|
.replace(/\s/g, "-")
|
||||||
|
|
@ -116,6 +116,13 @@ export function roomAliasFromRoomName(roomName: string): string {
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fullAliasFromRoomName(
|
||||||
|
roomName: string,
|
||||||
|
client: MatrixClient
|
||||||
|
): string {
|
||||||
|
return `#${roomAliasLocalpartFromRoomName(roomName)}:${client.getDomain()}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function roomNameFromRoomId(roomId: string): string {
|
export function roomNameFromRoomId(roomId: string): string {
|
||||||
return roomId
|
return roomId
|
||||||
.match(/([^:]+):.*$/)[1]
|
.match(/([^:]+):.*$/)[1]
|
||||||
|
|
@ -151,7 +158,7 @@ export async function createRoom(
|
||||||
visibility: Visibility.Private,
|
visibility: Visibility.Private,
|
||||||
preset: Preset.PublicChat,
|
preset: Preset.PublicChat,
|
||||||
name,
|
name,
|
||||||
room_alias_name: roomAliasFromRoomName(name),
|
room_alias_name: roomAliasLocalpartFromRoomName(name),
|
||||||
power_level_content_override: {
|
power_level_content_override: {
|
||||||
invite: 100,
|
invite: 100,
|
||||||
kick: 100,
|
kick: 100,
|
||||||
|
|
@ -177,7 +184,7 @@ export async function createRoom(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log({ isPtt });
|
console.log(`Creating ${isPtt ? "PTT" : "video"} group call room`);
|
||||||
|
|
||||||
await client.createGroupCall(
|
await client.createGroupCall(
|
||||||
createRoomResult.room_id,
|
createRoomResult.room_id,
|
||||||
|
|
@ -186,7 +193,7 @@ export async function createRoom(
|
||||||
GroupCallIntent.Prompt
|
GroupCallIntent.Prompt
|
||||||
);
|
);
|
||||||
|
|
||||||
return createRoomResult.room_id;
|
return fullAliasFromRoomName(name, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRoomUrl(roomId: string): string {
|
export function getRoomUrl(roomId: string): string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue