2019-01-18 10:12:08 +00:00
|
|
|
/*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-01-18 10:12:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-12 17:26:22 +00:00
|
|
|
package im.vector.matrix.android.internal.database.query
|
|
|
|
|
2019-05-07 17:33:58 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.model.Membership
|
2019-02-26 13:50:53 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
2018-10-12 17:26:22 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.RoomEntity
|
2018-10-26 13:12:38 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.RoomEntityFields
|
2018-10-15 17:42:13 +00:00
|
|
|
import io.realm.Realm
|
2018-10-17 16:21:09 +00:00
|
|
|
import io.realm.RealmQuery
|
2018-10-26 13:12:38 +00:00
|
|
|
import io.realm.kotlin.where
|
2018-10-12 17:26:22 +00:00
|
|
|
|
2018-11-08 10:04:40 +00:00
|
|
|
internal fun RoomEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<RoomEntity> {
|
2019-07-09 13:33:31 +00:00
|
|
|
return realm.where<RoomEntity>()
|
|
|
|
.equalTo(RoomEntityFields.ROOM_ID, roomId)
|
2018-10-12 17:26:22 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 17:33:58 +00:00
|
|
|
internal fun RoomEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<RoomEntity> {
|
2018-10-26 13:12:38 +00:00
|
|
|
val query = realm.where<RoomEntity>()
|
2018-10-12 17:26:22 +00:00
|
|
|
if (membership != null) {
|
2018-10-26 13:12:38 +00:00
|
|
|
query.equalTo(RoomEntityFields.MEMBERSHIP_STR, membership.name)
|
2018-10-12 17:26:22 +00:00
|
|
|
}
|
2018-10-17 16:21:09 +00:00
|
|
|
return query
|
2018-10-16 13:52:30 +00:00
|
|
|
}
|
2019-02-26 13:50:53 +00:00
|
|
|
|
|
|
|
internal fun RoomEntity.fastContains(eventId: String): Boolean {
|
|
|
|
return EventEntity.where(realm, eventId = eventId).findFirst() != null
|
|
|
|
}
|