diff --git a/changelog.d/1823.bugfix b/changelog.d/1823.bugfix new file mode 100644 index 0000000000..8252e1826f --- /dev/null +++ b/changelog.d/1823.bugfix @@ -0,0 +1 @@ +- Add mxid to autocomplete suggestion if more than one user in a room has the same displayname diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt b/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt index ecc607f08d..aa0c10e0a2 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberPresenter.kt @@ -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.disambiguate(): Sequence { + val displayNames = hashMapOf().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 + } +}