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:
Tigermouthbear 2021-08-13 23:23:19 -04:00
parent 37e722e85d
commit 65076a4aec
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) val members = room.getRoomMembers(queryParams)
.asSequence() .asSequence()
.sortedBy { it.displayName } .sortedBy { it.displayName }
.disambiguate()
controller.setData(members.toList()) 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
}
}