Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Show an error tile when the predecessor room is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Mar 31, 2023
1 parent c6736e0 commit 0075c0c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
16 changes: 15 additions & 1 deletion src/components/views/messages/RoomPredecessorTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,21 @@ export const RoomPredecessorTile: React.FC<IProps> = ({ mxEvent, timestamp }) =>
const prevRoom = MatrixClientPeg.get().getRoom(predecessor.roomId);
if (!prevRoom) {
logger.warn(`Failed to find predecessor room with id ${predecessor.roomId}`);
return <></>;
return (
<EventTileBubble
className="mx_CreateEvent"
title={_t("This room is a continuation of another conversation.")}
timestamp={timestamp}
>
<div className="mx_EventTile_body">
<span className="mx_EventTile_tileError">
{_t("Can't find the old version of this room (room id: %(roomId)s).", {
roomId: predecessor.roomId,
})}
</span>
</div>
</EventTileBubble>
);
}
const permalinkCreator = new RoomPermalinkCreator(prevRoom, predecessor.roomId);
permalinkCreator.load();
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <img/>": "%(senderDisplayName)s changed the room avatar to <img/>",
"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",
Expand Down
26 changes: 22 additions & 4 deletions test/components/views/messages/RoomPredecessorTile-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -118,9 +118,14 @@ describe("<RoomPredecessorTile />", () => {
);
});

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 () => {
Expand Down Expand Up @@ -149,6 +154,19 @@ describe("<RoomPredecessorTile />", () => {
);
});

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(
Expand Down

0 comments on commit 0075c0c

Please sign in to comment.