Fix case where heroes is empty (fallback to display name of loaded members)

This commit is contained in:
ganfra 2018-10-23 18:31:33 +02:00
parent f747d268c9
commit 88362edece
1 changed files with 5 additions and 5 deletions

View File

@ -5,20 +5,20 @@ import im.vector.matrix.android.api.session.room.model.RoomMember
class RoomMemberDisplayNameResolver {
fun resolve(userId: String, members: Map<String, RoomMember>): String? {
var displayName: String? = null
val currentMember = members[userId]
var displayName = currentMember?.displayName
// Get the user display name from the member list of the room
// Do not consider null display name
if (currentMember != null && !currentMember.displayName.isNullOrEmpty()) {
val hasNameCollision = members
.filterValues { it != currentMember && it.displayName == currentMember.displayName }
.isNotEmpty()
displayName = if (hasNameCollision) {
"${currentMember.displayName} ( $userId )"
} else {
currentMember.displayName
if (hasNameCollision) {
displayName = "${currentMember.displayName} ( $userId )"
}
}
// TODO handle invited users
/*else if (null != member && TextUtils.equals(member!!.membership, RoomMember.MEMBERSHIP_INVITE)) {
val user = (mDataHandler as MXDataHandler).getUser(userId)