Re-add truthy check on room name/avatar/alias events (#5081)
* Re-add truthy check on room name/avatar/alias events Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add regression test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0bf2702149
commit
90da67aa95
@@ -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("");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user