Even if it's not happening, do not add the search term if already present in the results.
This commit is contained in:
parent
3163bc8b80
commit
06cf59bca7
|
@ -60,20 +60,24 @@ class DirectoryUsersController @Inject constructor(private val session: Session,
|
||||||
when (val asyncUsers = currentState.directoryUsers) {
|
when (val asyncUsers = currentState.directoryUsers) {
|
||||||
is Uninitialized -> renderEmptyState(false)
|
is Uninitialized -> renderEmptyState(false)
|
||||||
is Loading -> renderLoading()
|
is Loading -> renderLoading()
|
||||||
is Success -> renderSuccess(getAsyncUsers(currentState), currentState.selectedUsers.map { it.userId }, hasSearch)
|
is Success -> renderSuccess(
|
||||||
|
computeUsersList(asyncUsers(), currentState.directorySearchTerm),
|
||||||
|
currentState.selectedUsers.map { it.userId },
|
||||||
|
hasSearch
|
||||||
|
)
|
||||||
is Fail -> renderFailure(asyncUsers.error)
|
is Fail -> renderFailure(asyncUsers.error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAsyncUsers(currentState: CreateDirectRoomViewState): List<User> {
|
/**
|
||||||
return currentState
|
* Eventually add the searched terms, if it is a userId, and if not already present in the result
|
||||||
.directoryUsers()
|
*/
|
||||||
?.toMutableList()
|
private fun computeUsersList(directoryUsers: List<User>, searchTerms: String): List<User> {
|
||||||
?.apply {
|
return directoryUsers +
|
||||||
currentState.directorySearchTerm
|
searchTerms
|
||||||
.takeIf { MatrixPatterns.isUserId(it) }
|
.takeIf { terms -> MatrixPatterns.isUserId(terms) && !directoryUsers.any { it.userId == terms } }
|
||||||
?.let { add(User(it)) }
|
?.let { listOf(User(it)) }
|
||||||
} ?: emptyList()
|
.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderLoading() {
|
private fun renderLoading() {
|
||||||
|
|
Loading…
Reference in New Issue