From 20dc6df7418dcbd698fb9bdc13d3682e7fd7faab Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 30 Mar 2023 14:05:56 +0100 Subject: [PATCH 01/17] Improve typing in constructor of RoomPermalinkCreator --- src/utils/permalinks/Permalinks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/permalinks/Permalinks.ts b/src/utils/permalinks/Permalinks.ts index caae2eb6c38..641d119d96a 100644 --- a/src/utils/permalinks/Permalinks.ts +++ b/src/utils/permalinks/Permalinks.ts @@ -96,7 +96,7 @@ export class RoomPermalinkCreator { // Some of the tests done by this class are relatively expensive, so normally // throttled to not happen on every update. Pass false as the shouldThrottle // param to disable this behaviour, eg. for tests. - public constructor(private room: Room, roomId: string | null = null, shouldThrottle = true) { + public constructor(private room: Room | null, roomId: string | null = null, shouldThrottle = true) { this.roomId = room ? room.roomId : roomId!; if (!this.roomId) { From c6736e0ddb60cd7028022c60e557064c8b447b2d Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 30 Mar 2023 14:06:50 +0100 Subject: [PATCH 02/17] Provide via servers if present when navigating to predecessor room from Advanced Room Settings --- .../views/settings/tabs/room/AdvancedRoomSettingsTab.tsx | 3 +++ .../views/settings/tabs/room/AdvancedRoomSettingsTab-test.tsx | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx index 34153819fc0..8482bbada4d 100644 --- a/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx @@ -44,6 +44,7 @@ interface IState { upgradeRecommendation?: IRecommendedVersion; oldRoomId?: string; oldEventId?: string; + oldViaServers?: string[]; upgraded?: boolean; } @@ -65,6 +66,7 @@ export default class AdvancedRoomSettingsTab extends React.Component { mocked(dis.dispatch).mockReset(); mocked(room.findPredecessor).mockImplementation((msc3946: boolean) => msc3946 - ? { roomId: "old_room_id_via_predecessor" } + ? { roomId: "old_room_id_via_predecessor", viaServers: ["one.example.com", "two.example.com"] } : { roomId: "old_room_id", eventId: "tombstone_event_id" }, ); }); @@ -138,6 +138,7 @@ describe("AdvancedRoomSettingsTab", () => { action: Action.ViewRoom, event_id: undefined, room_id: "old_room_id_via_predecessor", + via_servers: ["one.example.com", "two.example.com"], metricsTrigger: "WebPredecessorSettings", metricsViaKeyboard: false, }); From 0075c0c24e4d4c20af598d9e948900c738ca74d4 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 30 Mar 2023 14:07:54 +0100 Subject: [PATCH 03/17] Show an error tile when the predecessor room is not found --- .../views/messages/RoomPredecessorTile.tsx | 16 +++++++++++- src/i18n/strings/en_EN.json | 3 ++- .../messages/RoomPredecessorTile-test.tsx | 26 ++++++++++++++++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index 5c47cda56fe..0f3fea90907 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -88,7 +88,21 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => const prevRoom = MatrixClientPeg.get().getRoom(predecessor.roomId); if (!prevRoom) { logger.warn(`Failed to find predecessor room with id ${predecessor.roomId}`); - return <>; + return ( + +
+ + {_t("Can't find the old version of this room (room id: %(roomId)s).", { + roomId: predecessor.roomId, + })} + +
+
+ ); } const permalinkCreator = new RoomPermalinkCreator(prevRoom, predecessor.roomId); permalinkCreator.load(); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index f67847fd925..8ae06736aea 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2464,8 +2464,9 @@ "%(senderDisplayName)s changed the avatar for %(roomName)s": "%(senderDisplayName)s changed the avatar for %(roomName)s", "%(senderDisplayName)s removed the room avatar.": "%(senderDisplayName)s removed the room avatar.", "%(senderDisplayName)s changed the room avatar to ": "%(senderDisplayName)s changed the room avatar to ", - "Click here to see older messages.": "Click here to see older messages.", "This room is a continuation of another conversation.": "This room is a continuation of another conversation.", + "Can't find the old version of this room (room id: %(roomId)s).": "Can't find the old version of this room (room id: %(roomId)s).", + "Click here to see older messages.": "Click here to see older messages.", "Add an Integration": "Add an Integration", "You are about to be taken to a third-party site so you can authenticate your account for use with %(integrationsUrl)s. Do you wish to continue?": "You are about to be taken to a third-party site so you can authenticate your account for use with %(integrationsUrl)s. Do you wish to continue?", "Edited at %(date)s": "Edited at %(date)s", diff --git a/test/components/views/messages/RoomPredecessorTile-test.tsx b/test/components/views/messages/RoomPredecessorTile-test.tsx index 61bf8e82c5a..6f3d5dbba57 100644 --- a/test/components/views/messages/RoomPredecessorTile-test.tsx +++ b/test/components/views/messages/RoomPredecessorTile-test.tsx @@ -26,7 +26,7 @@ import { RoomPredecessorTile } from "../../../../src/components/views/messages/R import { stubClient, upsertRoomStateEvents } from "../../../test-utils/test-utils"; import { Action } from "../../../../src/dispatcher/actions"; import RoomContext from "../../../../src/contexts/RoomContext"; -import { getRoomContext } from "../../../test-utils"; +import { filterConsole, getRoomContext } from "../../../test-utils"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; jest.mock("../../../../src/dispatcher/dispatcher"); @@ -118,9 +118,14 @@ describe("", () => { ); }); - it("Shows an empty div if there is no predecessor", () => { - renderTile(roomNoPredecessors); - expect(screen.queryByText("Click here to see older messages.", { exact: false })).toBeNull(); + describe("(filtering warnings about no predecessor)", () => { + filterConsole("RoomPredecessorTile unexpectedly used in a room with no predecessor."); + + it("Shows an empty div if there is no predecessor", () => { + filterConsole; + renderTile(roomNoPredecessors); + expect(screen.queryByText("Click here to see older messages.", { exact: false })).toBeNull(); + }); }); it("Opens the old room on click", async () => { @@ -149,6 +154,19 @@ describe("", () => { ); }); + describe("If the predecessor room is not found", () => { + filterConsole("Failed to find predecessor room with id old_room_id"); + + beforeEach(() => { + mocked(MatrixClientPeg.get().getRoom).mockReturnValue(null); + }); + + it("Shows an error", () => { + renderTile(roomCreateAndPredecessor); + expect(screen.getByText("Can't find the old version of this room", { exact: false })).toBeInTheDocument(); + }); + }); + describe("When feature_dynamic_room_predecessors = true", () => { beforeEach(() => { jest.spyOn(SettingsStore, "getValue").mockImplementation( From edb38a8ad275743f29c94689d94c112843748c71 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 30 Mar 2023 14:27:52 +0100 Subject: [PATCH 04/17] Test for MatrixToPermalinkConstructor.forRoom --- .../utils/permalinks/MatrixToPermalinkConstructor-test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts b/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts index e8750114136..7a4fa5a60b7 100644 --- a/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts +++ b/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts @@ -41,4 +41,12 @@ describe("MatrixToPermalinkConstructor", () => { ); }); }); + + describe("forRoom", () => { + it("constructs a link given a room ID and via servers", () => { + expect(peramlinkConstructor.forRoom("!myroom:example.com", ["one.example.com", "two.example.com"])).toEqual( + "https://matrix.to/#/!myroom:example.com?via=one.example.com&via=two.example.com", + ); + }); + }); }); From 44762c904f4f88f172bef67e2ea42ee64cfe9924 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 30 Mar 2023 17:22:29 +0100 Subject: [PATCH 05/17] Test for MatrixToPermalinkConstructor.forEvent --- .../utils/permalinks/MatrixToPermalinkConstructor-test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts b/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts index 7a4fa5a60b7..27cd4a993a3 100644 --- a/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts +++ b/test/utils/permalinks/MatrixToPermalinkConstructor-test.ts @@ -49,4 +49,12 @@ describe("MatrixToPermalinkConstructor", () => { ); }); }); + + describe("forEvent", () => { + it("constructs a link given an event ID, room ID and via servers", () => { + expect( + peramlinkConstructor.forEvent("!myroom:example.com", "$event4", ["one.example.com", "two.example.com"]), + ).toEqual("https://matrix.to/#/!myroom:example.com/$event4?via=one.example.com&via=two.example.com"); + }); + }); }); From 9767dea2a263620d657345dc9bc12b63c69f2402 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 30 Mar 2023 17:31:06 +0100 Subject: [PATCH 06/17] Display a tile for predecessor event if it contains via servers --- .../views/messages/RoomPredecessorTile.tsx | 39 ++++++++++++++----- .../messages/RoomPredecessorTile-test.tsx | 38 +++++++++++++++++- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index 0f3fea90907..99cee680760 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -18,6 +18,7 @@ limitations under the License. import React, { useCallback, useContext } from "react"; import { logger } from "matrix-js-sdk/src/logger"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { Room } from "matrix-js-sdk/src/matrix"; import dis from "../../../dispatcher/dispatcher"; import { Action } from "../../../dispatcher/actions"; @@ -29,6 +30,7 @@ import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; import RoomContext from "../../../contexts/RoomContext"; import { useRoomState } from "../../../hooks/useRoomState"; import SettingsStore from "../../../settings/SettingsStore"; +import MatrixToPermalinkConstructor from "../../../utils/permalinks/MatrixToPermalinkConstructor"; interface IProps { /** The m.room.create MatrixEvent that this tile represents */ @@ -86,7 +88,10 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => } const prevRoom = MatrixClientPeg.get().getRoom(predecessor.roomId); - if (!prevRoom) { + + // We need either the previous room, or some servers to find it with. + // Otherwise, we must bail out here + if (!prevRoom && !predecessor.viaServers) { logger.warn(`Failed to find predecessor room with id ${predecessor.roomId}`); return ( = ({ mxEvent, timestamp }) => ); } - const permalinkCreator = new RoomPermalinkCreator(prevRoom, predecessor.roomId); - permalinkCreator.load(); - let predecessorPermalink: string; - if (predecessor.eventId) { - predecessorPermalink = permalinkCreator.forEvent(predecessor.eventId); - } else { - predecessorPermalink = permalinkCreator.forRoom(); - } + + const predecessorPermalink = prevRoom + ? createLinkWithRoom(prevRoom, predecessor.roomId, predecessor.eventId) + : createLinkWithoutRoom(predecessor.roomId, predecessor.viaServers); + const link = ( {_t("Click here to see older messages.")} @@ -126,4 +128,23 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => timestamp={timestamp} /> ); + + function createLinkWithRoom(room: Room, roomId: string, eventId?: string): string { + const permalinkCreator = new RoomPermalinkCreator(room, roomId); + permalinkCreator.load(); + if (eventId) { + return permalinkCreator.forEvent(eventId); + } else { + return permalinkCreator.forRoom(); + } + } + + function createLinkWithoutRoom(roomId: string, viaServers: string[], eventId?: string): string { + const matrixToPermalinkConstructor = new MatrixToPermalinkConstructor(); + if (eventId) { + return matrixToPermalinkConstructor.forEvent(roomId, eventId, viaServers); + } else { + return matrixToPermalinkConstructor.forRoom(roomId, viaServers); + } + } }; diff --git a/test/components/views/messages/RoomPredecessorTile-test.tsx b/test/components/views/messages/RoomPredecessorTile-test.tsx index 6f3d5dbba57..fbdac1c7c53 100644 --- a/test/components/views/messages/RoomPredecessorTile-test.tsx +++ b/test/components/views/messages/RoomPredecessorTile-test.tsx @@ -62,6 +62,17 @@ describe("", () => { }, event_id: "$create", }); + const viaPredecessorEvent = new MatrixEvent({ + type: EventType.RoomPredecessor, + state_key: "", + sender: userId, + room_id: roomId, + content: { + predecessor_room_id: "old_room_id_from_predecessor", + via_servers: ["a.example.com", "b.example.com"], + }, + event_id: "$create", + }); const predecessorEventWithEventId = new MatrixEvent({ type: EventType.RoomPredecessor, state_key: "", @@ -83,6 +94,8 @@ describe("", () => { upsertRoomStateEvents(roomCreateAndPredecessorWithEventId, [createEvent, predecessorEventWithEventId]); const roomNoPredecessors = new Room(roomId, client, userId); upsertRoomStateEvents(roomNoPredecessors, [createEventWithoutPredecessor]); + const roomCreateAndViaPredecessor = new Room(roomId, client, userId); + upsertRoomStateEvents(roomCreateAndViaPredecessor, [createEvent, viaPredecessorEvent]); beforeEach(() => { jest.clearAllMocks(); @@ -161,7 +174,7 @@ describe("", () => { mocked(MatrixClientPeg.get().getRoom).mockReturnValue(null); }); - it("Shows an error", () => { + it("Shows an error if there are no via servers", () => { renderTile(roomCreateAndPredecessor); expect(screen.getByText("Can't find the old version of this room", { exact: false })).toBeInTheDocument(); }); @@ -201,5 +214,28 @@ describe("", () => { "https://matrix.to/#/old_room_id_from_predecessor/tombstone_event_id_from_predecessor", ); }); + + describe("If the predecessor room is not found", () => { + filterConsole("Failed to find predecessor room with id old_room_id"); + + beforeEach(() => { + mocked(MatrixClientPeg.get().getRoom).mockReturnValue(null); + }); + + it("Shows an error if there are no via servers", () => { + renderTile(roomCreateAndPredecessor); + expect( + screen.getByText("Can't find the old version of this room", { exact: false }), + ).toBeInTheDocument(); + }); + + it("Shows a tile if there are via servers", () => { + renderTile(roomCreateAndViaPredecessor); + expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( + "href", + "https://matrix.to/#/old_room_id_from_predecessor?via=a.example.com&via=b.example.com", + ); + }); + }); }); }); From 21c834180a96eba319eb1c4d3fcd5a33a4f69f44 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Mon, 3 Apr 2023 16:27:57 +0100 Subject: [PATCH 07/17] Fix missing case where event id is provided as well as via servers --- .../views/messages/RoomPredecessorTile.tsx | 2 +- .../messages/RoomPredecessorTile-test.tsx | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index 99cee680760..7edd80d00a8 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -112,7 +112,7 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => const predecessorPermalink = prevRoom ? createLinkWithRoom(prevRoom, predecessor.roomId, predecessor.eventId) - : createLinkWithoutRoom(predecessor.roomId, predecessor.viaServers); + : createLinkWithoutRoom(predecessor.roomId, predecessor.viaServers, predecessor.eventId); const link = ( diff --git a/test/components/views/messages/RoomPredecessorTile-test.tsx b/test/components/views/messages/RoomPredecessorTile-test.tsx index fbdac1c7c53..afc840b69d6 100644 --- a/test/components/views/messages/RoomPredecessorTile-test.tsx +++ b/test/components/views/messages/RoomPredecessorTile-test.tsx @@ -236,6 +236,29 @@ describe("", () => { "https://matrix.to/#/old_room_id_from_predecessor?via=a.example.com&via=b.example.com", ); }); + + it("Shows a tile linking to an event if there are via servers", () => { + const predecessorEvent = new MatrixEvent({ + type: EventType.RoomPredecessor, + state_key: "", + sender: userId, + room_id: roomId, + content: { + predecessor_room_id: "old_room_id_from_predecessor", + last_known_event_id: "$tombstone", + via_servers: ["a.example.com", "b.example.com"], + }, + event_id: "$create", + }); + const room = new Room(roomId, client, userId); + upsertRoomStateEvents(room, [createEvent, predecessorEvent]); + + renderTile(room); + expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( + "href", + "https://matrix.to/#/old_room_id_from_predecessor/$tombstone?via=a.example.com&via=b.example.com", + ); + }); }); }); }); From 849b45b14ac163f25eaa38b682b2382658e5fa13 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Mon, 3 Apr 2023 17:38:32 +0100 Subject: [PATCH 08/17] Refactor RoomPredecessor tests --- .../messages/RoomPredecessorTile-test.tsx | 187 +++++++++--------- .../RoomPredecessorTile-test.tsx.snap | 2 +- 2 files changed, 95 insertions(+), 94 deletions(-) diff --git a/test/components/views/messages/RoomPredecessorTile-test.tsx b/test/components/views/messages/RoomPredecessorTile-test.tsx index afc840b69d6..a010c1fa4cd 100644 --- a/test/components/views/messages/RoomPredecessorTile-test.tsx +++ b/test/components/views/messages/RoomPredecessorTile-test.tsx @@ -34,68 +34,61 @@ jest.mock("../../../../src/dispatcher/dispatcher"); describe("", () => { const userId = "@alice:server.org"; const roomId = "!room:server.org"; - const createEvent = new MatrixEvent({ - type: EventType.RoomCreate, - state_key: "", - sender: userId, - room_id: roomId, - content: { - predecessor: { room_id: "old_room_id", event_id: "tombstone_event_id" }, - }, - event_id: "$create", - }); - const createEventWithoutPredecessor = new MatrixEvent({ - type: EventType.RoomCreate, - state_key: "", - sender: userId, - room_id: roomId, - content: {}, - event_id: "$create", - }); - const predecessorEvent = new MatrixEvent({ - type: EventType.RoomPredecessor, - state_key: "", - sender: userId, - room_id: roomId, - content: { - predecessor_room_id: "old_room_id_from_predecessor", - }, - event_id: "$create", - }); - const viaPredecessorEvent = new MatrixEvent({ - type: EventType.RoomPredecessor, - state_key: "", - sender: userId, - room_id: roomId, - content: { - predecessor_room_id: "old_room_id_from_predecessor", - via_servers: ["a.example.com", "b.example.com"], - }, - event_id: "$create", - }); - const predecessorEventWithEventId = new MatrixEvent({ - type: EventType.RoomPredecessor, - state_key: "", - sender: userId, - room_id: roomId, - content: { - predecessor_room_id: "old_room_id_from_predecessor", - last_known_event_id: "tombstone_event_id_from_predecessor", - }, - event_id: "$create", - }); stubClient(); const client = mocked(MatrixClientPeg.get()); - const roomJustCreate = new Room(roomId, client, userId); - upsertRoomStateEvents(roomJustCreate, [createEvent]); - const roomCreateAndPredecessor = new Room(roomId, client, userId); - upsertRoomStateEvents(roomCreateAndPredecessor, [createEvent, predecessorEvent]); - const roomCreateAndPredecessorWithEventId = new Room(roomId, client, userId); - upsertRoomStateEvents(roomCreateAndPredecessorWithEventId, [createEvent, predecessorEventWithEventId]); - const roomNoPredecessors = new Room(roomId, client, userId); - upsertRoomStateEvents(roomNoPredecessors, [createEventWithoutPredecessor]); - const roomCreateAndViaPredecessor = new Room(roomId, client, userId); - upsertRoomStateEvents(roomCreateAndViaPredecessor, [createEvent, viaPredecessorEvent]); + + function makeRoom({ + createEventHasPredecessor = false, + predecessorEventExists = false, + predecessorEventHasEventId = false, + predecessorEventHasViaServers = false, + }): Room { + const room = new Room(roomId, client, userId); + + const createInfo = { + type: EventType.RoomCreate, + state_key: "", + sender: userId, + room_id: roomId, + content: {}, + event_id: "$create", + }; + + if (createEventHasPredecessor) { + createInfo.content = { + predecessor: { room_id: "old_room_id", event_id: "$tombstone_event_id" }, + }; + } + + const createEvent = new MatrixEvent(createInfo); + upsertRoomStateEvents(room, [createEvent]); + + if (predecessorEventExists) { + const predecessorInfo = { + type: EventType.RoomPredecessor, + state_key: "", + sender: userId, + room_id: roomId, + content: { + predecessor_room_id: "old_room_id_from_predecessor", + last_known_event_id: undefined, + via_servers: undefined, + }, + event_id: "$predecessor", + }; + + if (predecessorEventHasEventId) { + predecessorInfo.content.last_known_event_id = "$tombstone_event_id_from_predecessor"; + } + if (predecessorEventHasViaServers) { + predecessorInfo.content.via_servers = ["a.example.com", "b.example.com"]; + } + + const predecessorEvent = new MatrixEvent(predecessorInfo); + upsertRoomStateEvents(room, [predecessorEvent]); + } + return room; + } beforeEach(() => { jest.clearAllMocks(); @@ -111,6 +104,10 @@ describe("", () => { }); function renderTile(room: Room) { + // Find this room's create event (it should have one!) + const createEvent = room.currentState.getStateEvents("m.room.create")[0]; + expect(createEvent).toBeTruthy(); + return render( @@ -119,15 +116,15 @@ describe("", () => { } it("Renders as expected", () => { - const roomCreate = renderTile(roomJustCreate); + const roomCreate = renderTile(makeRoom({ createEventHasPredecessor: true })); expect(roomCreate.asFragment()).toMatchSnapshot(); }); it("Links to the old version of the room", () => { - renderTile(roomJustCreate); + renderTile(makeRoom({ createEventHasPredecessor: true })); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", - "https://matrix.to/#/old_room_id/tombstone_event_id", + "https://matrix.to/#/old_room_id/$tombstone_event_id", ); }); @@ -136,13 +133,13 @@ describe("", () => { it("Shows an empty div if there is no predecessor", () => { filterConsole; - renderTile(roomNoPredecessors); + renderTile(makeRoom({})); expect(screen.queryByText("Click here to see older messages.", { exact: false })).toBeNull(); }); }); it("Opens the old room on click", async () => { - renderTile(roomJustCreate); + renderTile(makeRoom({ createEventHasPredecessor: true })); const link = screen.getByText("Click here to see older messages."); await act(() => userEvent.click(link)); @@ -150,7 +147,7 @@ describe("", () => { await waitFor(() => expect(dis.dispatch).toHaveBeenCalledWith({ action: Action.ViewRoom, - event_id: "tombstone_event_id", + event_id: "$tombstone_event_id", highlighted: true, room_id: "old_room_id", metricsTrigger: "Predecessor", @@ -160,10 +157,10 @@ describe("", () => { }); it("Ignores m.predecessor if labs flag is off", () => { - renderTile(roomCreateAndPredecessor); + renderTile(makeRoom({ createEventHasPredecessor: true, predecessorEventExists: true })); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", - "https://matrix.to/#/old_room_id/tombstone_event_id", + "https://matrix.to/#/old_room_id/$tombstone_event_id", ); }); @@ -175,7 +172,7 @@ describe("", () => { }); it("Shows an error if there are no via servers", () => { - renderTile(roomCreateAndPredecessor); + renderTile(makeRoom({ createEventHasPredecessor: true, predecessorEventExists: true })); expect(screen.getByText("Can't find the old version of this room", { exact: false })).toBeInTheDocument(); }); }); @@ -192,15 +189,15 @@ describe("", () => { }); it("Uses the create event if there is no m.predecessor", () => { - renderTile(roomJustCreate); + renderTile(makeRoom({ createEventHasPredecessor: true })); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", - "https://matrix.to/#/old_room_id/tombstone_event_id", + "https://matrix.to/#/old_room_id/$tombstone_event_id", ); }); it("Uses m.predecessor when it's there", () => { - renderTile(roomCreateAndPredecessor); + renderTile(makeRoom({ createEventHasPredecessor: true, predecessorEventExists: true })); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", "https://matrix.to/#/old_room_id_from_predecessor", @@ -208,10 +205,16 @@ describe("", () => { }); it("Links to the event in the room if event ID is provided", () => { - renderTile(roomCreateAndPredecessorWithEventId); + renderTile( + makeRoom({ + createEventHasPredecessor: true, + predecessorEventExists: true, + predecessorEventHasEventId: true, + }), + ); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", - "https://matrix.to/#/old_room_id_from_predecessor/tombstone_event_id_from_predecessor", + "https://matrix.to/#/old_room_id_from_predecessor/$tombstone_event_id_from_predecessor", ); }); @@ -223,14 +226,20 @@ describe("", () => { }); it("Shows an error if there are no via servers", () => { - renderTile(roomCreateAndPredecessor); + renderTile(makeRoom({ createEventHasPredecessor: true, predecessorEventExists: true })); expect( screen.getByText("Can't find the old version of this room", { exact: false }), ).toBeInTheDocument(); }); it("Shows a tile if there are via servers", () => { - renderTile(roomCreateAndViaPredecessor); + renderTile( + makeRoom({ + createEventHasPredecessor: true, + predecessorEventExists: true, + predecessorEventHasViaServers: true, + }), + ); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", "https://matrix.to/#/old_room_id_from_predecessor?via=a.example.com&via=b.example.com", @@ -238,25 +247,17 @@ describe("", () => { }); it("Shows a tile linking to an event if there are via servers", () => { - const predecessorEvent = new MatrixEvent({ - type: EventType.RoomPredecessor, - state_key: "", - sender: userId, - room_id: roomId, - content: { - predecessor_room_id: "old_room_id_from_predecessor", - last_known_event_id: "$tombstone", - via_servers: ["a.example.com", "b.example.com"], - }, - event_id: "$create", - }); - const room = new Room(roomId, client, userId); - upsertRoomStateEvents(room, [createEvent, predecessorEvent]); - - renderTile(room); + renderTile( + makeRoom({ + createEventHasPredecessor: true, + predecessorEventExists: true, + predecessorEventHasEventId: true, + predecessorEventHasViaServers: true, + }), + ); expect(screen.getByText("Click here to see older messages.")).toHaveAttribute( "href", - "https://matrix.to/#/old_room_id_from_predecessor/$tombstone?via=a.example.com&via=b.example.com", + "https://matrix.to/#/old_room_id_from_predecessor/$tombstone_event_id_from_predecessor?via=a.example.com&via=b.example.com", ); }); }); diff --git a/test/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap b/test/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap index 5e692de3fd5..2b8670a7524 100644 --- a/test/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap +++ b/test/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap @@ -14,7 +14,7 @@ exports[` Renders as expected 1`] = ` class="mx_EventTileBubble_subtitle" > Click here to see older messages. From 8aa996c70e8a158e9b00481c3d5e236853551c63 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Mon, 3 Apr 2023 17:40:16 +0100 Subject: [PATCH 09/17] Return lost filterConsole to its home --- test/components/views/messages/RoomPredecessorTile-test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/test/components/views/messages/RoomPredecessorTile-test.tsx b/test/components/views/messages/RoomPredecessorTile-test.tsx index a010c1fa4cd..7f4e58435ca 100644 --- a/test/components/views/messages/RoomPredecessorTile-test.tsx +++ b/test/components/views/messages/RoomPredecessorTile-test.tsx @@ -132,7 +132,6 @@ describe("", () => { filterConsole("RoomPredecessorTile unexpectedly used in a room with no predecessor."); it("Shows an empty div if there is no predecessor", () => { - filterConsole; renderTile(makeRoom({})); expect(screen.queryByText("Click here to see older messages.", { exact: false })).toBeNull(); }); From b8cec9849ffcff783356818dd17c2ec9cb19bde5 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Mon, 3 Apr 2023 17:47:45 +0100 Subject: [PATCH 10/17] Comments for IState in AdvancedRoomSettingsTab --- .../views/settings/tabs/room/AdvancedRoomSettingsTab.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx index 8482bbada4d..869c51c9494 100644 --- a/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx @@ -42,9 +42,16 @@ interface IRecommendedVersion { interface IState { // This is eventually set to the value of room.getRecommendedVersion() upgradeRecommendation?: IRecommendedVersion; + + /** The room ID of this room's predecessor, if it exists. */ oldRoomId?: string; + + /** The ID of tombstone event in this room's predecessor, if it exists. */ oldEventId?: string; + + /** The via servers to use to find this room's predecessor, if it exists. */ oldViaServers?: string[]; + upgraded?: boolean; } From 7db8b269607f0fc587503de371906227f2e9354f Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 4 Apr 2023 12:51:03 +0100 Subject: [PATCH 11/17] Explain why we might render a tile even without prevRoom --- src/components/views/messages/RoomPredecessorTile.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index 7edd80d00a8..7c5c9c8d031 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -109,6 +109,9 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => ); } + // Otherwise, we expect to be able to find this room either because it is + // already loaded, or because we have via_servers that we can use. + // So we go ahead with rendering the tile. const predecessorPermalink = prevRoom ? createLinkWithRoom(prevRoom, predecessor.roomId, predecessor.eventId) From eba4adbaf76bd05345cb5e6a2f594b465604b0ab Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 4 Apr 2023 13:25:24 +0100 Subject: [PATCH 12/17] Guess the old room's via servers if they are not provided --- .../views/messages/RoomPredecessorTile.tsx | 45 +++++++++++++++++-- src/i18n/strings/en_EN.json | 3 +- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index 7c5c9c8d031..772e66d5c11 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -93,6 +93,9 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => // Otherwise, we must bail out here if (!prevRoom && !predecessor.viaServers) { logger.warn(`Failed to find predecessor room with id ${predecessor.roomId}`); + + const guessedLink = guessLinkForRoomId(predecessor.roomId); + return ( = ({ mxEvent, timestamp }) => >
- {_t("Can't find the old version of this room (room id: %(roomId)s).", { - roomId: predecessor.roomId, - })} + {!!guessedLink ? ( + <> + {_t( + "Can't find the old version of this room (room ID: %(roomId)s), and we have not been " + + "provided with 'via_servers' to look for it. It's possible that guessing the " + + "server from the room ID will work. If you want to try, click this link:", + { + roomId: predecessor.roomId, + }, + )} + {guessedLink} + + ) : ( + _t( + "Can't find the old version of this room (room ID: %(roomId)s), and we have not been " + + "provided with 'via_servers' to look for it.", + { + roomId: predecessor.roomId, + }, + ) + )}
@@ -150,4 +171,22 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => return matrixToPermalinkConstructor.forRoom(roomId, viaServers); } } + + /** + * Guess the permalink for a room based on its room ID. + * + * The spec says that Room IDs are opaque [1] so this can only ever be a + * guess. There is no guarantee that this room exists on this server. + * + * [1] https://spec.matrix.org/v1.5/appendices/#room-ids-and-event-ids + */ + function guessLinkForRoomId(roomId: string): string | null { + const m = roomId.match(/:(.*)$/); + if (m) { + const serverName = m[1]; + return new MatrixToPermalinkConstructor().forRoom(roomId, [serverName]); + } else { + return null; + } + } }; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 8ae06736aea..1b223c6fd82 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2465,7 +2465,8 @@ "%(senderDisplayName)s removed the room avatar.": "%(senderDisplayName)s removed the room avatar.", "%(senderDisplayName)s changed the room avatar to ": "%(senderDisplayName)s changed the room avatar to ", "This room is a continuation of another conversation.": "This room is a continuation of another conversation.", - "Can't find the old version of this room (room id: %(roomId)s).": "Can't find the old version of this room (room id: %(roomId)s).", + "Can't find the old version of this room (room ID: %(roomId)s), and we have not been provided with 'via_servers' to look for it. It's possible that guessing the server from the room ID will work. If you want to try, click this link:": "Can't find the old version of this room (room ID: %(roomId)s), and we have not been provided with 'via_servers' to look for it. It's possible that guessing the server from the room ID will work. If you want to try, click this link:", + "Can't find the old version of this room (room ID: %(roomId)s), and we have not been provided with 'via_servers' to look for it.": "Can't find the old version of this room (room ID: %(roomId)s), and we have not been provided with 'via_servers' to look for it.", "Click here to see older messages.": "Click here to see older messages.", "Add an Integration": "Add an Integration", "You are about to be taken to a third-party site so you can authenticate your account for use with %(integrationsUrl)s. Do you wish to continue?": "You are about to be taken to a third-party site so you can authenticate your account for use with %(integrationsUrl)s. Do you wish to continue?", From 5a110fdb8140ed98328577fdc226a2b162a4cb22 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 4 Apr 2023 13:34:18 +0100 Subject: [PATCH 13/17] Fix TypeScript errors --- src/utils/permalinks/Permalinks.ts | 24 ++++++++++--------- .../messages/RoomPredecessorTile-test.tsx | 13 ++++------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/utils/permalinks/Permalinks.ts b/src/utils/permalinks/Permalinks.ts index 641d119d96a..365ba570d14 100644 --- a/src/utils/permalinks/Permalinks.ts +++ b/src/utils/permalinks/Permalinks.ts @@ -118,12 +118,12 @@ export class RoomPermalinkCreator { public start(): void { this.load(); - this.room.currentState.on(RoomStateEvent.Update, this.onRoomStateUpdate); + this.room?.currentState.on(RoomStateEvent.Update, this.onRoomStateUpdate); this.started = true; } public stop(): void { - this.room.currentState.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate); + this.room?.currentState.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate); this.started = false; } @@ -171,7 +171,7 @@ export class RoomPermalinkCreator { } private updateHighestPlUser(): void { - const plEvent = this.room.currentState.getStateEvents("m.room.power_levels", ""); + const plEvent = this.room?.currentState.getStateEvents("m.room.power_levels", ""); if (plEvent) { const content = plEvent.getContent(); if (content) { @@ -179,7 +179,7 @@ export class RoomPermalinkCreator { if (users) { const entries = Object.entries(users); const allowedEntries = entries.filter(([userId]) => { - const member = this.room.getMember(userId); + const member = this.room?.getMember(userId); if (!member || member.membership !== "join") { return false; } @@ -213,8 +213,8 @@ export class RoomPermalinkCreator { private updateAllowedServers(): void { const bannedHostsRegexps: RegExp[] = []; let allowedHostsRegexps = [ANY_REGEX]; // default allow everyone - if (this.room.currentState) { - const aclEvent = this.room.currentState.getStateEvents(EventType.RoomServerAcl, ""); + if (this.room?.currentState) { + const aclEvent = this.room?.currentState.getStateEvents(EventType.RoomServerAcl, ""); if (aclEvent && aclEvent.getContent()) { const getRegex = (hostname: string): RegExp => new RegExp("^" + utils.globToRegexp(hostname, false) + "$"); @@ -237,12 +237,14 @@ export class RoomPermalinkCreator { private updatePopulationMap(): void { const populationMap: { [server: string]: number } = {}; - for (const member of this.room.getJoinedMembers()) { - const serverName = getServerName(member.userId); - if (!populationMap[serverName]) { - populationMap[serverName] = 0; + if (this.room) { + for (const member of this.room.getJoinedMembers()) { + const serverName = getServerName(member.userId); + if (!populationMap[serverName]) { + populationMap[serverName] = 0; + } + populationMap[serverName]++; } - populationMap[serverName]++; } this.populationMap = populationMap; } diff --git a/test/components/views/messages/RoomPredecessorTile-test.tsx b/test/components/views/messages/RoomPredecessorTile-test.tsx index 7f4e58435ca..2d7ed23acab 100644 --- a/test/components/views/messages/RoomPredecessorTile-test.tsx +++ b/test/components/views/messages/RoomPredecessorTile-test.tsx @@ -71,19 +71,14 @@ describe("", () => { room_id: roomId, content: { predecessor_room_id: "old_room_id_from_predecessor", - last_known_event_id: undefined, - via_servers: undefined, + last_known_event_id: predecessorEventHasEventId + ? "$tombstone_event_id_from_predecessor" + : undefined, + via_servers: predecessorEventHasViaServers ? ["a.example.com", "b.example.com"] : undefined, }, event_id: "$predecessor", }; - if (predecessorEventHasEventId) { - predecessorInfo.content.last_known_event_id = "$tombstone_event_id_from_predecessor"; - } - if (predecessorEventHasViaServers) { - predecessorInfo.content.via_servers = ["a.example.com", "b.example.com"]; - } - const predecessorEvent = new MatrixEvent(predecessorInfo); upsertRoomStateEvents(room, [predecessorEvent]); } From 1ab7740685fb3a51da61a00d0651451de38c8215 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 5 Apr 2023 14:03:46 +0100 Subject: [PATCH 14/17] Adjust regular expression (hopefully) to avoid potential catastrophic backtracking --- src/components/views/messages/RoomPredecessorTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index 772e66d5c11..776a490485d 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -181,7 +181,7 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => * [1] https://spec.matrix.org/v1.5/appendices/#room-ids-and-event-ids */ function guessLinkForRoomId(roomId: string): string | null { - const m = roomId.match(/:(.*)$/); + const m = roomId.match(/[^:]*:(.*)/); if (m) { const serverName = m[1]; return new MatrixToPermalinkConstructor().forRoom(roomId, [serverName]); From eeb92e69df6b05c0168b48b51cfafd9149c69e71 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 5 Apr 2023 15:13:10 +0100 Subject: [PATCH 15/17] Another attempt at avoiding super-liner regex performance --- src/components/views/messages/RoomPredecessorTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index 776a490485d..bdd270a7450 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -181,7 +181,7 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => * [1] https://spec.matrix.org/v1.5/appendices/#room-ids-and-event-ids */ function guessLinkForRoomId(roomId: string): string | null { - const m = roomId.match(/[^:]*:(.*)/); + const m = roomId.match(/:([^:]*)$/); if (m) { const serverName = m[1]; return new MatrixToPermalinkConstructor().forRoom(roomId, [serverName]); From 2f80b71b3b19ab674d3ecbbbd1d264a79843776c Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 12 Apr 2023 13:55:07 +0100 Subject: [PATCH 16/17] Tests for guessServerNameFromRoomId and better implementation --- .../views/messages/RoomPredecessorTile.tsx | 24 +++++++++++-- .../messages/RoomPredecessorTile-test.tsx | 35 ++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index bdd270a7450..ef1c8a620c1 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -181,12 +181,30 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => * [1] https://spec.matrix.org/v1.5/appendices/#room-ids-and-event-ids */ function guessLinkForRoomId(roomId: string): string | null { - const m = roomId.match(/:([^:]*)$/); - if (m) { - const serverName = m[1]; + const serverName = guessServerNameFromRoomId(roomId); + if (serverName) { return new MatrixToPermalinkConstructor().forRoom(roomId, [serverName]); } else { return null; } } }; + +/** + * @internal Public for test only + * + * Guess the server name for a room based on its room ID. + * + * The spec says that Room IDs are opaque [1] so this can only ever be a + * guess. There is no guarantee that this room exists on this server. + * + * [1] https://spec.matrix.org/v1.5/appendices/#room-ids-and-event-ids + */ +export function guessServerNameFromRoomId(roomId: string): string | null { + const m = roomId.match(/[^:]*:(.*)/); + if (m) { + return m[1]; + } else { + return null; + } +} diff --git a/test/components/views/messages/RoomPredecessorTile-test.tsx b/test/components/views/messages/RoomPredecessorTile-test.tsx index 2d7ed23acab..902eae1599f 100644 --- a/test/components/views/messages/RoomPredecessorTile-test.tsx +++ b/test/components/views/messages/RoomPredecessorTile-test.tsx @@ -22,7 +22,10 @@ import { EventType, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; import dis from "../../../../src/dispatcher/dispatcher"; import SettingsStore from "../../../../src/settings/SettingsStore"; -import { RoomPredecessorTile } from "../../../../src/components/views/messages/RoomPredecessorTile"; +import { + guessServerNameFromRoomId, + RoomPredecessorTile, +} from "../../../../src/components/views/messages/RoomPredecessorTile"; import { stubClient, upsertRoomStateEvents } from "../../../test-utils/test-utils"; import { Action } from "../../../../src/dispatcher/actions"; import RoomContext from "../../../../src/contexts/RoomContext"; @@ -257,3 +260,33 @@ describe("", () => { }); }); }); + +describe("guessServerNameFromRoomId", () => { + it("Extracts the domain name from a standard room ID", () => { + expect(guessServerNameFromRoomId("!436456:example.com")).toEqual("example.com"); + }); + + it("Extracts the domain name and port when included", () => { + expect(guessServerNameFromRoomId("!436456:example.com:8888")).toEqual("example.com:8888"); + }); + + it("Handles an IPv4 address for server name", () => { + expect(guessServerNameFromRoomId("!436456:127.0.0.1")).toEqual("127.0.0.1"); + }); + + it("Handles an IPv4 address and port", () => { + expect(guessServerNameFromRoomId("!436456:127.0.0.1:81")).toEqual("127.0.0.1:81"); + }); + + it("Handles an IPv6 address for server name", () => { + expect(guessServerNameFromRoomId("!436456:::1")).toEqual("::1"); + }); + + it("Handles an IPv6 address and port", () => { + expect(guessServerNameFromRoomId("!436456:::1:8080")).toEqual("::1:8080"); + }); + + it("Returns null when the room ID contains no colon", () => { + expect(guessServerNameFromRoomId("!436456")).toBeNull(); + }); +}); From 7f1ac7a746ea83fe4efc80868a711c12cfa7cbc7 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 12 Apr 2023 15:08:59 +0100 Subject: [PATCH 17/17] Further attempt to prevent backtracking --- src/components/views/messages/RoomPredecessorTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/messages/RoomPredecessorTile.tsx b/src/components/views/messages/RoomPredecessorTile.tsx index ef1c8a620c1..bee0849fa41 100644 --- a/src/components/views/messages/RoomPredecessorTile.tsx +++ b/src/components/views/messages/RoomPredecessorTile.tsx @@ -201,7 +201,7 @@ export const RoomPredecessorTile: React.FC = ({ mxEvent, timestamp }) => * [1] https://spec.matrix.org/v1.5/appendices/#room-ids-and-event-ids */ export function guessServerNameFromRoomId(roomId: string): string | null { - const m = roomId.match(/[^:]*:(.*)/); + const m = roomId.match(/^[^:]*:(.*)/); if (m) { return m[1]; } else {