mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Merge pull request #3834 from Tigermouthbear/develop
Add mxid to autocomplete suggestion if multiple users have same displayname
This commit is contained in:
commit
6fd66752bc
1
changelog.d/1823.bugfix
Normal file
1
changelog.d/1823.bugfix
Normal file
@ -0,0 +1 @@
|
||||
- Add mxid to autocomplete suggestion if more than one user in a room has the same displayname
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user