Check if user is not already selected

This commit is contained in:
Florian Renaud
2023-04-13 23:33:54 +02:00
parent 5979421f48
commit a3bb817d1f
2 changed files with 4 additions and 6 deletions

View File

@@ -26,7 +26,9 @@ class UserListDataStore @Inject constructor() {
private val selectedUsers: MutableStateFlow<List<MatrixUser>> = MutableStateFlow(emptyList())
fun selectUser(user: MatrixUser) {
selectedUsers.tryEmit(selectedUsers.value.plus(user))
if (user !in selectedUsers.value) {
selectedUsers.tryEmit(selectedUsers.value.plus(user))
}
}
fun removeUserFromSelection(user: MatrixUser) {

View File

@@ -72,11 +72,7 @@ class DefaultUserListPresenter @AssistedInject constructor(
when (event) {
is UserListEvents.OnSearchActiveChanged -> isSearchActive = event.active
is UserListEvents.UpdateSearchQuery -> searchQuery = event.query
is UserListEvents.AddToSelection -> {
if (event.matrixUser !in selectedUsers.value) {
userListDataStore.selectUser(event.matrixUser)
}
}
is UserListEvents.AddToSelection -> userListDataStore.selectUser(event.matrixUser)
is UserListEvents.RemoveFromSelection -> userListDataStore.removeUserFromSelection(event.matrixUser)
}
}