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 { class RoomMemberDisplayNameResolver {
fun resolve(userId: String, members: Map<String, RoomMember>): String? { fun resolve(userId: String, members: Map<String, RoomMember>): String? {
var displayName: String? = null
val currentMember = members[userId] val currentMember = members[userId]
var displayName = currentMember?.displayName
// Get the user display name from the member list of the room // Get the user display name from the member list of the room
// Do not consider null display name // Do not consider null display name
if (currentMember != null && !currentMember.displayName.isNullOrEmpty()) { if (currentMember != null && !currentMember.displayName.isNullOrEmpty()) {
val hasNameCollision = members val hasNameCollision = members
.filterValues { it != currentMember && it.displayName == currentMember.displayName } .filterValues { it != currentMember && it.displayName == currentMember.displayName }
.isNotEmpty() .isNotEmpty()
displayName = if (hasNameCollision) { if (hasNameCollision) {
"${currentMember.displayName} ( $userId )" displayName = "${currentMember.displayName} ( $userId )"
} else {
currentMember.displayName
} }
} }
// TODO handle invited users // TODO handle invited users
/*else if (null != member && TextUtils.equals(member!!.membership, RoomMember.MEMBERSHIP_INVITE)) { /*else if (null != member && TextUtils.equals(member!!.membership, RoomMember.MEMBERSHIP_INVITE)) {
val user = (mDataHandler as MXDataHandler).getUser(userId) val user = (mDataHandler as MXDataHandler).getUser(userId)