Merge pull request #3834 from Tigermouthbear/develop

Add mxid to autocomplete suggestion if multiple users have same displayname
This commit is contained in:
Benoit Marty 2021-08-26 10:48:38 +02:00 committed by GitHub
commit 6fd66752bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

1
changelog.d/1823.bugfix Normal file
View File

@ -0,0 +1 @@
- Add mxid to autocomplete suggestion if more than one user in a room has the same displayname

View File

@ -71,6 +71,23 @@ class AutocompleteMemberPresenter @AssistedInject constructor(context: Context,
val members = room.getRoomMembers(queryParams)
.asSequence()
.sortedBy { it.displayName }
.disambiguate()
controller.setData(members.toList())
}
}
private fun Sequence<RoomMemberSummary>.disambiguate(): Sequence<RoomMemberSummary> {
val displayNames = hashMapOf<String, Int>().also { map ->
for (item in this) {
item.displayName?.lowercase()?.also { displayName ->
map[displayName] = map.getOrPut(displayName, { 0 }) + 1
}
}
}
return map { roomMemberSummary ->
if (displayNames[roomMemberSummary.displayName?.lowercase()] ?: 0 > 1) {
roomMemberSummary.copy(displayName = roomMemberSummary.displayName + " " + roomMemberSummary.userId)
} else roomMemberSummary
}
}