Skip to content

Commit

Permalink
Merge pull request #710 from matrix-org/bwindels/avatarfixbis
Browse files Browse the repository at this point in the history
Fix for "otherMember.getAvatarUrl is not a function"
  • Loading branch information
dbkr authored Aug 31, 2018
2 parents 938772b + 414b153 commit e8e8073
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/models/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const EventEmitter = require("events").EventEmitter;

const EventStatus = require("./event").EventStatus;
const RoomSummary = require("./room-summary");
const RoomMember = require("./room-member");
const MatrixEvent = require("./event").MatrixEvent;
const utils = require("../utils");
const ContentRepo = require("../content-repo");
Expand Down Expand Up @@ -328,17 +329,41 @@ Room.prototype.guessDMUserId = function() {

Room.prototype.getAvatarFallbackMember = function() {
const memberCount = this.getInvitedAndJoinedMemberCount();
if (memberCount <= 2) {
if (this._summaryHeroes && this._summaryHeroes.length) {
return this._summaryHeroes[0];
if (memberCount > 2) {
return;
}
const hasHeroes = Array.isArray(this._summaryHeroes) &&
this._summaryHeroes.length;
if (hasHeroes) {
const availableMember = this._summaryHeroes.map((userId) => {
return this.getMember(userId);
}).find((member) => !!member);
if (availableMember) {
return availableMember;
}
const members = this.currentState.getMembers();
// could be different than memberCount
// as this includes left members
if (members.length <= 2) {
return members.find((m) => {
return m.userId !== this.myUserId;
});
}
const members = this.currentState.getMembers();
// could be different than memberCount
// as this includes left members
if (members.length <= 2) {
const availableMember = members.find((m) => {
return m.userId !== this.myUserId;
});
if (availableMember) {
return availableMember;
}
}
// if all else fails, try falling back to a user,
// and create a one-off member for it
if (hasHeroes) {
const availableUser = this._summaryHeroes.map((userId) => {
return this._client.getUser(userId);
}).find((user) => !!user);
if (availableUser) {
const member = new RoomMember(
this.roomId, availableUser.userId);
member.user = availableUser;
return member;
}
}
};
Expand Down

0 comments on commit e8e8073

Please sign in to comment.