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

Use room name as room intro #9231

Merged
merged 8 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/components/views/rooms/NewRoomIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ const NewRoomIntro = () => {
? room.targets[0]?.userId
: DMRoomMap.shared().getUserIdForRoomId(roomId);

let body;
let body: JSX.Element;
if (dmPartner) {
let introMessage = _t("This is the beginning of your direct message history with <displayName/>.");
let caption;
let captionElement: JSX.Element = <></>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't ever initialise to empty fragments, shouldn't we stay self-consistent, e.g. with L58 for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is valid for rendering, but you should be consistent with both vars either way


if (isLocalRoom) {
introMessage = _t("Send your first message to invite <displayName/> to chat");
} else if ((room.getJoinedMemberCount() + room.getInvitedMemberCount()) === 2) {
caption = _t("Only the two of you are in this conversation, unless either of you invites anyone to join.");
captionElement = <p>
{ _t("Only the two of you are in this conversation, unless either of you invites anyone to join.") }
</p>;
}

const member = room?.getMember(dmPartner);
const displayName = member?.rawDisplayName || dmPartner;
const displayName = room?.name || member?.rawDisplayName || dmPartner;
body = <React.Fragment>
<RoomAvatar
room={room}
Expand All @@ -87,7 +89,7 @@ const NewRoomIntro = () => {
<p>{ _t(introMessage, {}, {
displayName: () => <b>{ displayName }</b>,
}) }</p>
{ caption && <p>{ caption }</p> }
{ captionElement }
</React.Fragment>;
} else {
const inRoom = room && room.getMyMembership() === "join";
Expand Down
13 changes: 8 additions & 5 deletions test/components/views/rooms/NewRoomIntro-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,29 @@ describe("NewRoomIntro", () => {
describe("for a DM Room", () => {
beforeEach(() => {
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
renderNewRoomIntro(client, new Room(roomId, client, client.getUserId()));
const room = new Room(roomId, client, client.getUserId());
room.name = "test_room";
renderNewRoomIntro(client, room);
});

it("should render the expected intro", () => {
const expected = `This is the beginning of your direct message history with ${userId}.`;
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected);
const expected = `This is the beginning of your direct message history with test_room.`;
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
});
});

describe("for a DM LocalRoom", () => {
beforeEach(() => {
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
const localRoom = new LocalRoom(roomId, client, client.getUserId());
localRoom.name = "test_room";
localRoom.targets.push(new DirectoryMember({ user_id: userId }));
renderNewRoomIntro(client, localRoom);
});

it("should render the expected intro", () => {
const expected = `Send your first message to invite ${userId} to chat`;
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected);
const expected = `Send your first message to invite test_room to chat`;
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
});
});
});