Make sure roomAlias = null in widget mode (#1676)

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo
2023-10-04 15:56:57 +02:00
committed by GitHub
parent 1eb2302060
commit c18dce3617

View File

@@ -224,33 +224,39 @@ export function getRoomIdentifierFromUrl(
hash: string hash: string
): RoomIdentifier { ): RoomIdentifier {
let roomAlias: string | null = null; let roomAlias: string | null = null;
pathname = pathname.substring(1); // Strip the "/"
const pathComponents = pathname.split("/");
const pathHasRoom = pathComponents[0] == "room";
const hasRoomAlias = pathComponents.length > 1;
// Here we handle the beginning of the alias and make sure it starts with a "#" // What type is our url: roomAlias in hash, room alias as the search path, roomAlias after /room/
if (hash === "" || hash.startsWith("#?")) { if (hash === "" || hash.startsWith("#?")) {
roomAlias = pathname.substring(1); // Strip the "/" if (hasRoomAlias && pathHasRoom) {
roomAlias = pathComponents[1];
// Delete "/room/", if present
if (roomAlias.startsWith("room/")) {
roomAlias = roomAlias.substring("room/".length);
} }
// Add "#", if not present if (!pathHasRoom) {
if (!roomAlias.startsWith("#")) { roomAlias = pathComponents[0];
roomAlias = `#${roomAlias}`;
} }
} else { } else {
roomAlias = hash; roomAlias = hash;
} }
// Delete "?" and what comes afterwards // Delete "?" and what comes afterwards
roomAlias = roomAlias.split("?")[0]; roomAlias = roomAlias?.split("?")[0] ?? null;
if (roomAlias.length <= 1) { if (roomAlias) {
// Make roomAlias is null, if it only is a "#" // Make roomAlias is null, if it only is a "#"
roomAlias = null; if (roomAlias.length <= 1) {
} else { roomAlias = null;
// Add server part, if not present } else {
if (!roomAlias.includes(":")) { // Add "#", if not present
roomAlias = `${roomAlias}:${Config.defaultServerName()}`; if (!roomAlias.startsWith("#")) {
roomAlias = `#${roomAlias}`;
}
// Add server part, if not present
if (!roomAlias.includes(":")) {
roomAlias = `${roomAlias}:${Config.defaultServerName()}`;
}
} }
} }