mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
making value processing an injectable class, it will need to have its own dependencies to support normalisation
This commit is contained in:
parent
72508c61d9
commit
2681601d35
5 changed files with 70 additions and 44 deletions
|
@ -22,20 +22,24 @@ import io.realm.RealmQuery
|
|||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue.ContentQueryStringValue
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
fun <T : RealmObject> RealmQuery<T>.process(field: String, queryStringValue: QueryStringValue): RealmQuery<T> {
|
||||
return when (queryStringValue) {
|
||||
is QueryStringValue.NoCondition -> {
|
||||
Timber.v("No condition to process")
|
||||
this
|
||||
}
|
||||
is QueryStringValue.IsNotNull -> isNotNull(field)
|
||||
is QueryStringValue.IsNull -> isNull(field)
|
||||
is QueryStringValue.IsEmpty -> isEmpty(field)
|
||||
is QueryStringValue.IsNotEmpty -> isNotEmpty(field)
|
||||
is ContentQueryStringValue -> when (queryStringValue) {
|
||||
is QueryStringValue.Equals -> equalTo(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
is QueryStringValue.Contains -> contains(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
class QueryStringValueProcessor @Inject constructor() {
|
||||
|
||||
fun <T : RealmObject> RealmQuery<T>.process(field: String, queryStringValue: QueryStringValue): RealmQuery<T> {
|
||||
return when (queryStringValue) {
|
||||
is QueryStringValue.NoCondition -> {
|
||||
Timber.v("No condition to process")
|
||||
this
|
||||
}
|
||||
is QueryStringValue.IsNotNull -> isNotNull(field)
|
||||
is QueryStringValue.IsNull -> isNull(field)
|
||||
is QueryStringValue.IsEmpty -> isEmpty(field)
|
||||
is QueryStringValue.IsNotEmpty -> isNotEmpty(field)
|
||||
is ContentQueryStringValue -> when (queryStringValue) {
|
||||
is QueryStringValue.Equals -> equalTo(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
is QueryStringValue.Contains -> contains(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,16 @@ import org.matrix.android.sdk.internal.database.model.GroupSummaryEntity
|
|||
import org.matrix.android.sdk.internal.database.model.GroupSummaryEntityFields
|
||||
import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.query.QueryStringValueProcessor
|
||||
import org.matrix.android.sdk.internal.query.process
|
||||
import org.matrix.android.sdk.internal.util.fetchCopyMap
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultGroupService @Inject constructor(@SessionDatabase private val monarchy: Monarchy,
|
||||
private val groupFactory: GroupFactory) : GroupService {
|
||||
internal class DefaultGroupService @Inject constructor(
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val groupFactory: GroupFactory,
|
||||
private val queryStringValueProcessor: QueryStringValueProcessor,
|
||||
) : GroupService {
|
||||
|
||||
override fun getGroup(groupId: String): Group? {
|
||||
return Realm.getInstance(monarchy.realmConfiguration).use { realm ->
|
||||
|
@ -67,8 +71,10 @@ internal class DefaultGroupService @Inject constructor(@SessionDatabase private
|
|||
}
|
||||
|
||||
private fun groupSummariesQuery(realm: Realm, queryParams: GroupSummaryQueryParams): RealmQuery<GroupSummaryEntity> {
|
||||
return GroupSummaryEntity.where(realm)
|
||||
.process(GroupSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
|
||||
.process(GroupSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
|
||||
return with(queryStringValueProcessor) {
|
||||
GroupSummaryEntity.where(realm)
|
||||
.process(GroupSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
|
||||
.process(GroupSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
|||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.di.UserId
|
||||
import org.matrix.android.sdk.internal.query.QueryStringValueProcessor
|
||||
import org.matrix.android.sdk.internal.query.process
|
||||
import org.matrix.android.sdk.internal.session.room.membership.admin.MembershipAdminTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.joining.InviteTask
|
||||
|
@ -51,7 +52,8 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
|||
private val leaveRoomTask: LeaveRoomTask,
|
||||
private val membershipAdminTask: MembershipAdminTask,
|
||||
@UserId
|
||||
private val userId: String
|
||||
private val userId: String,
|
||||
private val queryStringValueProcessor: QueryStringValueProcessor
|
||||
) : MembershipService {
|
||||
|
||||
@AssistedFactory
|
||||
|
@ -94,15 +96,17 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun roomMembersQuery(realm: Realm, queryParams: RoomMemberQueryParams): RealmQuery<RoomMemberSummaryEntity> {
|
||||
return RoomMemberHelper(realm, roomId).queryRoomMembersEvent()
|
||||
.process(RoomMemberSummaryEntityFields.USER_ID, queryParams.userId)
|
||||
.process(RoomMemberSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
|
||||
.process(RoomMemberSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
|
||||
.apply {
|
||||
if (queryParams.excludeSelf) {
|
||||
notEqualTo(RoomMemberSummaryEntityFields.USER_ID, userId)
|
||||
return with(queryStringValueProcessor) {
|
||||
RoomMemberHelper(realm, roomId).queryRoomMembersEvent()
|
||||
.process(RoomMemberSummaryEntityFields.USER_ID, queryParams.userId)
|
||||
.process(RoomMemberSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
|
||||
.process(RoomMemberSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
|
||||
.apply {
|
||||
if (queryParams.excludeSelf) {
|
||||
notEqualTo(RoomMemberSummaryEntityFields.USER_ID, userId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getNumberOfJoinedMembers(): Int {
|
||||
|
|
|
@ -31,11 +31,15 @@ import org.matrix.android.sdk.internal.database.mapper.asDomain
|
|||
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
|
||||
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFields
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.query.QueryStringValueProcessor
|
||||
import org.matrix.android.sdk.internal.query.process
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class StateEventDataSource @Inject constructor(@SessionDatabase private val monarchy: Monarchy,
|
||||
private val realmSessionProvider: RealmSessionProvider) {
|
||||
internal class StateEventDataSource @Inject constructor(
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val realmSessionProvider: RealmSessionProvider,
|
||||
private val queryStringValueProcessor: QueryStringValueProcessor
|
||||
) {
|
||||
|
||||
fun getStateEvent(roomId: String, eventType: String, stateKey: QueryStringValue): Event? {
|
||||
return realmSessionProvider.withRealm { realm ->
|
||||
|
@ -78,13 +82,15 @@ internal class StateEventDataSource @Inject constructor(@SessionDatabase private
|
|||
eventTypes: Set<String>,
|
||||
stateKey: QueryStringValue
|
||||
): RealmQuery<CurrentStateEventEntity> {
|
||||
return realm.where<CurrentStateEventEntity>()
|
||||
.equalTo(CurrentStateEventEntityFields.ROOM_ID, roomId)
|
||||
.apply {
|
||||
if (eventTypes.isNotEmpty()) {
|
||||
`in`(CurrentStateEventEntityFields.TYPE, eventTypes.toTypedArray())
|
||||
return with(queryStringValueProcessor) {
|
||||
realm.where<CurrentStateEventEntity>()
|
||||
.equalTo(CurrentStateEventEntityFields.ROOM_ID, roomId)
|
||||
.apply {
|
||||
if (eventTypes.isNotEmpty()) {
|
||||
`in`(CurrentStateEventEntityFields.TYPE, eventTypes.toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
.process(CurrentStateEventEntityFields.STATE_KEY, stateKey)
|
||||
.process(CurrentStateEventEntityFields.STATE_KEY, stateKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,16 @@ import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
|
|||
import org.matrix.android.sdk.internal.database.query.findByAlias
|
||||
import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.query.QueryStringValueProcessor
|
||||
import org.matrix.android.sdk.internal.query.process
|
||||
import org.matrix.android.sdk.internal.util.fetchCopyMap
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase private val monarchy: Monarchy,
|
||||
private val roomSummaryMapper: RoomSummaryMapper) {
|
||||
internal class RoomSummaryDataSource @Inject constructor(
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val roomSummaryMapper: RoomSummaryMapper,
|
||||
private val queryStringValueProcessor: QueryStringValueProcessor
|
||||
) {
|
||||
|
||||
fun getRoomSummary(roomIdOrAlias: String): RoomSummary? {
|
||||
return monarchy
|
||||
|
@ -238,12 +242,14 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
|
|||
}
|
||||
|
||||
private fun roomSummariesQuery(realm: Realm, queryParams: RoomSummaryQueryParams): RealmQuery<RoomSummaryEntity> {
|
||||
val query = RoomSummaryEntity.where(realm)
|
||||
query.process(RoomSummaryEntityFields.ROOM_ID, queryParams.roomId)
|
||||
query.process(RoomSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
|
||||
query.process(RoomSummaryEntityFields.CANONICAL_ALIAS, queryParams.canonicalAlias)
|
||||
query.process(RoomSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
|
||||
query.equalTo(RoomSummaryEntityFields.IS_HIDDEN_FROM_USER, false)
|
||||
val query = with(queryStringValueProcessor) {
|
||||
val query = RoomSummaryEntity.where(realm)
|
||||
query.process(RoomSummaryEntityFields.ROOM_ID, queryParams.roomId)
|
||||
query.process(RoomSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
|
||||
query.process(RoomSummaryEntityFields.CANONICAL_ALIAS, queryParams.canonicalAlias)
|
||||
query.process(RoomSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
|
||||
query.equalTo(RoomSummaryEntityFields.IS_HIDDEN_FROM_USER, false)
|
||||
}
|
||||
|
||||
queryParams.roomCategoryFilter?.let {
|
||||
when (it) {
|
||||
|
|
Loading…
Reference in a new issue