From f3f40de14a442676648d7b65416e528be2e1e2a2 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 20 Nov 2025 18:27:23 +0100 Subject: [PATCH] change(members): search is now dependent of the selected section --- .../impl/members/RoomMemberListDataSource.kt | 18 +++++++++++++----- .../impl/members/RoomMemberListPresenter.kt | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt index 87ae53c93c..5e00ce0937 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt @@ -13,23 +13,31 @@ import io.element.android.libraries.core.bool.orFalse import io.element.android.libraries.core.coroutine.CoroutineDispatchers import io.element.android.libraries.matrix.api.room.BaseRoom import io.element.android.libraries.matrix.api.room.RoomMember +import io.element.android.libraries.matrix.api.room.RoomMembershipState import io.element.android.libraries.matrix.api.room.roomMembers import kotlinx.coroutines.withContext +import kotlin.collections.filter @Inject class RoomMemberListDataSource( private val room: BaseRoom, private val coroutineDispatchers: CoroutineDispatchers, ) { - suspend fun search(query: String): List = withContext(coroutineDispatchers.io) { + suspend fun search(query: String, selectedSection: SelectedSection): List = withContext(coroutineDispatchers.io) { val roomMembersState = room.membersStateFlow.value - val activeRoomMembers = roomMembersState.roomMembers() - ?.filter { it.membership.isActive() } + val displayableMembers = roomMembersState.roomMembers() .orEmpty() + .filter { + when(selectedSection){ + SelectedSection.MEMBERS -> it.membership.isActive() + SelectedSection.BANNED -> it.membership == RoomMembershipState.BAN + } + } + val filteredMembers = if (query.isBlank()) { - activeRoomMembers + displayableMembers } else { - activeRoomMembers.filter { member -> + displayableMembers.filter { member -> member.userId.value.contains(query, ignoreCase = true) || member.displayName?.contains(query, ignoreCase = true).orFalse() } diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt index 65385e5f08..400432d331 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt @@ -130,7 +130,7 @@ class RoomMemberListPresenter( searchResults = if (searchQuery.isEmpty() || !isSearchActive) { SearchBarResultState.Initial() } else { - val results = roomMemberListDataSource.search(searchQuery).groupBy { it.membership } + val results = roomMemberListDataSource.search(searchQuery, selectedSection).groupBy { it.membership } if (results.isEmpty()) { SearchBarResultState.NoResultsFound() } else {