Filter existing room members.

This commit is contained in:
onurays 2020-04-30 15:28:20 +03:00
parent 57a87ba620
commit 5dc50195b3
8 changed files with 21 additions and 11 deletions

View File

@ -81,8 +81,8 @@ class RxSession(private val session: Session) {
return session.getIgnoredUsersLive().asObservable()
}
fun livePagedUsers(filter: String? = null): Observable<PagedList<User>> {
return session.getPagedUsersLive(filter).asObservable()
fun livePagedUsers(filter: String? = null, excludedUserIds: Set<String>? = null): Observable<PagedList<User>> {
return session.getPagedUsersLive(filter, excludedUserIds).asObservable()
}
fun createRoom(roomParams: CreateRoomParams): Single<String> = singleBuilder {

View File

@ -63,7 +63,7 @@ interface UserService {
* @param filter the filter. It will look into userId and displayName.
* @return a Livedata of users
*/
fun getPagedUsersLive(filter: String? = null): LiveData<PagedList<User>>
fun getPagedUsersLive(filter: String? = null, excludedUserIds: Set<String>? = null): LiveData<PagedList<User>>
/**
* Get list of ignored users

View File

@ -91,7 +91,7 @@ internal class DefaultUserService @Inject constructor(private val monarchy: Mona
)
}
override fun getPagedUsersLive(filter: String?): LiveData<PagedList<User>> {
override fun getPagedUsersLive(filter: String?, excludedUserIds: Set<String>?): LiveData<PagedList<User>> {
realmDataSourceFactory.updateQuery { realm ->
val query = realm.where(UserEntity::class.java)
if (filter.isNullOrEmpty()) {
@ -104,6 +104,9 @@ internal class DefaultUserService @Inject constructor(private val monarchy: Mona
.contains(UserEntityFields.USER_ID, filter)
.endGroup()
}
excludedUserIds?.let {
query.not().`in`(UserEntityFields.USER_ID, it.toTypedArray())
}
query.sort(UserEntityFields.DISPLAY_NAME)
}
return monarchy.findAllPagedWithChanges(realmDataSourceFactory, livePagedListBuilder)

View File

@ -85,7 +85,8 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
KnownUsersFragment::class.java,
KnownUsersFragmentArgs(
title = getString(R.string.invite_users_to_room_title),
menuResId = R.menu.vector_invite_users_to_room
menuResId = R.menu.vector_invite_users_to_room,
excludedUserIds = viewModel.getUserIdsOfRoomMembers()
)
)
}

View File

@ -67,4 +67,8 @@ class InviteUsersToRoomViewModel @AssistedInject constructor(@Assisted
_viewEvents.post(InviteUsersToRoomViewEvents.Failure(it))
}).disposeOnClear()
}
fun getUserIdsOfRoomMembers(): Set<String> {
return room.roomSummary()?.otherMemberIds?.toSet() ?: emptySet()
}
}

View File

@ -22,5 +22,6 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
data class KnownUsersFragmentArgs(
val title: String,
val menuResId: Int? = null
val menuResId: Int? = null,
val excludedUserIds: Set<String>? = null
) : Parcelable

View File

@ -96,7 +96,7 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
setState { copy(selectedUsers = selectedUsers) }
}
private fun observeDirectoryUsers() {
private fun observeDirectoryUsers() = withState { state ->
directoryUsersSearch
.debounce(300, TimeUnit.MILLISECONDS)
.switchMapSingle { search ->
@ -104,7 +104,7 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
Single.just(emptyList())
} else {
session.rx()
.searchUsersDirectory(search, 50, emptySet())
.searchUsersDirectory(search, 50, state.excludedUserIds ?: emptySet())
.map { users ->
users.sortedBy { it.toMatrixItem().firstLetterOfDisplayName() }
}
@ -117,12 +117,12 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
.disposeOnClear()
}
private fun observeKnownUsers() {
private fun observeKnownUsers() = withState { state ->
knownUsersFilter
.throttleLast(300, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.switchMap {
session.rx().livePagedUsers(it.orNull())
session.rx().livePagedUsers(it.orNull(), state.excludedUserIds)
}
.execute { async ->
copy(

View File

@ -24,6 +24,7 @@ import com.airbnb.mvrx.Uninitialized
import im.vector.matrix.android.api.session.user.model.User
data class UserDirectoryViewState(
val excludedUserIds: Set<String>? = null,
val knownUsers: Async<PagedList<User>> = Uninitialized,
val directoryUsers: Async<List<User>> = Uninitialized,
val selectedUsers: Set<User> = emptySet(),
@ -34,7 +35,7 @@ data class UserDirectoryViewState(
val menuResId: Int?
) : MvRxState {
constructor(args: KnownUsersFragmentArgs) : this(title = args.title, menuResId = args.menuResId)
constructor(args: KnownUsersFragmentArgs) : this(title = args.title, menuResId = args.menuResId, excludedUserIds = args.excludedUserIds)
enum class DisplayMode {
KNOWN_USERS,