From 10017522e2556d85018b3a9ebaa165dd39916c0b Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 19 Dec 2016 17:59:13 +0000 Subject: [PATCH 1/4] Use correct 1-1 room avatar after users leave The correct 1-1 avatar is used with rooms in which there are only two users with either "join" or "invite" as their membership (importantly, not "leave" or otherwise). (This is important when a user moves accounts and re-joins previously left 1-1 chats) --- src/components/views/avatars/RoomAvatar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/avatars/RoomAvatar.js b/src/components/views/avatars/RoomAvatar.js index dcb25eff61..2bb6caddb7 100644 --- a/src/components/views/avatars/RoomAvatar.js +++ b/src/components/views/avatars/RoomAvatar.js @@ -86,7 +86,7 @@ module.exports = React.createClass({ var userIds = []; // for .. in optimisation to return early if there are >2 keys for (var uid in mlist) { - if (mlist.hasOwnProperty(uid)) { + if (mlist.hasOwnProperty(uid) && ["join", "invite"].includes(mlist[uid].membership)) { userIds.push(uid); } if (userIds.length > 2) { From 583f86eb06d7df4b49378ce7e2101311223b1104 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 19 Dec 2016 18:41:34 +0000 Subject: [PATCH 2/4] Handle the case where the other 1-1 user left --- src/components/views/avatars/RoomAvatar.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/views/avatars/RoomAvatar.js b/src/components/views/avatars/RoomAvatar.js index 2bb6caddb7..09a9e6c6c0 100644 --- a/src/components/views/avatars/RoomAvatar.js +++ b/src/components/views/avatars/RoomAvatar.js @@ -84,10 +84,15 @@ module.exports = React.createClass({ var mlist = props.room.currentState.members; var userIds = []; + var leftUserIds = []; // for .. in optimisation to return early if there are >2 keys for (var uid in mlist) { - if (mlist.hasOwnProperty(uid) && ["join", "invite"].includes(mlist[uid].membership)) { - userIds.push(uid); + if (mlist.hasOwnProperty(uid)) { + if (["join", "invite"].includes(mlist[uid].membership)) { + userIds.push(uid); + } else { + leftUserIds.push(uid); + } } if (userIds.length > 2) { return null; @@ -101,12 +106,21 @@ module.exports = React.createClass({ } else { theOtherGuy = mlist[userIds[0]]; } + return theOtherGuy.getAvatarUrl( MatrixClientPeg.get().getHomeserverUrl(), props.width, props.height, props.resizeMethod, false ); } else if (userIds.length == 1) { + // The other 1-1 user left, leaving just the current user, so show the left user's avatar + if (leftUserIds.length === 1) { + return mlist[leftUserIds[0]].getAvatarUrl( + MatrixClientPeg.get().getHomeserverUrl(), + props.width, props.height, props.resizeMethod, + false + ); + } return mlist[userIds[0]].getAvatarUrl( MatrixClientPeg.get().getHomeserverUrl(), props.width, props.height, props.resizeMethod, From 714b63519a8ebac1c58404236cd811f59259a905 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 20 Dec 2016 11:50:35 +0000 Subject: [PATCH 3/4] Remove empty line --- src/components/views/avatars/RoomAvatar.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/views/avatars/RoomAvatar.js b/src/components/views/avatars/RoomAvatar.js index 09a9e6c6c0..f5f42318eb 100644 --- a/src/components/views/avatars/RoomAvatar.js +++ b/src/components/views/avatars/RoomAvatar.js @@ -106,7 +106,6 @@ module.exports = React.createClass({ } else { theOtherGuy = mlist[userIds[0]]; } - return theOtherGuy.getAvatarUrl( MatrixClientPeg.get().getHomeserverUrl(), props.width, props.height, props.resizeMethod, From 2549b44768a525e0ca46778573fcd99132b864a7 Mon Sep 17 00:00:00 2001 From: lukebarnard Date: Wed, 7 Feb 2018 18:57:32 +0000 Subject: [PATCH 4/4] Linting --- src/components/views/avatars/RoomAvatar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/avatars/RoomAvatar.js b/src/components/views/avatars/RoomAvatar.js index 37e7abe05e..e71a3c929b 100644 --- a/src/components/views/avatars/RoomAvatar.js +++ b/src/components/views/avatars/RoomAvatar.js @@ -122,7 +122,7 @@ module.exports = React.createClass({ return mlist[leftUserIds[0]].getAvatarUrl( MatrixClientPeg.get().getHomeserverUrl(), props.width, props.height, props.resizeMethod, - false + false, ); } return mlist[userIds[0]].getAvatarUrl(