mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +03:00
Add mxid to autocomplete suggestion if more than one user in a room has the same displayname, closes #1823
improve performance of duplicate displayname finding fix code formatting move member autocomplete disambiguation to AutocompleteMemberPresenter and preserve original order Add mxid to autocomplete suggestion if more than one user in a room has the same displayname, closes #1823
This commit is contained in:
parent
37e722e85d
commit
65076a4aec
2 changed files with 18 additions and 0 deletions
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 a new issue