Exclude current user from autocompletion with room members

This commit is contained in:
Benoit Marty 2020-01-10 16:28:14 +01:00
parent de84bb7535
commit 32d2daee3c
3 changed files with 22 additions and 9 deletions

View file

@ -28,17 +28,20 @@ fun roomMemberQueryParams(init: (RoomMemberQueryParams.Builder.() -> Unit) = {})
*/ */
data class RoomMemberQueryParams( data class RoomMemberQueryParams(
val displayName: QueryStringValue, val displayName: QueryStringValue,
val memberships: List<Membership> val memberships: List<Membership>,
val excludeSelf: Boolean
) { ) {
class Builder { class Builder {
var displayName: QueryStringValue = QueryStringValue.IsNotEmpty var displayName: QueryStringValue = QueryStringValue.IsNotEmpty
var memberships: List<Membership> = Membership.all() var memberships: List<Membership> = Membership.all()
var excludeSelf: Boolean = false
fun build() = RoomMemberQueryParams( fun build() = RoomMemberQueryParams(
displayName = displayName, displayName = displayName,
memberships = memberships memberships = memberships,
excludeSelf = excludeSelf
) )
} }
} }

View file

@ -29,6 +29,7 @@ import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.internal.database.mapper.asDomain import im.vector.matrix.android.internal.database.mapper.asDomain
import im.vector.matrix.android.internal.database.model.RoomMemberEntity import im.vector.matrix.android.internal.database.model.RoomMemberEntity
import im.vector.matrix.android.internal.database.model.RoomMemberEntityFields import im.vector.matrix.android.internal.database.model.RoomMemberEntityFields
import im.vector.matrix.android.internal.di.UserId
import im.vector.matrix.android.internal.query.process import im.vector.matrix.android.internal.query.process
import im.vector.matrix.android.internal.session.room.membership.joining.InviteTask import im.vector.matrix.android.internal.session.room.membership.joining.InviteTask
import im.vector.matrix.android.internal.session.room.membership.joining.JoinRoomTask import im.vector.matrix.android.internal.session.room.membership.joining.JoinRoomTask
@ -39,13 +40,16 @@ import im.vector.matrix.android.internal.util.fetchCopied
import io.realm.Realm import io.realm.Realm
import io.realm.RealmQuery import io.realm.RealmQuery
internal class DefaultMembershipService @AssistedInject constructor(@Assisted private val roomId: String, internal class DefaultMembershipService @AssistedInject constructor(
private val monarchy: Monarchy, @Assisted private val roomId: String,
private val taskExecutor: TaskExecutor, private val monarchy: Monarchy,
private val loadRoomMembersTask: LoadRoomMembersTask, private val taskExecutor: TaskExecutor,
private val inviteTask: InviteTask, private val loadRoomMembersTask: LoadRoomMembersTask,
private val joinTask: JoinRoomTask, private val inviteTask: InviteTask,
private val leaveRoomTask: LeaveRoomTask private val joinTask: JoinRoomTask,
private val leaveRoomTask: LeaveRoomTask,
@UserId
private val userId: String
) : MembershipService { ) : MembershipService {
@AssistedInject.Factory @AssistedInject.Factory
@ -95,6 +99,11 @@ internal class DefaultMembershipService @AssistedInject constructor(@Assisted pr
return RoomMembers(realm, roomId).queryRoomMembersEvent() return RoomMembers(realm, roomId).queryRoomMembersEvent()
.process(RoomMemberEntityFields.MEMBERSHIP_STR, queryParams.memberships) .process(RoomMemberEntityFields.MEMBERSHIP_STR, queryParams.memberships)
.process(RoomMemberEntityFields.DISPLAY_NAME, queryParams.displayName) .process(RoomMemberEntityFields.DISPLAY_NAME, queryParams.displayName)
.apply {
if (queryParams.excludeSelf) {
notEqualTo(RoomMemberEntityFields.USER_ID, userId)
}
}
} }
override fun getNumberOfJoinedMembers(): Int { override fun getNumberOfJoinedMembers(): Int {

View file

@ -63,6 +63,7 @@ class AutocompleteMemberPresenter @AssistedInject constructor(context: Context,
QueryStringValue.Contains(query.toString(), QueryStringValue.Case.INSENSITIVE) QueryStringValue.Contains(query.toString(), QueryStringValue.Case.INSENSITIVE)
} }
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
excludeSelf = true
} }
val members = room.getRoomMembers(queryParams) val members = room.getRoomMembers(queryParams)
.asSequence() .asSequence()