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

Commit 9f7165e

Browse files
authored
Use room name as room intro (#9231)
* Use roon name for room intro * Fix types * Revert caption var change * Fix type issue
1 parent 4524291 commit 9f7165e

File tree

3 files changed

+3558
-8
lines changed

3 files changed

+3558
-8
lines changed

src/components/views/rooms/NewRoomIntro.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ const NewRoomIntro = () => {
5555
? room.targets[0]?.userId
5656
: DMRoomMap.shared().getUserIdForRoomId(roomId);
5757

58-
let body;
58+
let body: JSX.Element;
5959
if (dmPartner) {
6060
let introMessage = _t("This is the beginning of your direct message history with <displayName/>.");
61-
let caption;
61+
let caption: string | undefined;
6262

6363
if (isLocalRoom) {
6464
introMessage = _t("Send your first message to invite <displayName/> to chat");
@@ -67,7 +67,7 @@ const NewRoomIntro = () => {
6767
}
6868

6969
const member = room?.getMember(dmPartner);
70-
const displayName = member?.rawDisplayName || dmPartner;
70+
const displayName = room?.name || member?.rawDisplayName || dmPartner;
7171
body = <React.Fragment>
7272
<RoomAvatar
7373
room={room}

test/components/views/rooms/NewRoomIntro-test.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,29 @@ describe("NewRoomIntro", () => {
5353
describe("for a DM Room", () => {
5454
beforeEach(() => {
5555
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
56-
renderNewRoomIntro(client, new Room(roomId, client, client.getUserId()));
56+
const room = new Room(roomId, client, client.getUserId());
57+
room.name = "test_room";
58+
renderNewRoomIntro(client, room);
5759
});
5860

5961
it("should render the expected intro", () => {
60-
const expected = `This is the beginning of your direct message history with ${userId}.`;
61-
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected);
62+
const expected = `This is the beginning of your direct message history with test_room.`;
63+
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
6264
});
6365
});
6466

6567
describe("for a DM LocalRoom", () => {
6668
beforeEach(() => {
6769
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
6870
const localRoom = new LocalRoom(roomId, client, client.getUserId());
71+
localRoom.name = "test_room";
6972
localRoom.targets.push(new DirectoryMember({ user_id: userId }));
7073
renderNewRoomIntro(client, localRoom);
7174
});
7275

7376
it("should render the expected intro", () => {
74-
const expected = `Send your first message to invite ${userId} to chat`;
75-
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected);
77+
const expected = `Send your first message to invite test_room to chat`;
78+
screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
7679
});
7780
});
7881
});

0 commit comments

Comments
 (0)