mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
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:
parent
5f6074eef3
commit
bd9cb5aae5
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user