forked from mystiq/hydrogen-web
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
2 changed files with 17 additions and 4 deletions
|
@ -22,12 +22,12 @@ function calculateRoomName(sortedMembers, summary) {
|
||||||
if (sortedMembers.length > 1) {
|
if (sortedMembers.length > 1) {
|
||||||
const lastMember = sortedMembers[sortedMembers.length - 1];
|
const lastMember = sortedMembers[sortedMembers.length - 1];
|
||||||
const firstMembers = sortedMembers.slice(0, 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 {
|
} else {
|
||||||
return sortedMembers[0].displayName;
|
return sortedMembers[0].name;
|
||||||
}
|
}
|
||||||
} else if (sortedMembers.length < countWithoutMe) {
|
} 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 {
|
} else {
|
||||||
// Empty Room
|
// Empty Room
|
||||||
return null;
|
return null;
|
||||||
|
@ -81,7 +81,7 @@ export class Heroes {
|
||||||
for (const member of updatedHeroMembers) {
|
for (const member of updatedHeroMembers) {
|
||||||
this._members.set(member.userId, member);
|
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);
|
this._roomName = calculateRoomName(sortedMembers, summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,23 @@ export class RoomMember {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {String?} the display name, if any
|
||||||
|
*/
|
||||||
get displayName() {
|
get displayName() {
|
||||||
return this._data.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() {
|
get avatarUrl() {
|
||||||
return this._data.avatarUrl;
|
return this._data.avatarUrl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue