From e7996915731ea47b565d42f35729948bd920265e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 21 Feb 2020 14:14:24 +0000 Subject: [PATCH] Apply null-guard to room pills for when we can't fetch the room Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/Avatar.js | 2 ++ src/editor/parts.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Avatar.js b/src/Avatar.js index 5a330c31e9..217b196348 100644 --- a/src/Avatar.js +++ b/src/Avatar.js @@ -102,6 +102,8 @@ export function getInitialLetter(name) { } export function avatarUrlForRoom(room, width, height, resizeMethod) { + if (!room) return null; // null-guard + const explicitRoomAvatar = room.getAvatarUrl( MatrixClientPeg.get().getHomeserverUrl(), width, diff --git a/src/editor/parts.js b/src/editor/parts.js index 652342405f..8bb4f8633e 100644 --- a/src/editor/parts.js +++ b/src/editor/parts.js @@ -254,8 +254,8 @@ class RoomPillPart extends PillPart { let initialLetter = ""; let avatarUrl = Avatar.avatarUrlForRoom(this._room, 16 * window.devicePixelRatio, 16 * window.devicePixelRatio); if (!avatarUrl) { - initialLetter = Avatar.getInitialLetter(this._room.name); - avatarUrl = `../../${Avatar.defaultAvatarUrlForString(this._room.roomId)}`; + initialLetter = Avatar.getInitialLetter(this._room ? this._room.name : this.resourceId); + avatarUrl = `../../${Avatar.defaultAvatarUrlForString(this._room ? this._room.roomId : this.resourceId)}`; } this._setAvatarVars(node, avatarUrl, initialLetter); }