Use room name as room intro (#9231)

* Use roon name for room intro

* Fix types

* Revert caption var change

* Fix type issue
This commit is contained in:
Michael Weimann 2022-09-06 09:54:53 +02:00 committed by GitHub
parent 4524291331
commit 9f7165ed63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3558 additions and 8 deletions

View File

@ -55,10 +55,10 @@ const NewRoomIntro = () => {
? room.targets[0]?.userId ? room.targets[0]?.userId
: DMRoomMap.shared().getUserIdForRoomId(roomId); : DMRoomMap.shared().getUserIdForRoomId(roomId);
let body; let body: JSX.Element;
if (dmPartner) { if (dmPartner) {
let introMessage = _t("This is the beginning of your direct message history with <displayName/>."); let introMessage = _t("This is the beginning of your direct message history with <displayName/>.");
let caption; let caption: string | undefined;
if (isLocalRoom) { if (isLocalRoom) {
introMessage = _t("Send your first message to invite <displayName/> to chat"); introMessage = _t("Send your first message to invite <displayName/> to chat");
@ -67,7 +67,7 @@ const NewRoomIntro = () => {
} }
const member = room?.getMember(dmPartner); const member = room?.getMember(dmPartner);
const displayName = member?.rawDisplayName || dmPartner; const displayName = room?.name || member?.rawDisplayName || dmPartner;
body = <React.Fragment> body = <React.Fragment>
<RoomAvatar <RoomAvatar
room={room} room={room}

View File

@ -53,12 +53,14 @@ describe("NewRoomIntro", () => {
describe("for a DM Room", () => { describe("for a DM Room", () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId); 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", () => { it("should render the expected intro", () => {
const expected = `This is the beginning of your direct message history with ${userId}.`; const expected = `This is the beginning of your direct message history with test_room.`;
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected); screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
}); });
}); });
@ -66,13 +68,14 @@ describe("NewRoomIntro", () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId); jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(userId);
const localRoom = new LocalRoom(roomId, client, client.getUserId()); const localRoom = new LocalRoom(roomId, client, client.getUserId());
localRoom.name = "test_room";
localRoom.targets.push(new DirectoryMember({ user_id: userId })); localRoom.targets.push(new DirectoryMember({ user_id: userId }));
renderNewRoomIntro(client, localRoom); renderNewRoomIntro(client, localRoom);
}); });
it("should render the expected intro", () => { it("should render the expected intro", () => {
const expected = `Send your first message to invite ${userId} to chat`; const expected = `Send your first message to invite test_room to chat`;
screen.getByText((id, element) => element.tagName === "SPAN" && element.textContent === expected); screen.getByText((id, element) => element?.tagName === "SPAN" && element?.textContent === expected);
}); });
}); });
}); });

3547
tsc.txt Normal file

File diff suppressed because it is too large Load Diff