2018-10-23 16:25:28 +00:00
|
|
|
package im.vector.matrix.android.internal.database.query
|
|
|
|
|
|
|
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
2018-10-26 13:12:38 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntityFields
|
2018-10-23 16:25:28 +00:00
|
|
|
import io.realm.Realm
|
|
|
|
import io.realm.RealmQuery
|
2018-10-26 13:12:38 +00:00
|
|
|
import io.realm.kotlin.where
|
2018-10-23 16:25:28 +00:00
|
|
|
|
|
|
|
fun RoomSummaryEntity.Companion.where(realm: Realm, roomId: String? = null): RealmQuery<RoomSummaryEntity> {
|
2018-10-26 13:12:38 +00:00
|
|
|
val query = realm.where<RoomSummaryEntity>()
|
2018-10-23 16:25:28 +00:00
|
|
|
if (roomId != null) {
|
2018-10-26 13:12:38 +00:00
|
|
|
query.equalTo(RoomSummaryEntityFields.ROOM_ID, roomId)
|
2018-10-23 16:25:28 +00:00
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
2018-10-28 18:18:14 +00:00
|
|
|
|
|
|
|
fun RoomSummaryEntity.Companion.lastSelected(realm: Realm): RoomSummaryEntity? {
|
|
|
|
return realm.where<RoomSummaryEntity>()
|
|
|
|
.equalTo(RoomSummaryEntityFields.IS_LATEST_SELECTED, true)
|
|
|
|
.findFirst()
|
|
|
|
}
|