Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions spec/unit/models/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,27 @@ describe("Room", () => {
expect(room.getAltAliases()).toEqual(["#foo:bar"]);
});
});

describe("calculateRoomName()", () => {
it("should ignore empty m.room.name 'name' field", async () => {
const mockClient = createMockClient();
const room = new Room("!room:example.org", mockClient, CREATOR_USER_ID);
const event = new MatrixEvent({
type: EventType.RoomName,
content: {
name: "",
},
state_key: "",
event_id: "$123",
room_id: room.roomId,
sender: CREATOR_USER_ID,
});

// Set up the room
room.currentState.setStateEvents([event]);
room.recalculate();

expect(room.name).not.toEqual("");
});
});
});
6 changes: 3 additions & 3 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
*/
public getMxcAvatarUrl(): string | null {
const url = this.currentState.getStateEvents(EventType.RoomAvatar, "")?.getContent().url;
return typeof url === "string" ? url : null;
return url && typeof url === "string" ? url : null;
}

/**
Expand All @@ -1821,7 +1821,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
*/
public getCanonicalAlias(): string | null {
const canonicalAlias = this.currentState.getStateEvents(EventType.RoomCanonicalAlias, "")?.getContent().alias;
return typeof canonicalAlias === "string" ? canonicalAlias : null;
return canonicalAlias && typeof canonicalAlias === "string" ? canonicalAlias : null;
}

/**
Expand Down Expand Up @@ -3638,7 +3638,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
private calculateRoomName(userId: string, ignoreRoomNameEvent = false): string {
if (!ignoreRoomNameEvent) {
const name = this.currentState.getStateEvents(EventType.RoomName, "")?.getContent().name;
if (typeof name === "string") {
if (name && typeof name === "string") {
return this.roomNameGenerator({
type: RoomNameType.Actual,
name,
Expand Down