From 77b479d50c11d948cf767545541c38b475f14dbc Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 13 Jan 2020 12:29:03 +0000 Subject: [PATCH] Guard against missing members in avatars Part of https://github.com/vector-im/riot-web/issues/11744 --- src/Avatar.js | 19 +++++++++++-------- src/components/views/avatars/MemberAvatar.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Avatar.js b/src/Avatar.js index 17860698cb..a529ca5588 100644 --- a/src/Avatar.js +++ b/src/Avatar.js @@ -21,14 +21,17 @@ import DMRoomMap from './utils/DMRoomMap'; module.exports = { avatarUrlForMember: function(member, width, height, resizeMethod) { - let url = member.getAvatarUrl( - MatrixClientPeg.get().getHomeserverUrl(), - Math.floor(width * window.devicePixelRatio), - Math.floor(height * window.devicePixelRatio), - resizeMethod, - false, - false, - ); + let url; + if (member && member.getAvatarUrl) { + url = member.getAvatarUrl( + MatrixClientPeg.get().getHomeserverUrl(), + Math.floor(width * window.devicePixelRatio), + Math.floor(height * window.devicePixelRatio), + resizeMethod, + false, + false, + ); + } if (!url) { // member can be null here currently since on invites, the JS SDK // does not have enough info to build a RoomMember object for diff --git a/src/components/views/avatars/MemberAvatar.js b/src/components/views/avatars/MemberAvatar.js index 383bab5e79..8b6d41eb9f 100644 --- a/src/components/views/avatars/MemberAvatar.js +++ b/src/components/views/avatars/MemberAvatar.js @@ -55,7 +55,7 @@ module.exports = createReactClass({ }, _getState: function(props) { - if (props.member) { + if (props.member && props.member.name) { return { name: props.member.name, title: props.title || props.member.userId,