add RoomMember.name which falls back to userId

this will prevent the crash when left members
have their displayname removed (another issue)
This commit is contained in:
Bruno Windels 2020-08-27 09:51:00 +02:00
parent 5f6074eef3
commit bd9cb5aae5
2 changed files with 17 additions and 4 deletions

View File

@ -22,12 +22,12 @@ function calculateRoomName(sortedMembers, summary) {
if (sortedMembers.length > 1) {
const lastMember = sortedMembers[sortedMembers.length - 1];
const firstMembers = sortedMembers.slice(0, sortedMembers.length - 1);
return firstMembers.map(m => m.displayName).join(", ") + " and " + lastMember.displayName;
return firstMembers.map(m => m.name).join(", ") + " and " + lastMember.name;
} else {
return sortedMembers[0].displayName;
return sortedMembers[0].name;
}
} else if (sortedMembers.length < countWithoutMe) {
return sortedMembers.map(m => m.displayName).join(", ") + ` and ${countWithoutMe} others`;
return sortedMembers.map(m => m.name).join(", ") + ` and ${countWithoutMe} others`;
} else {
// Empty Room
return null;
@ -81,7 +81,7 @@ export class Heroes {
for (const member of updatedHeroMembers) {
this._members.set(member.userId, member);
}
const sortedMembers = Array.from(this._members.values()).sort((a, b) => a.displayName.localeCompare(b.displayName));
const sortedMembers = Array.from(this._members.values()).sort((a, b) => a.name.localeCompare(b.name));
this._roomName = calculateRoomName(sortedMembers, summary);
}

View File

@ -54,10 +54,23 @@ export class RoomMember {
});
}
/**
* @return {String?} the display name, if any
*/
get displayName() {
return this._data.displayName;
}
/**
* @return {String} the display name or userId
*/
get name() {
return this._data.displayName || this._data.userId;
}
/**
* @return {String?} the avatar mxc url, if any
*/
get avatarUrl() {
return this._data.avatarUrl;
}