Fix soft crash around unknown room pills (#9301)

* Fix soft crash around unknown room pills

* Add tests

* Fix types
This commit is contained in:
Michael Telatynski 2022-09-20 18:00:31 +01:00 committed by GitHub
parent 7e435eef13
commit fa2ec7f6c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -411,7 +411,7 @@ export class EmojiPart extends BasePart implements IBasePart {
}
class RoomPillPart extends PillPart {
constructor(resourceId: string, label: string, private room: Room) {
constructor(resourceId: string, label: string, private room?: Room) {
super(resourceId, label);
}
@ -419,8 +419,8 @@ class RoomPillPart extends PillPart {
let initialLetter = "";
let avatarUrl = Avatar.avatarUrlForRoom(this.room, 16, 16, "crop");
if (!avatarUrl) {
initialLetter = Avatar.getInitialLetter(this.room ? this.room.name : this.resourceId);
avatarUrl = Avatar.defaultAvatarUrlForString(this.room ? this.room.roomId : this.resourceId);
initialLetter = Avatar.getInitialLetter(this.room?.name || this.resourceId);
avatarUrl = Avatar.defaultAvatarUrlForString(this.room?.roomId ?? this.resourceId);
}
this.setAvatarVars(node, avatarUrl, initialLetter);
}
@ -430,7 +430,7 @@ class RoomPillPart extends PillPart {
}
protected get className() {
return "mx_Pill " + (this.room.isSpaceRoom() ? "mx_SpacePill" : "mx_RoomPill");
return "mx_Pill " + (this.room?.isSpaceRoom() ? "mx_SpacePill" : "mx_RoomPill");
}
}
@ -610,7 +610,7 @@ export class PartCreator {
}
public roomPill(alias: string, roomId?: string): RoomPillPart {
let room;
let room: Room | undefined;
if (roomId || alias[0] !== "#") {
room = this.client.getRoom(roomId || alias);
} else {