diff --git a/package.json b/package.json
index 6a5a47a1..7cf8eb1d 100644
--- a/package.json
+++ b/package.json
@@ -106,6 +106,7 @@
"identity-obj-proxy": "^3.0.0",
"jest": "^29.2.2",
"jest-environment-jsdom": "^29.3.1",
+ "jest-mock": "^29.5.0",
"prettier": "^2.6.2",
"sass": "^1.42.1",
"storybook-builder-vite": "^0.1.12",
diff --git a/src/App.tsx b/src/App.tsx
index 0ef5bcd6..71cc9710 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -24,7 +24,6 @@ import { HomePage } from "./home/HomePage";
import { LoginPage } from "./auth/LoginPage";
import { RegisterPage } from "./auth/RegisterPage";
import { RoomPage } from "./room/RoomPage";
-import { RoomRedirect } from "./room/RoomRedirect";
import { ClientProvider } from "./ClientContext";
import { usePageFocusStyle } from "./usePageFocusStyle";
import { SequenceDiagramViewerPage } from "./SequenceDiagramViewerPage";
@@ -71,14 +70,11 @@ export default function App({ history }: AppProps) {
-
-
-
-
+
diff --git a/src/UrlParams.ts b/src/UrlParams.ts
index eb2b1795..f41e3cfa 100644
--- a/src/UrlParams.ts
+++ b/src/UrlParams.ts
@@ -1,5 +1,5 @@
/*
-Copyright 2022 New Vector Ltd
+Copyright 2022 - 2023 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@ limitations under the License.
import { useMemo } from "react";
import { useLocation } from "react-router-dom";
+import { Config } from "./config/Config";
+
interface UrlParams {
roomAlias: string | null;
roomId: string | null;
@@ -93,14 +95,39 @@ interface UrlParams {
* @returns The app parameters encoded in the URL
*/
export const getUrlParams = (
- query: string = window.location.search,
- fragment: string = window.location.hash
+ ignoreRoomAlias?: boolean,
+ search = window.location.search,
+ pathname = window.location.pathname,
+ hash = window.location.hash
): UrlParams => {
- const fragmentQueryStart = fragment.indexOf("?");
+ let roomAlias: string | undefined;
+ if (!ignoreRoomAlias) {
+ if (hash === "") {
+ roomAlias = pathname.substring(1); // Strip the "/"
+
+ // Delete "/room/" and "?", if present
+ if (roomAlias.startsWith("room/")) {
+ roomAlias = roomAlias.substring("room/".length);
+ }
+ // Add "#", if not present
+ if (!roomAlias.startsWith("#")) {
+ roomAlias = `#${roomAlias}`;
+ }
+ } else {
+ roomAlias = hash;
+ }
+
+ // Add server part, if not present
+ if (!roomAlias.includes(":")) {
+ roomAlias = `${roomAlias}:${Config.defaultServerName()}`;
+ }
+ }
+
+ const fragmentQueryStart = hash.indexOf("?");
const fragmentParams = new URLSearchParams(
- fragmentQueryStart === -1 ? "" : fragment.substring(fragmentQueryStart)
+ fragmentQueryStart === -1 ? "" : hash.substring(fragmentQueryStart)
);
- const queryParams = new URLSearchParams(query);
+ const queryParams = new URLSearchParams(search);
// Normally, URL params should be encoded in the fragment so as to avoid
// leaking them to the server. However, we also check the normal query
@@ -114,16 +141,10 @@ export const getUrlParams = (
...queryParams.getAll(name),
];
- // The part of the fragment before the ?
- const fragmentRoute =
- fragmentQueryStart === -1
- ? fragment
- : fragment.substring(0, fragmentQueryStart);
-
const fontScale = parseFloat(getParam("fontScale") ?? "");
return {
- roomAlias: fragmentRoute.length > 1 ? fragmentRoute : null,
+ roomAlias: !roomAlias || roomAlias.includes("!") ? null : roomAlias,
roomId: getParam("roomId"),
viaServers: getAllParams("via"),
isEmbedded: hasParam("embed"),
@@ -149,6 +170,9 @@ export const getUrlParams = (
* @returns The app parameters for the current URL
*/
export const useUrlParams = (): UrlParams => {
- const { hash, search } = useLocation();
- return useMemo(() => getUrlParams(search, hash), [search, hash]);
+ const { search, pathname, hash } = useLocation();
+ return useMemo(
+ () => getUrlParams(false, search, pathname, hash),
+ [search, pathname, hash]
+ );
};
diff --git a/src/home/CallList.tsx b/src/home/CallList.tsx
index 545dfade..c3d5a6ae 100644
--- a/src/home/CallList.tsx
+++ b/src/home/CallList.tsx
@@ -35,13 +35,13 @@ export function CallList({ rooms, client, disableFacepile }: CallListProps) {
return (
<>
- {rooms.map(({ roomId, roomName, avatarUrl, participants }) => (
+ {rooms.map(({ roomAlias, roomName, avatarUrl, participants }) => (
@@ -59,7 +59,7 @@ export function CallList({ rooms, client, disableFacepile }: CallListProps) {
interface CallTileProps {
name: string;
avatarUrl: string;
- roomId: string;
+ roomAlias: string;
participants: RoomMember[];
client: MatrixClient;
disableFacepile?: boolean;
@@ -67,14 +67,17 @@ interface CallTileProps {
function CallTile({
name,
avatarUrl,
- roomId,
+ roomAlias,
participants,
client,
disableFacepile,
}: CallTileProps) {
return (