Fix: dont show 1:1 avatar for room with only 2 members loaded
This commit is contained in:
parent
8313dcd0dd
commit
36665d3c69
1 changed files with 14 additions and 48 deletions
|
@ -19,6 +19,7 @@ import {ContentRepo} from "matrix-js-sdk";
|
||||||
import MatrixClientPeg from "../../../MatrixClientPeg";
|
import MatrixClientPeg from "../../../MatrixClientPeg";
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import sdk from "../../../index";
|
import sdk from "../../../index";
|
||||||
|
import DMRoomMap from '../../../utils/DMRoomMap';
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'RoomAvatar',
|
displayName: 'RoomAvatar',
|
||||||
|
@ -109,56 +110,21 @@ module.exports = React.createClass({
|
||||||
getOneToOneAvatar: function(props) {
|
getOneToOneAvatar: function(props) {
|
||||||
if (!props.room) return null;
|
if (!props.room) return null;
|
||||||
|
|
||||||
const mlist = props.room.currentState.members;
|
const otherUserId = DMRoomMap.shared().getUserIdForRoomId(props.room.roomId);
|
||||||
const userIds = [];
|
if (!otherUserId) {
|
||||||
const leftUserIds = [];
|
|
||||||
// for .. in optimisation to return early if there are >2 keys
|
|
||||||
for (const uid in mlist) {
|
|
||||||
if (mlist.hasOwnProperty(uid)) {
|
|
||||||
if (["join", "invite"].includes(mlist[uid].membership)) {
|
|
||||||
userIds.push(uid);
|
|
||||||
} else {
|
|
||||||
leftUserIds.push(uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (userIds.length > 2) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const otherMember = props.room.getMember(otherUserId);
|
||||||
|
if (!otherMember) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
return otherMember.getAvatarUrl(
|
||||||
if (userIds.length == 2) {
|
|
||||||
let theOtherGuy = null;
|
|
||||||
if (mlist[userIds[0]].userId == MatrixClientPeg.get().credentials.userId) {
|
|
||||||
theOtherGuy = mlist[userIds[1]];
|
|
||||||
} else {
|
|
||||||
theOtherGuy = mlist[userIds[0]];
|
|
||||||
}
|
|
||||||
return theOtherGuy.getAvatarUrl(
|
|
||||||
MatrixClientPeg.get().getHomeserverUrl(),
|
MatrixClientPeg.get().getHomeserverUrl(),
|
||||||
Math.floor(props.width * window.devicePixelRatio),
|
Math.floor(props.width * window.devicePixelRatio),
|
||||||
Math.floor(props.height * window.devicePixelRatio),
|
Math.floor(props.height * window.devicePixelRatio),
|
||||||
props.resizeMethod,
|
props.resizeMethod,
|
||||||
false,
|
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(),
|
|
||||||
Math.floor(props.width * window.devicePixelRatio),
|
|
||||||
Math.floor(props.height * window.devicePixelRatio),
|
|
||||||
props.resizeMethod,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onRoomAvatarClick: function() {
|
onRoomAvatarClick: function() {
|
||||||
|
|
Loading…
Reference in a new issue