Realm kotlin: continue migrating queries (some are blocked by lack of backlink)
This commit is contained in:
parent
aeaf4389a8
commit
a4a4bac75b
@ -55,6 +55,23 @@ internal fun <T : RealmObject> RealmQuery<T>.queryIn(
|
||||
values: List<String>
|
||||
): RealmQuery<T> {
|
||||
if (values.isEmpty()) return this
|
||||
val filter = buildQueryInFilter(field, values)
|
||||
return query(filter)
|
||||
}
|
||||
|
||||
internal fun <T : RealmObject> RealmQuery<T>.queryNotIn(
|
||||
field: String,
|
||||
values: List<String>
|
||||
): RealmQuery<T> {
|
||||
if (values.isEmpty()) return this
|
||||
val filter = buildQueryInFilter(field, values)
|
||||
return query("NOT $filter")
|
||||
}
|
||||
|
||||
private fun buildQueryInFilter(
|
||||
field: String,
|
||||
values: List<String>
|
||||
): String {
|
||||
val filter = buildString {
|
||||
val iterator = values.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
@ -64,7 +81,7 @@ internal fun <T : RealmObject> RealmQuery<T>.queryIn(
|
||||
}
|
||||
}
|
||||
}
|
||||
return query(filter)
|
||||
return filter
|
||||
}
|
||||
|
||||
internal fun <T : RealmObject> RealmQuery<T>.andIf(
|
||||
|
||||
@ -16,15 +16,16 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import org.matrix.android.sdk.internal.database.model.BreadcrumbsEntity
|
||||
|
||||
internal fun BreadcrumbsEntity.Companion.get(realm: Realm): BreadcrumbsEntity? {
|
||||
return realm.where<BreadcrumbsEntity>().findFirst()
|
||||
internal fun BreadcrumbsEntity.Companion.get(realm: TypedRealm): BreadcrumbsEntity? {
|
||||
return realm.query(BreadcrumbsEntity::class).first().find()
|
||||
}
|
||||
|
||||
internal fun BreadcrumbsEntity.Companion.getOrCreate(realm: Realm): BreadcrumbsEntity {
|
||||
return get(realm) ?: realm.createObject()
|
||||
internal fun BreadcrumbsEntity.Companion.getOrCreate(realm: MutableRealm): BreadcrumbsEntity {
|
||||
return get(realm) ?: BreadcrumbsEntity().also {
|
||||
realm.copyToRealm(it)
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,17 +16,12 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.RealmResults
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import org.matrix.android.sdk.internal.database.model.ChunkEntity
|
||||
import org.matrix.android.sdk.internal.database.model.ChunkEntityFields
|
||||
|
||||
internal fun ChunkEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<ChunkEntity> {
|
||||
return realm.where<ChunkEntity>()
|
||||
.equalTo(ChunkEntityFields.ROOM.ROOM_ID, roomId)
|
||||
internal fun ChunkEntity.Companion.where(realm: TypedRealm, roomId: String): RealmQuery<ChunkEntity> {
|
||||
return realm.query(ChunkEntity::class)
|
||||
.query(ChunkEntityFields.ROOM.ROOM_ID, roomId)
|
||||
}
|
||||
|
||||
internal fun ChunkEntity.Companion.find(realm: Realm, roomId: String, prevToken: String? = null, nextToken: String? = null): ChunkEntity? {
|
||||
|
||||
@ -17,50 +17,49 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
|
||||
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFields
|
||||
|
||||
internal fun CurrentStateEventEntity.Companion.whereRoomId(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String
|
||||
): RealmQuery<CurrentStateEventEntity> {
|
||||
return realm.where(CurrentStateEventEntity::class.java)
|
||||
.equalTo(CurrentStateEventEntityFields.ROOM_ID, roomId)
|
||||
return realm.query(CurrentStateEventEntity::class)
|
||||
.query("roomId == $0", roomId)
|
||||
}
|
||||
|
||||
internal fun CurrentStateEventEntity.Companion.whereType(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String,
|
||||
type: String
|
||||
): RealmQuery<CurrentStateEventEntity> {
|
||||
return whereRoomId(realm = realm, roomId = roomId)
|
||||
.equalTo(CurrentStateEventEntityFields.TYPE, type)
|
||||
.query("type == $0", type)
|
||||
}
|
||||
|
||||
internal fun CurrentStateEventEntity.Companion.whereStateKey(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String,
|
||||
type: String,
|
||||
stateKey: String
|
||||
): RealmQuery<CurrentStateEventEntity> {
|
||||
return whereType(realm = realm, roomId = roomId, type = type)
|
||||
.equalTo(CurrentStateEventEntityFields.STATE_KEY, stateKey)
|
||||
.query("stateKey == $0", stateKey)
|
||||
}
|
||||
|
||||
internal fun CurrentStateEventEntity.Companion.getOrNull(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String,
|
||||
stateKey: String,
|
||||
type: String
|
||||
): CurrentStateEventEntity? {
|
||||
return whereStateKey(realm = realm, roomId = roomId, type = type, stateKey = stateKey).findFirst()
|
||||
return whereStateKey(realm = realm, roomId = roomId, type = type, stateKey = stateKey).first().find()
|
||||
}
|
||||
|
||||
internal fun CurrentStateEventEntity.Companion.getOrCreate(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
stateKey: String,
|
||||
type: String
|
||||
@ -69,14 +68,15 @@ internal fun CurrentStateEventEntity.Companion.getOrCreate(
|
||||
}
|
||||
|
||||
private fun create(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
stateKey: String,
|
||||
type: String
|
||||
): CurrentStateEventEntity {
|
||||
return realm.createObject<CurrentStateEventEntity>().apply {
|
||||
val currentStateEventEntity = CurrentStateEventEntity().apply {
|
||||
this.type = type
|
||||
this.roomId = roomId
|
||||
this.stateKey = stateKey
|
||||
}
|
||||
return realm.copyToRealm(currentStateEventEntity)
|
||||
}
|
||||
|
||||
@ -16,28 +16,30 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.model.EventAnnotationsSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.model.EventAnnotationsSummaryEntityFields
|
||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
||||
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<EventAnnotationsSummaryEntity> {
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.where(realm: TypedRealm, eventId: String): RealmQuery<EventAnnotationsSummaryEntity> {
|
||||
return realm.where<EventAnnotationsSummaryEntity>()
|
||||
.equalTo(EventAnnotationsSummaryEntityFields.EVENT_ID, eventId)
|
||||
}
|
||||
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.where(realm: Realm, roomId: String, eventId: String): RealmQuery<EventAnnotationsSummaryEntity> {
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.where(realm: TypedRealm, roomId: String, eventId: String): RealmQuery<EventAnnotationsSummaryEntity> {
|
||||
return realm.where<EventAnnotationsSummaryEntity>()
|
||||
.equalTo(EventAnnotationsSummaryEntityFields.ROOM_ID, roomId)
|
||||
.equalTo(EventAnnotationsSummaryEntityFields.EVENT_ID, eventId)
|
||||
}
|
||||
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.create(realm: Realm, roomId: String, eventId: String): EventAnnotationsSummaryEntity {
|
||||
val obj = realm.createObject(EventAnnotationsSummaryEntity::class.java, eventId).apply {
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.create(realm: MutableRealm, roomId: String, eventId: String): EventAnnotationsSummaryEntity {
|
||||
val obj = EventAnnotationsSummaryEntity().apply {
|
||||
this.eventId = eventId
|
||||
this.roomId = roomId
|
||||
}
|
||||
val managedObj = realm.copyToRealm(obj)
|
||||
// Denormalization
|
||||
TimelineEventEntity.where(realm, roomId = roomId, eventId = eventId).findAll()?.forEach {
|
||||
it.annotations = obj
|
||||
@ -45,11 +47,11 @@ internal fun EventAnnotationsSummaryEntity.Companion.create(realm: Realm, roomId
|
||||
return obj
|
||||
}
|
||||
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.getOrCreate(realm: Realm, roomId: String, eventId: String): EventAnnotationsSummaryEntity {
|
||||
return EventAnnotationsSummaryEntity.where(realm, roomId, eventId).findFirst()
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.getOrCreate(realm: MutableRealm, roomId: String, eventId: String): EventAnnotationsSummaryEntity {
|
||||
return EventAnnotationsSummaryEntity.where(realm, roomId, eventId).first().find()
|
||||
?: EventAnnotationsSummaryEntity.create(realm, roomId, eventId)
|
||||
}
|
||||
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.get(realm: Realm, eventId: String): EventAnnotationsSummaryEntity? {
|
||||
return EventAnnotationsSummaryEntity.where(realm, eventId).findFirst()
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.get(realm: TypedRealm, eventId: String): EventAnnotationsSummaryEntity? {
|
||||
return EventAnnotationsSummaryEntity.where(realm, eventId).first().find()
|
||||
}
|
||||
|
||||
@ -16,27 +16,34 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.internal.database.andIf
|
||||
import org.matrix.android.sdk.internal.database.model.EventEntity
|
||||
import org.matrix.android.sdk.internal.database.model.EventEntityFields
|
||||
import org.matrix.android.sdk.internal.database.model.EventInsertEntity
|
||||
import org.matrix.android.sdk.internal.database.model.EventInsertType
|
||||
import org.matrix.android.sdk.internal.database.queryIn
|
||||
|
||||
internal fun EventEntity.copyToRealmOrIgnore(realm: Realm, insertType: EventInsertType): EventEntity {
|
||||
val eventEntity = realm.where<EventEntity>()
|
||||
.equalTo(EventEntityFields.EVENT_ID, eventId)
|
||||
.equalTo(EventEntityFields.ROOM_ID, roomId)
|
||||
.findFirst()
|
||||
internal fun EventEntity.copyToRealmOrIgnore(realm: MutableRealm, insertType: EventInsertType): EventEntity {
|
||||
val eventId = this.eventId
|
||||
val type = this.type
|
||||
val eventEntity = realm.query(EventEntity::class)
|
||||
.query("eventId == $0", eventId)
|
||||
.query("roomId == $0", roomId)
|
||||
.first()
|
||||
.find()
|
||||
return if (eventEntity == null) {
|
||||
val canBeProcessed = type != EventType.ENCRYPTED || decryptionResultJson != null
|
||||
val insertEntity = EventInsertEntity(eventId = eventId, eventType = type, canBeProcessed = canBeProcessed).apply {
|
||||
val insertEntity = EventInsertEntity().apply {
|
||||
this.eventId = eventId
|
||||
this.eventType = type
|
||||
this.canBeProcessed = canBeProcessed
|
||||
this.insertType = insertType
|
||||
}
|
||||
realm.insert(insertEntity)
|
||||
realm.copyToRealm(insertEntity)
|
||||
// copy this event entity and return it
|
||||
realm.copyToRealm(this)
|
||||
} else {
|
||||
@ -44,44 +51,43 @@ internal fun EventEntity.copyToRealmOrIgnore(realm: Realm, insertType: EventInse
|
||||
}
|
||||
}
|
||||
|
||||
internal fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<EventEntity> {
|
||||
return realm.where<EventEntity>()
|
||||
.equalTo(EventEntityFields.EVENT_ID, eventId)
|
||||
internal fun EventEntity.Companion.where(realm: TypedRealm, eventId: String): RealmQuery<EventEntity> {
|
||||
return realm.query(EventEntity::class)
|
||||
.query("eventId == $0", eventId)
|
||||
}
|
||||
|
||||
internal fun EventEntity.Companion.whereRoomId(realm: Realm, roomId: String): RealmQuery<EventEntity> {
|
||||
return realm.where<EventEntity>()
|
||||
.equalTo(EventEntityFields.ROOM_ID, roomId)
|
||||
internal fun EventEntity.Companion.whereRoomId(realm: TypedRealm, roomId: String): RealmQuery<EventEntity> {
|
||||
return realm.query(EventEntity::class)
|
||||
.query("roomId == $0", roomId)
|
||||
}
|
||||
|
||||
internal fun EventEntity.Companion.where(realm: Realm, eventIds: List<String>): RealmQuery<EventEntity> {
|
||||
return realm.where<EventEntity>()
|
||||
.`in`(EventEntityFields.EVENT_ID, eventIds.toTypedArray())
|
||||
internal fun EventEntity.Companion.where(realm: TypedRealm, eventIds: List<String>): RealmQuery<EventEntity> {
|
||||
return realm.query(EventEntity::class)
|
||||
.queryIn("eventId", eventIds)
|
||||
}
|
||||
|
||||
internal fun EventEntity.Companion.whereType(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
type: String,
|
||||
roomId: String? = null
|
||||
): RealmQuery<EventEntity> {
|
||||
val query = realm.where<EventEntity>()
|
||||
if (roomId != null) {
|
||||
query.equalTo(EventEntityFields.ROOM_ID, roomId)
|
||||
}
|
||||
return query.equalTo(EventEntityFields.TYPE, type)
|
||||
return realm.query(EventEntity::class)
|
||||
.query("type == $0", type)
|
||||
.andIf(roomId != null){
|
||||
query("roomId == $0", roomId!!)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun EventEntity.Companion.whereTypes(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
typeList: List<String> = emptyList(),
|
||||
roomId: String? = null
|
||||
): RealmQuery<EventEntity> {
|
||||
val query = realm.where<EventEntity>()
|
||||
query.`in`(EventEntityFields.TYPE, typeList.toTypedArray())
|
||||
if (roomId != null) {
|
||||
query.equalTo(EventEntityFields.ROOM_ID, roomId)
|
||||
}
|
||||
return query
|
||||
return realm.query(EventEntity::class)
|
||||
.queryIn("type", typeList)
|
||||
.andIf(roomId != null){
|
||||
query("roomId == $0", roomId!!)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun RealmList<EventEntity>.find(eventId: String): EventEntity? {
|
||||
|
||||
@ -16,27 +16,30 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import org.matrix.android.sdk.internal.database.model.FilterEntity
|
||||
import org.matrix.android.sdk.internal.session.filter.FilterFactory
|
||||
|
||||
/**
|
||||
* Get the current filter.
|
||||
*/
|
||||
internal fun FilterEntity.Companion.get(realm: Realm): FilterEntity? {
|
||||
return realm.where<FilterEntity>().findFirst()
|
||||
internal fun FilterEntity.Companion.get(realm: TypedRealm): FilterEntity? {
|
||||
return realm.query(FilterEntity::class).first().find()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current filter, create one if it does not exist.
|
||||
*/
|
||||
internal fun FilterEntity.Companion.getOrCreate(realm: Realm): FilterEntity {
|
||||
return get(realm) ?: realm.createObject<FilterEntity>()
|
||||
.apply {
|
||||
filterBodyJson = FilterFactory.createDefaultFilter().toJSONString()
|
||||
roomEventFilterJson = FilterFactory.createDefaultRoomFilter().toJSONString()
|
||||
filterId = ""
|
||||
}
|
||||
internal fun FilterEntity.Companion.getOrCreate(realm: MutableRealm): FilterEntity {
|
||||
return get(realm) ?: create(realm)
|
||||
}
|
||||
|
||||
internal fun FilterEntity.Companion.create(realm: MutableRealm): FilterEntity {
|
||||
val filterEntity = FilterEntity().apply {
|
||||
filterBodyJson = FilterFactory.createDefaultFilter().toJSONString()
|
||||
roomEventFilterJson = FilterFactory.createDefaultRoomFilter().toJSONString()
|
||||
filterId = ""
|
||||
}
|
||||
return realm.copyToRealm(filterEntity)
|
||||
}
|
||||
|
||||
@ -16,21 +16,25 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity
|
||||
|
||||
/**
|
||||
* Get the current HomeServerCapabilitiesEntity, return null if it does not exist.
|
||||
*/
|
||||
internal fun HomeServerCapabilitiesEntity.Companion.get(realm: Realm): HomeServerCapabilitiesEntity? {
|
||||
return realm.where<HomeServerCapabilitiesEntity>().findFirst()
|
||||
internal fun HomeServerCapabilitiesEntity.Companion.get(realm: TypedRealm): HomeServerCapabilitiesEntity? {
|
||||
return realm.query(HomeServerCapabilitiesEntity::class).first().find()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current HomeServerCapabilitiesEntity, create one if it does not exist.
|
||||
*/
|
||||
internal fun HomeServerCapabilitiesEntity.Companion.getOrCreate(realm: Realm): HomeServerCapabilitiesEntity {
|
||||
return get(realm) ?: realm.createObject()
|
||||
internal fun HomeServerCapabilitiesEntity.Companion.getOrCreate(realm: MutableRealm): HomeServerCapabilitiesEntity {
|
||||
return get(realm) ?: create(realm)
|
||||
}
|
||||
|
||||
internal fun HomeServerCapabilitiesEntity.Companion.create(realm: MutableRealm): HomeServerCapabilitiesEntity {
|
||||
return realm.copyToRealm(HomeServerCapabilitiesEntity())
|
||||
}
|
||||
|
||||
|
||||
@ -16,24 +16,30 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntity
|
||||
import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntityFields
|
||||
|
||||
/**
|
||||
* Get the current PreviewUrlCacheEntity, return null if it does not exist.
|
||||
*/
|
||||
internal fun PreviewUrlCacheEntity.Companion.get(realm: Realm, url: String): PreviewUrlCacheEntity? {
|
||||
return realm.where<PreviewUrlCacheEntity>()
|
||||
.equalTo(PreviewUrlCacheEntityFields.URL, url)
|
||||
.findFirst()
|
||||
internal fun PreviewUrlCacheEntity.Companion.get(realm: TypedRealm, url: String): PreviewUrlCacheEntity? {
|
||||
return realm.query(PreviewUrlCacheEntity::class)
|
||||
.query("url == $0", url)
|
||||
.first()
|
||||
.find()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current PreviewUrlCacheEntity, create one if it does not exist.
|
||||
*/
|
||||
internal fun PreviewUrlCacheEntity.Companion.getOrCreate(realm: Realm, url: String): PreviewUrlCacheEntity {
|
||||
return get(realm, url) ?: realm.createObject(url)
|
||||
internal fun PreviewUrlCacheEntity.Companion.getOrCreate(realm: MutableRealm, url: String): PreviewUrlCacheEntity {
|
||||
return get(realm, url) ?: create(realm, url)
|
||||
}
|
||||
|
||||
internal fun PreviewUrlCacheEntity.Companion.create(realm: MutableRealm, url: String): PreviewUrlCacheEntity {
|
||||
val previewUrlCacheEntity = PreviewUrlCacheEntity().apply {
|
||||
this.url = url
|
||||
}
|
||||
return realm.copyToRealm(previewUrlCacheEntity)
|
||||
}
|
||||
|
||||
@ -15,45 +15,45 @@
|
||||
*/
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.api.session.pushrules.RuleKind
|
||||
import org.matrix.android.sdk.internal.database.andIf
|
||||
import org.matrix.android.sdk.internal.database.model.PushRuleEntity
|
||||
import org.matrix.android.sdk.internal.database.model.PushRuleEntityFields
|
||||
import org.matrix.android.sdk.internal.database.model.PushRulesEntity
|
||||
import org.matrix.android.sdk.internal.database.model.PushRulesEntityFields
|
||||
import org.matrix.android.sdk.internal.database.model.PusherEntity
|
||||
import org.matrix.android.sdk.internal.database.model.PusherEntityFields
|
||||
|
||||
internal fun PusherEntity.Companion.where(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
pushKey: String? = null
|
||||
): RealmQuery<PusherEntity> {
|
||||
return realm.where<PusherEntity>()
|
||||
.apply {
|
||||
if (pushKey != null) {
|
||||
equalTo(PusherEntityFields.PUSH_KEY, pushKey)
|
||||
}
|
||||
return realm.query(PusherEntity::class)
|
||||
.andIf(pushKey != null) {
|
||||
query("pushKey == $0", pushKey!!)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PushRulesEntity.Companion.where(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
scope: String,
|
||||
kind: RuleKind
|
||||
): RealmQuery<PushRulesEntity> {
|
||||
return realm.where<PushRulesEntity>()
|
||||
.equalTo(PushRulesEntityFields.SCOPE, scope)
|
||||
.equalTo(PushRulesEntityFields.KIND_STR, kind.name)
|
||||
return realm.query(PushRulesEntity::class)
|
||||
.query("scope == $0", scope)
|
||||
.query("kindStr == $0", kind.name)
|
||||
}
|
||||
|
||||
/*
|
||||
internal fun PushRuleEntity.Companion.where(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
scope: String,
|
||||
ruleId: String
|
||||
): RealmQuery<PushRuleEntity> {
|
||||
return realm.where<PushRuleEntity>()
|
||||
return realm.query(PushRuleEntity::class)
|
||||
.equalTo(PushRuleEntityFields.PARENT.SCOPE, scope)
|
||||
.equalTo(PushRuleEntityFields.RULE_ID, ruleId)
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@ -16,18 +16,24 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.model.ReadMarkerEntity
|
||||
import org.matrix.android.sdk.internal.database.model.ReadMarkerEntityFields
|
||||
|
||||
internal fun ReadMarkerEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<ReadMarkerEntity> {
|
||||
return realm.where<ReadMarkerEntity>()
|
||||
.equalTo(ReadMarkerEntityFields.ROOM_ID, roomId)
|
||||
internal fun ReadMarkerEntity.Companion.where(realm: TypedRealm, roomId: String): RealmQuery<ReadMarkerEntity> {
|
||||
return realm.query(ReadMarkerEntity::class)
|
||||
.query("roomId == $0", roomId)
|
||||
}
|
||||
|
||||
internal fun ReadMarkerEntity.Companion.getOrCreate(realm: Realm, roomId: String): ReadMarkerEntity {
|
||||
return where(realm, roomId).findFirst() ?: realm.createObject(roomId)
|
||||
internal fun ReadMarkerEntity.Companion.getOrCreate(realm: MutableRealm, roomId: String): ReadMarkerEntity {
|
||||
return where(realm, roomId).first().find() ?: create(realm, roomId)
|
||||
}
|
||||
|
||||
internal fun ReadMarkerEntity.Companion.create(realm: MutableRealm, roomId: String): ReadMarkerEntity {
|
||||
val readMarkerEntity = ReadMarkerEntity().apply {
|
||||
this.roomId = roomId
|
||||
}
|
||||
return realm.copyToRealm(readMarkerEntity)
|
||||
}
|
||||
|
||||
|
||||
@ -16,21 +16,19 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.Realm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.model.ReadReceiptEntity
|
||||
import org.matrix.android.sdk.internal.database.model.ReadReceiptEntityFields
|
||||
|
||||
internal fun ReadReceiptEntity.Companion.where(realm: Realm, roomId: String, userId: String): RealmQuery<ReadReceiptEntity> {
|
||||
return realm.where<ReadReceiptEntity>()
|
||||
.equalTo(ReadReceiptEntityFields.PRIMARY_KEY, buildPrimaryKey(roomId, userId))
|
||||
return realm.query(ReadReceiptEntity::class)
|
||||
.query("primaryKey == $0", buildPrimaryKey(roomId, userId))
|
||||
}
|
||||
|
||||
internal fun ReadReceiptEntity.Companion.whereUserId(realm: Realm, userId: String): RealmQuery<ReadReceiptEntity> {
|
||||
return realm.where<ReadReceiptEntity>()
|
||||
.equalTo(ReadReceiptEntityFields.USER_ID, userId)
|
||||
return realm.query(ReadReceiptEntity::class)
|
||||
.query("userId == $0", userId)
|
||||
}
|
||||
|
||||
internal fun ReadReceiptEntity.Companion.createUnmanaged(roomId: String, eventId: String, userId: String, originServerTs: Double): ReadReceiptEntity {
|
||||
@ -43,13 +41,16 @@ internal fun ReadReceiptEntity.Companion.createUnmanaged(roomId: String, eventId
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ReadReceiptEntity.Companion.getOrCreate(realm: Realm, roomId: String, userId: String): ReadReceiptEntity {
|
||||
return ReadReceiptEntity.where(realm, roomId, userId).findFirst()
|
||||
?: realm.createObject<ReadReceiptEntity>(buildPrimaryKey(roomId, userId))
|
||||
.apply {
|
||||
this.roomId = roomId
|
||||
this.userId = userId
|
||||
}
|
||||
internal fun ReadReceiptEntity.Companion.getOrCreate(realm: MutableRealm, roomId: String, userId: String): ReadReceiptEntity {
|
||||
return ReadReceiptEntity.where(realm, roomId, userId).first()
|
||||
?: {
|
||||
val entity = ReadReceiptEntity().apply {
|
||||
this.primaryKey = buildPrimaryKey(roomId, userId)
|
||||
this.roomId = roomId
|
||||
this.userId = userId
|
||||
}
|
||||
realm.copyToRealm(entity)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildPrimaryKey(roomId: String, userId: String) = "${roomId}_$userId"
|
||||
|
||||
@ -16,18 +16,18 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import io.realm.kotlin.query.RealmSingleQuery
|
||||
import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntityFields
|
||||
|
||||
internal fun ReadReceiptsSummaryEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<ReadReceiptsSummaryEntity> {
|
||||
return realm.where<ReadReceiptsSummaryEntity>()
|
||||
.equalTo(ReadReceiptsSummaryEntityFields.EVENT_ID, eventId)
|
||||
internal fun ReadReceiptsSummaryEntity.Companion.where(realm: TypedRealm, eventId: String): RealmSingleQuery<ReadReceiptsSummaryEntity> {
|
||||
return realm.query(ReadReceiptsSummaryEntity::class)
|
||||
.query("eventId == $0", eventId)
|
||||
.first()
|
||||
}
|
||||
|
||||
internal fun ReadReceiptsSummaryEntity.Companion.whereInRoom(realm: Realm, roomId: String): RealmQuery<ReadReceiptsSummaryEntity> {
|
||||
return realm.where<ReadReceiptsSummaryEntity>()
|
||||
.equalTo(ReadReceiptsSummaryEntityFields.ROOM_ID, roomId)
|
||||
internal fun ReadReceiptsSummaryEntity.Companion.whereInRoom(realm: TypedRealm, roomId: String): RealmQuery<ReadReceiptsSummaryEntity> {
|
||||
return realm.query(ReadReceiptsSummaryEntity::class)
|
||||
.query("roomId == $0", roomId)
|
||||
}
|
||||
|
||||
@ -16,32 +16,38 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.internal.database.andIf
|
||||
import org.matrix.android.sdk.internal.database.model.EventEntity
|
||||
import org.matrix.android.sdk.internal.database.model.RoomEntity
|
||||
import org.matrix.android.sdk.internal.database.model.RoomEntityFields
|
||||
import org.matrix.android.sdk.internal.extensions.realm
|
||||
|
||||
internal fun RoomEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<RoomEntity> {
|
||||
return realm.where<RoomEntity>()
|
||||
.equalTo(RoomEntityFields.ROOM_ID, roomId)
|
||||
internal fun RoomEntity.Companion.where(realm: TypedRealm, roomId: String): RealmQuery<RoomEntity> {
|
||||
return realm.query(RoomEntity::class)
|
||||
.query("roomId == $0", roomId)
|
||||
}
|
||||
|
||||
internal fun RoomEntity.Companion.getOrCreate(realm: Realm, roomId: String): RoomEntity {
|
||||
return where(realm, roomId).findFirst() ?: realm.createObject(RoomEntity::class.java, roomId)
|
||||
internal fun RoomEntity.Companion.getOrCreate(realm: MutableRealm, roomId: String): RoomEntity {
|
||||
return where(realm, roomId).first().find() ?: create(realm, roomId)
|
||||
}
|
||||
|
||||
internal fun RoomEntity.Companion.where(realm: Realm, membership: Membership? = null): RealmQuery<RoomEntity> {
|
||||
val query = realm.where<RoomEntity>()
|
||||
if (membership != null) {
|
||||
query.equalTo(RoomEntityFields.MEMBERSHIP_STR, membership.name)
|
||||
internal fun RoomEntity.Companion.create(realm: MutableRealm, roomId: String): RoomEntity {
|
||||
val entity = RoomEntity().apply {
|
||||
this.roomId = roomId
|
||||
}
|
||||
return query
|
||||
return realm.copyToRealm(entity)
|
||||
}
|
||||
|
||||
internal fun RoomEntity.fastContains(eventId: String): Boolean {
|
||||
internal fun RoomEntity.Companion.where(realm: TypedRealm, membership: Membership? = null): RealmQuery<RoomEntity> {
|
||||
return realm.query(RoomEntity::class)
|
||||
.andIf(membership != null) {
|
||||
query("membershipStr == $0", membership!!.name)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun RoomEntity.fastContains(realm: TypedRealm, eventId: String): Boolean {
|
||||
return EventEntity.where(realm, eventId = eventId).findFirst() != null
|
||||
}
|
||||
|
||||
@ -16,29 +16,26 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.andIf
|
||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields
|
||||
import org.matrix.android.sdk.internal.database.model.presence.UserPresenceEntity
|
||||
|
||||
internal fun RoomMemberSummaryEntity.Companion.where(realm: Realm, roomId: String, userId: String? = null): RealmQuery<RoomMemberSummaryEntity> {
|
||||
val query = realm
|
||||
.where<RoomMemberSummaryEntity>()
|
||||
.equalTo(RoomMemberSummaryEntityFields.ROOM_ID, roomId)
|
||||
|
||||
if (userId != null) {
|
||||
query.equalTo(RoomMemberSummaryEntityFields.USER_ID, userId)
|
||||
}
|
||||
return query
|
||||
internal fun RoomMemberSummaryEntity.Companion.where(realm: TypedRealm, roomId: String, userId: String? = null): RealmQuery<RoomMemberSummaryEntity> {
|
||||
return realm.query(RoomMemberSummaryEntity::class)
|
||||
.query("roomId == $0", roomId)
|
||||
.andIf(userId != null) {
|
||||
query("userId == $0", userId!!)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun RoomMemberSummaryEntity.Companion.updateUserPresence(realm: Realm, userId: String, userPresenceEntity: UserPresenceEntity) {
|
||||
realm.where<RoomMemberSummaryEntity>()
|
||||
.equalTo(RoomMemberSummaryEntityFields.USER_ID, userId)
|
||||
.isNull(RoomMemberSummaryEntityFields.USER_PRESENCE_ENTITY.`$`)
|
||||
.findAll()
|
||||
internal fun RoomMemberSummaryEntity.Companion.updateUserPresence(realm: MutableRealm, userId: String, userPresenceEntity: UserPresenceEntity) {
|
||||
realm.query(RoomMemberSummaryEntity::class)
|
||||
.query("userId == $0", userId)
|
||||
.query("userPresenceEntity == nil")
|
||||
.find()
|
||||
.map {
|
||||
it.userPresenceEntity = userPresenceEntity
|
||||
}
|
||||
|
||||
@ -16,14 +16,12 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.model.ScalarTokenEntity
|
||||
import org.matrix.android.sdk.internal.database.model.ScalarTokenEntityFields
|
||||
|
||||
internal fun ScalarTokenEntity.Companion.where(realm: Realm, serverUrl: String): RealmQuery<ScalarTokenEntity> {
|
||||
internal fun ScalarTokenEntity.Companion.where(realm: TypedRealm, serverUrl: String): RealmQuery<ScalarTokenEntity> {
|
||||
return realm
|
||||
.where<ScalarTokenEntity>()
|
||||
.equalTo(ScalarTokenEntityFields.SERVER_URL, serverUrl)
|
||||
.query(ScalarTokenEntity::class)
|
||||
.query("serverUrl == $0", serverUrl)
|
||||
}
|
||||
|
||||
@ -16,62 +16,59 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.RealmResults
|
||||
import io.realm.Sort
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEventFilters
|
||||
import org.matrix.android.sdk.internal.database.model.ChunkEntity
|
||||
import org.matrix.android.sdk.internal.database.model.RoomEntity
|
||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
|
||||
import org.matrix.android.sdk.internal.database.queryIn
|
||||
|
||||
internal fun TimelineEventEntity.Companion.where(realm: Realm): RealmQuery<TimelineEventEntity> {
|
||||
return realm.where()
|
||||
internal fun TimelineEventEntity.Companion.where(realm: TypedRealm): RealmQuery<TimelineEventEntity> {
|
||||
return realm.query(TimelineEventEntity::class)
|
||||
}
|
||||
|
||||
internal fun TimelineEventEntity.Companion.where(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String,
|
||||
eventId: String
|
||||
): RealmQuery<TimelineEventEntity> {
|
||||
return where(realm)
|
||||
.equalTo(TimelineEventEntityFields.ROOM_ID, roomId)
|
||||
.equalTo(TimelineEventEntityFields.EVENT_ID, eventId)
|
||||
.query("roomId == $0", roomId)
|
||||
.query("evendId == $0", eventId)
|
||||
}
|
||||
|
||||
internal fun TimelineEventEntity.Companion.where(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String,
|
||||
eventIds: List<String>
|
||||
): RealmQuery<TimelineEventEntity> {
|
||||
return where(realm)
|
||||
.equalTo(TimelineEventEntityFields.ROOM_ID, roomId)
|
||||
.`in`(TimelineEventEntityFields.EVENT_ID, eventIds.toTypedArray())
|
||||
.query("roomId == $0", roomId)
|
||||
.queryIn("evendId", eventIds)
|
||||
}
|
||||
|
||||
internal fun TimelineEventEntity.Companion.whereRoomId(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String
|
||||
): RealmQuery<TimelineEventEntity> {
|
||||
return where(realm)
|
||||
.equalTo(TimelineEventEntityFields.ROOM_ID, roomId)
|
||||
.query("roomId == $0", roomId)
|
||||
}
|
||||
|
||||
internal fun TimelineEventEntity.Companion.findWithSenderMembershipEvent(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
senderMembershipEventId: String
|
||||
): List<TimelineEventEntity> {
|
||||
return where(realm)
|
||||
.equalTo(TimelineEventEntityFields.SENDER_MEMBERSHIP_EVENT_ID, senderMembershipEventId)
|
||||
.findAll()
|
||||
.query("senderMembershipEventId == $0", senderMembershipEventId)
|
||||
.find()
|
||||
}
|
||||
|
||||
internal fun TimelineEventEntity.Companion.latestEvent(
|
||||
realm: Realm,
|
||||
realm: TypedRealm,
|
||||
roomId: String,
|
||||
includesSending: Boolean,
|
||||
filters: TimelineEventFilters = TimelineEventFilters()
|
||||
|
||||
@ -16,14 +16,12 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.model.UserEntity
|
||||
import org.matrix.android.sdk.internal.database.model.UserEntityFields
|
||||
|
||||
internal fun UserEntity.Companion.where(realm: Realm, userId: String): RealmQuery<UserEntity> {
|
||||
internal fun UserEntity.Companion.where(realm: TypedRealm, userId: String): RealmQuery<UserEntity> {
|
||||
return realm
|
||||
.where<UserEntity>()
|
||||
.equalTo(UserEntityFields.USER_ID, userId)
|
||||
.query(UserEntity::class)
|
||||
.query("userId == $0", userId)
|
||||
}
|
||||
|
||||
@ -16,14 +16,12 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.query
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import io.realm.kotlin.where
|
||||
import io.realm.kotlin.TypedRealm
|
||||
import io.realm.kotlin.query.RealmQuery
|
||||
import org.matrix.android.sdk.internal.database.model.presence.UserPresenceEntity
|
||||
import org.matrix.android.sdk.internal.database.model.presence.UserPresenceEntityFields
|
||||
|
||||
internal fun UserPresenceEntity.Companion.where(realm: Realm, userId: String): RealmQuery<UserPresenceEntity> {
|
||||
internal fun UserPresenceEntity.Companion.where(realm: TypedRealm, userId: String): RealmQuery<UserPresenceEntity> {
|
||||
return realm
|
||||
.where<UserPresenceEntity>()
|
||||
.equalTo(UserPresenceEntityFields.USER_ID, userId)
|
||||
.query(UserPresenceEntity::class)
|
||||
.query("userId == $0", userId)
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
package org.matrix.android.sdk.internal.session.room.summary
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.createObject
|
||||
import io.realm.kotlin.deleteFromRealm
|
||||
import kotlinx.coroutines.runBlocking
|
||||
@ -217,7 +218,7 @@ internal class RoomSummaryUpdater @Inject constructor(
|
||||
/**
|
||||
* Should be called at the end of the room sync, to check and validate all parent/child relations.
|
||||
*/
|
||||
fun validateSpaceRelationship(realm: Realm) {
|
||||
fun validateSpaceRelationship(realm: MutableRealm) {
|
||||
measureTimeMillis {
|
||||
val lookupMap = realm.where(RoomSummaryEntity::class.java)
|
||||
.process(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.activeMemberships())
|
||||
|
||||
@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.session.sync.model.RoomsSyncResponse
|
||||
import org.matrix.android.sdk.api.session.sync.model.SyncResponse
|
||||
import org.matrix.android.sdk.internal.SessionManager
|
||||
import org.matrix.android.sdk.internal.crypto.DefaultCryptoService
|
||||
import org.matrix.android.sdk.internal.database.RealmInstance
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.di.SessionId
|
||||
import org.matrix.android.sdk.internal.session.SessionListeners
|
||||
@ -40,7 +41,7 @@ import javax.inject.Inject
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
internal class SyncResponseHandler @Inject constructor(
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
@SessionDatabase private val realmInstance: RealmInstance,
|
||||
@SessionId private val sessionId: String,
|
||||
private val sessionManager: SessionManager,
|
||||
private val sessionListeners: SessionListeners,
|
||||
@ -94,13 +95,13 @@ internal class SyncResponseHandler @Inject constructor(
|
||||
// }
|
||||
|
||||
// Start one big transaction
|
||||
monarchy.awaitTransaction { realm ->
|
||||
realmInstance.write {
|
||||
// IMPORTANT nothing should be suspend here as we are accessing the realm instance (thread local)
|
||||
measureTimeMillis {
|
||||
Timber.v("Handle rooms")
|
||||
reportSubtask(reporter, InitialSyncStep.ImportingAccountRoom, 1, 0.8f) {
|
||||
if (syncResponse.rooms != null) {
|
||||
roomSyncHandler.handle(realm, syncResponse.rooms, isInitialSync, aggregator, reporter)
|
||||
roomSyncHandler.handle(this, syncResponse.rooms, isInitialSync, aggregator, reporter)
|
||||
}
|
||||
}
|
||||
}.also {
|
||||
@ -110,7 +111,7 @@ internal class SyncResponseHandler @Inject constructor(
|
||||
measureTimeMillis {
|
||||
reportSubtask(reporter, InitialSyncStep.ImportingAccountData, 1, 0.1f) {
|
||||
Timber.v("Handle accountData")
|
||||
userAccountDataSyncHandler.handle(realm, syncResponse.accountData)
|
||||
userAccountDataSyncHandler.handle(this, syncResponse.accountData)
|
||||
}
|
||||
}.also {
|
||||
Timber.v("Finish handling accountData in $it ms")
|
||||
@ -118,11 +119,11 @@ internal class SyncResponseHandler @Inject constructor(
|
||||
|
||||
measureTimeMillis {
|
||||
Timber.v("Handle Presence")
|
||||
presenceSyncHandler.handle(realm, syncResponse.presence)
|
||||
presenceSyncHandler.handle(this, syncResponse.presence)
|
||||
}.also {
|
||||
Timber.v("Finish handling Presence in $it ms")
|
||||
}
|
||||
tokenStore.saveToken(realm, syncResponse.nextBatch)
|
||||
tokenStore.saveToken(this, syncResponse.nextBatch)
|
||||
}
|
||||
|
||||
// Everything else we need to do outside the transaction
|
||||
@ -138,8 +139,8 @@ internal class SyncResponseHandler @Inject constructor(
|
||||
cryptoSyncHandler.onSyncCompleted(syncResponse)
|
||||
|
||||
// post sync stuffs
|
||||
monarchy.writeAsync {
|
||||
roomSyncHandler.postSyncSpaceHierarchyHandle(it)
|
||||
realmInstance.asyncWrite {
|
||||
roomSyncHandler.postSyncSpaceHierarchyHandle(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,25 +16,25 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.sync
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import org.matrix.android.sdk.internal.database.RealmInstance
|
||||
import org.matrix.android.sdk.internal.database.model.SyncEntity
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class SyncTokenStore @Inject constructor(@SessionDatabase private val monarchy: Monarchy) {
|
||||
internal class SyncTokenStore @Inject constructor(@SessionDatabase private val realmInstance: RealmInstance) {
|
||||
|
||||
fun getLastToken(): String? {
|
||||
val token = Realm.getInstance(monarchy.realmConfiguration).use {
|
||||
// Makes sure realm is up-to-date as it's used for querying internally on non looper thread.
|
||||
it.refresh()
|
||||
it.where(SyncEntity::class.java).findFirst()?.nextBatch
|
||||
}
|
||||
return token
|
||||
return realmInstance.getBlockingRealm()
|
||||
.query(SyncEntity::class)
|
||||
.first()
|
||||
.find()
|
||||
?.nextBatch
|
||||
}
|
||||
|
||||
fun saveToken(realm: Realm, token: String?) {
|
||||
val sync = SyncEntity(token)
|
||||
realm.insertOrUpdate(sync)
|
||||
fun saveToken(realm: MutableRealm, token: String?) {
|
||||
val sync = SyncEntity().apply { nextBatch = token }
|
||||
realm.copyToRealm(sync, updatePolicy = UpdatePolicy.ALL)
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,8 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.sync.handler
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import org.matrix.android.sdk.api.MatrixConfiguration
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.getPresenceContent
|
||||
@ -30,23 +31,21 @@ import javax.inject.Inject
|
||||
|
||||
internal class PresenceSyncHandler @Inject constructor(private val matrixConfiguration: MatrixConfiguration) {
|
||||
|
||||
fun handle(realm: Realm, presenceSyncResponse: PresenceSyncResponse?) {
|
||||
fun handle(realm: MutableRealm, presenceSyncResponse: PresenceSyncResponse?) {
|
||||
presenceSyncResponse?.events
|
||||
?.filter { event -> event.type == EventType.PRESENCE }
|
||||
?.forEach { event ->
|
||||
val content = event.getPresenceContent() ?: return@forEach
|
||||
val userId = event.senderId ?: return@forEach
|
||||
val userPresenceEntity = UserPresenceEntity(
|
||||
userId = userId,
|
||||
lastActiveAgo = content.lastActiveAgo,
|
||||
statusMessage = content.statusMessage,
|
||||
isCurrentlyActive = content.isCurrentlyActive,
|
||||
avatarUrl = content.avatarUrl,
|
||||
displayName = content.displayName
|
||||
).also {
|
||||
it.presence = content.presence
|
||||
val senderId = event.senderId ?: return@forEach
|
||||
val userPresenceEntity = UserPresenceEntity().apply {
|
||||
userId = senderId
|
||||
lastActiveAgo = content.lastActiveAgo
|
||||
statusMessage = content.statusMessage
|
||||
isCurrentlyActive = content.isCurrentlyActive
|
||||
avatarUrl = content.avatarUrl
|
||||
displayName = content.displayName
|
||||
presence = content.presence
|
||||
}
|
||||
|
||||
storePresenceToDB(realm, userPresenceEntity)
|
||||
}
|
||||
}
|
||||
@ -54,8 +53,8 @@ internal class PresenceSyncHandler @Inject constructor(private val matrixConfigu
|
||||
/**
|
||||
* Store user presence to DB and update Direct Rooms and Room Member Summaries accordingly.
|
||||
*/
|
||||
private fun storePresenceToDB(realm: Realm, userPresenceEntity: UserPresenceEntity) =
|
||||
realm.copyToRealmOrUpdate(userPresenceEntity)?.apply {
|
||||
private fun storePresenceToDB(realm: MutableRealm, userPresenceEntity: UserPresenceEntity) =
|
||||
realm.copyToRealm(userPresenceEntity, updatePolicy = UpdatePolicy.ALL)?.also {
|
||||
RoomSummaryEntity.updateDirectUserPresence(realm, userPresenceEntity.userId, this)
|
||||
RoomMemberSummaryEntity.updateUserPresence(realm, userPresenceEntity.userId, this)
|
||||
}
|
||||
|
||||
@ -16,10 +16,11 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.sync.handler
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import org.matrix.android.sdk.api.MatrixPatterns
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.session.user.model.User
|
||||
import org.matrix.android.sdk.internal.database.RealmInstance
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.session.profile.GetProfileInfoTask
|
||||
import org.matrix.android.sdk.internal.session.sync.RoomSyncEphemeralTemporaryStore
|
||||
@ -28,7 +29,6 @@ import org.matrix.android.sdk.internal.session.sync.model.accountdata.toMutable
|
||||
import org.matrix.android.sdk.internal.session.user.UserEntityFactory
|
||||
import org.matrix.android.sdk.internal.session.user.accountdata.DirectChatsHelper
|
||||
import org.matrix.android.sdk.internal.session.user.accountdata.UpdateUserAccountDataTask
|
||||
import org.matrix.android.sdk.internal.util.awaitTransaction
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class SyncResponsePostTreatmentAggregatorHandler @Inject constructor(
|
||||
@ -36,7 +36,7 @@ internal class SyncResponsePostTreatmentAggregatorHandler @Inject constructor(
|
||||
private val ephemeralTemporaryStore: RoomSyncEphemeralTemporaryStore,
|
||||
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
|
||||
private val getProfileInfoTask: GetProfileInfoTask,
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
@SessionDatabase private val realmInstance: RealmInstance,
|
||||
) {
|
||||
suspend fun handle(aggregator: SyncResponsePostTreatmentAggregator) {
|
||||
cleanupEphemeralFiles(aggregator.ephemeralFilesToDelete)
|
||||
@ -93,9 +93,11 @@ internal class SyncResponsePostTreatmentAggregatorHandler @Inject constructor(
|
||||
}
|
||||
|
||||
private suspend fun List<User>.saveLocally() {
|
||||
val userEntities = map { user -> UserEntityFactory.create(user) }
|
||||
monarchy.awaitTransaction {
|
||||
it.insertOrUpdate(userEntities)
|
||||
realmInstance.write {
|
||||
forEach { user ->
|
||||
val userEntity = UserEntityFactory.create(user)
|
||||
copyToRealm(userEntity, updatePolicy = UpdatePolicy.ALL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@ package org.matrix.android.sdk.internal.session.sync.handler
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import io.realm.kotlin.where
|
||||
import org.matrix.android.sdk.api.failure.GlobalError
|
||||
import org.matrix.android.sdk.api.failure.InitialSyncRequestReason
|
||||
@ -79,7 +81,7 @@ internal class UserAccountDataSyncHandler @Inject constructor(
|
||||
private val sessionListeners: SessionListeners
|
||||
) {
|
||||
|
||||
fun handle(realm: Realm, accountData: UserAccountDataSync?) {
|
||||
fun handle(realm: MutableRealm, accountData: UserAccountDataSync?) {
|
||||
accountData?.list?.forEach { event ->
|
||||
// Generic handling, just save in base
|
||||
handleGenericAccountData(realm, event.type, event.content)
|
||||
@ -125,49 +127,67 @@ internal class UserAccountDataSyncHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlePushRules(realm: Realm, event: UserAccountDataEvent) {
|
||||
private fun handlePushRules(realm: MutableRealm, event: UserAccountDataEvent) {
|
||||
val pushRules = event.content.toModel<GetPushRulesResponse>() ?: return
|
||||
realm.where(PushRulesEntity::class.java)
|
||||
.findAll()
|
||||
.forEach { it.deleteOnCascade() }
|
||||
realm
|
||||
.query(PushRulesEntity::class)
|
||||
.find()
|
||||
.forEach {
|
||||
//it.deleteOnCascade()
|
||||
}
|
||||
|
||||
// Save only global rules for the moment
|
||||
val globalRules = pushRules.global
|
||||
|
||||
val content = PushRulesEntity(RuleScope.GLOBAL).apply { kind = RuleSetKey.CONTENT }
|
||||
val content = PushRulesEntity().apply {
|
||||
scope = RuleScope.GLOBAL
|
||||
kind = RuleSetKey.CONTENT
|
||||
}
|
||||
globalRules.content?.forEach { rule ->
|
||||
content.pushRules.add(PushRulesMapper.map(rule))
|
||||
}
|
||||
realm.insertOrUpdate(content)
|
||||
realm.copyToRealm(content, updatePolicy = UpdatePolicy.ALL)
|
||||
|
||||
val override = PushRulesEntity(RuleScope.GLOBAL).apply { kind = RuleSetKey.OVERRIDE }
|
||||
val override = PushRulesEntity().apply {
|
||||
scope = RuleScope.GLOBAL
|
||||
kind = RuleSetKey.OVERRIDE
|
||||
}
|
||||
globalRules.override?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
override.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(override)
|
||||
realm.copyToRealm(override, updatePolicy = UpdatePolicy.ALL)
|
||||
|
||||
val rooms = PushRulesEntity(RuleScope.GLOBAL).apply { kind = RuleSetKey.ROOM }
|
||||
val rooms = PushRulesEntity().apply {
|
||||
scope = RuleScope.GLOBAL
|
||||
kind = RuleSetKey.ROOM
|
||||
}
|
||||
globalRules.room?.forEach { rule ->
|
||||
rooms.pushRules.add(PushRulesMapper.map(rule))
|
||||
}
|
||||
realm.insertOrUpdate(rooms)
|
||||
realm.copyToRealm(rooms, updatePolicy = UpdatePolicy.ALL)
|
||||
|
||||
val senders = PushRulesEntity(RuleScope.GLOBAL).apply { kind = RuleSetKey.SENDER }
|
||||
val senders = PushRulesEntity().apply {
|
||||
scope = RuleScope.GLOBAL
|
||||
kind = RuleSetKey.SENDER
|
||||
}
|
||||
globalRules.sender?.forEach { rule ->
|
||||
senders.pushRules.add(PushRulesMapper.map(rule))
|
||||
}
|
||||
realm.insertOrUpdate(senders)
|
||||
realm.copyToRealm(senders, updatePolicy = UpdatePolicy.ALL)
|
||||
|
||||
val underrides = PushRulesEntity(RuleScope.GLOBAL).apply { kind = RuleSetKey.UNDERRIDE }
|
||||
val underrides = PushRulesEntity().apply {
|
||||
scope = RuleScope.GLOBAL
|
||||
kind = RuleSetKey.UNDERRIDE
|
||||
}
|
||||
globalRules.underride?.forEach { rule ->
|
||||
underrides.pushRules.add(PushRulesMapper.map(rule))
|
||||
}
|
||||
realm.insertOrUpdate(underrides)
|
||||
realm.copyToRealm(underrides, updatePolicy = UpdatePolicy.ALL)
|
||||
}
|
||||
|
||||
private fun handleDirectChatRooms(realm: Realm, event: UserAccountDataEvent) {
|
||||
private fun handleDirectChatRooms(realm: MutableRealm, event: UserAccountDataEvent) {
|
||||
val content = event.content.toModel<DirectMessagesContent>() ?: return
|
||||
content.forEach { (userId, roomIds) ->
|
||||
roomIds.forEach { roomId ->
|
||||
@ -193,14 +213,19 @@ internal class UserAccountDataSyncHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleIgnoredUsers(realm: Realm, event: UserAccountDataEvent) {
|
||||
private fun handleIgnoredUsers(realm: MutableRealm, event: UserAccountDataEvent) {
|
||||
val userIds = event.content.toModel<IgnoredUsersContent>()?.ignoredUsers?.keys ?: return
|
||||
val currentIgnoredUsers = realm.where(IgnoredUserEntity::class.java).findAll()
|
||||
val currentIgnoredUsers = realm.query(IgnoredUserEntity::class).find()
|
||||
val currentIgnoredUserIds = currentIgnoredUsers.map { it.userId }
|
||||
// Delete the previous list
|
||||
currentIgnoredUsers.deleteAllFromRealm()
|
||||
realm.delete(currentIgnoredUsers)
|
||||
// And save the new received list
|
||||
userIds.forEach { realm.createObject(IgnoredUserEntity::class.java).apply { userId = it } }
|
||||
userIds.forEach {
|
||||
val ignoredUserEntity = IgnoredUserEntity().apply {
|
||||
userId = it
|
||||
}
|
||||
realm.copyToRealm(ignoredUserEntity)
|
||||
}
|
||||
|
||||
// Delete all the TimelineEvents for all the ignored users
|
||||
// See https://spec.matrix.org/latest/client-server-api/#client-behaviour-22 :
|
||||
@ -227,7 +252,7 @@ internal class UserAccountDataSyncHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleBreadcrumbs(realm: Realm, event: UserAccountDataEvent) {
|
||||
private fun handleBreadcrumbs(realm: MutableRealm, event: UserAccountDataEvent) {
|
||||
val recentRoomIds = event.content.toModel<BreadcrumbsContent>()?.recentRoomIds ?: return
|
||||
val entity = BreadcrumbsEntity.getOrCreate(realm)
|
||||
|
||||
@ -251,7 +276,7 @@ internal class UserAccountDataSyncHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun handleGenericAccountData(realm: Realm, type: String, content: Content?) {
|
||||
fun handleGenericAccountData(realm: MutableRealm, type: String, content: Content?) {
|
||||
val existing = realm.where<UserAccountDataEntity>()
|
||||
.equalTo(UserAccountDataEntityFields.TYPE, type)
|
||||
.findFirst()
|
||||
|
||||
@ -16,12 +16,14 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.sync.handler.room
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.internal.database.model.ReadReceiptEntity
|
||||
import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.query.createUnmanaged
|
||||
import org.matrix.android.sdk.internal.database.query.getOrCreate
|
||||
import org.matrix.android.sdk.internal.database.query.readReceiptSummaryEntityQueries
|
||||
import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.session.sync.RoomSyncEphemeralTemporaryStore
|
||||
import org.matrix.android.sdk.internal.session.sync.SyncResponsePostTreatmentAggregator
|
||||
@ -62,7 +64,7 @@ internal class ReadReceiptHandler @Inject constructor(
|
||||
}
|
||||
|
||||
fun handle(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
content: ReadReceiptContent?,
|
||||
isInitialSync: Boolean,
|
||||
@ -78,7 +80,7 @@ internal class ReadReceiptHandler @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleReadReceiptContent(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
content: ReadReceiptContent,
|
||||
isInitialSync: Boolean,
|
||||
@ -91,24 +93,29 @@ internal class ReadReceiptHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun initialSyncStrategy(realm: Realm, roomId: String, content: ReadReceiptContent) {
|
||||
val readReceiptSummaries = ArrayList<ReadReceiptsSummaryEntity>()
|
||||
private fun initialSyncStrategy(realm: MutableRealm, roomId: String, content: ReadReceiptContent) {
|
||||
for ((eventId, receiptDict) in content) {
|
||||
val userIdsDict = receiptDict[READ_KEY] ?: continue
|
||||
val readReceiptsSummary = ReadReceiptsSummaryEntity(eventId = eventId, roomId = roomId)
|
||||
|
||||
val readReceiptsSummary = ReadReceiptsSummaryEntity().apply {
|
||||
this.eventId = eventId
|
||||
this.roomId = roomId
|
||||
}
|
||||
for ((userId, paramsDict) in userIdsDict) {
|
||||
val ts = paramsDict[TIMESTAMP_KEY] ?: 0.0
|
||||
val receiptEntity = ReadReceiptEntity.createUnmanaged(roomId, eventId, userId, ts)
|
||||
val receiptEntity = ReadReceiptEntity().apply {
|
||||
this.roomId = roomId
|
||||
this.eventId = eventId
|
||||
this.userId = userId
|
||||
this.originServerTs = ts
|
||||
}
|
||||
readReceiptsSummary.readReceipts.add(receiptEntity)
|
||||
}
|
||||
readReceiptSummaries.add(readReceiptsSummary)
|
||||
realm.copyToRealm(readReceiptsSummary, updatePolicy = UpdatePolicy.ALL)
|
||||
}
|
||||
realm.insertOrUpdate(readReceiptSummaries)
|
||||
}
|
||||
|
||||
private fun incrementalSyncStrategy(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
content: ReadReceiptContent,
|
||||
aggregator: SyncResponsePostTreatmentAggregator?
|
||||
@ -123,10 +130,10 @@ internal class ReadReceiptHandler @Inject constructor(
|
||||
doIncrementalSyncStrategy(realm, roomId, content)
|
||||
}
|
||||
|
||||
private fun doIncrementalSyncStrategy(realm: Realm, roomId: String, content: ReadReceiptContent) {
|
||||
private fun doIncrementalSyncStrategy(realm: MutableRealm, roomId: String, content: ReadReceiptContent) {
|
||||
for ((eventId, receiptDict) in content) {
|
||||
val userIdsDict = receiptDict[READ_KEY] ?: continue
|
||||
val readReceiptsSummary = ReadReceiptsSummaryEntity.where(realm, eventId).findFirst()
|
||||
val readReceiptsSummary = ReadReceiptsSummaryEntity.where(realm, eventId).find()
|
||||
?: realm.createObject(ReadReceiptsSummaryEntity::class.java, eventId).apply {
|
||||
this.roomId = roomId
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
package org.matrix.android.sdk.internal.session.sync.handler.room
|
||||
|
||||
import dagger.Lazy
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.MutableRealm
|
||||
import io.realm.kotlin.createObject
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
||||
@ -108,7 +108,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
}
|
||||
|
||||
fun handle(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomsSyncResponse: RoomsSyncResponse,
|
||||
isInitialSync: Boolean,
|
||||
aggregator: SyncResponsePostTreatmentAggregator,
|
||||
@ -122,13 +122,13 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
// roomSummaryUpdater.validateSpaceRelationship(realm)
|
||||
}
|
||||
|
||||
fun postSyncSpaceHierarchyHandle(realm: Realm) {
|
||||
fun postSyncSpaceHierarchyHandle(realm: MutableRealm) {
|
||||
roomSummaryUpdater.validateSpaceRelationship(realm)
|
||||
}
|
||||
// PRIVATE METHODS *****************************************************************************
|
||||
|
||||
private fun handleRoomSync(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
handlingStrategy: HandlingStrategy,
|
||||
isInitialSync: Boolean,
|
||||
aggregator: SyncResponsePostTreatmentAggregator,
|
||||
@ -140,7 +140,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
EventInsertType.INCREMENTAL_SYNC
|
||||
}
|
||||
val syncLocalTimeStampMillis = clock.epochMillis()
|
||||
val rooms = when (handlingStrategy) {
|
||||
when (handlingStrategy) {
|
||||
is HandlingStrategy.JOINED -> {
|
||||
if (isInitialSync && initialSyncStrategy is InitialSyncStrategy.Optimized) {
|
||||
insertJoinRoomsFromInitSync(realm, handlingStrategy, syncLocalTimeStampMillis, aggregator, reporter)
|
||||
@ -163,11 +163,10 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(rooms)
|
||||
}
|
||||
|
||||
private fun insertJoinRoomsFromInitSync(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
handlingStrategy: HandlingStrategy.JOINED,
|
||||
syncLocalTimeStampMillis: Long,
|
||||
aggregator: SyncResponsePostTreatmentAggregator,
|
||||
@ -211,7 +210,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleJoinedRoom(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
roomSync: RoomSync,
|
||||
insertType: EventInsertType,
|
||||
@ -291,7 +290,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleInvitedRoom(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
roomSync: InvitedRoomSync,
|
||||
insertType: EventInsertType,
|
||||
@ -324,7 +323,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleLeftRoom(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
roomSync: RoomSync,
|
||||
insertType: EventInsertType,
|
||||
@ -371,7 +370,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleTimelineEvents(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
roomEntity: RoomEntity,
|
||||
eventList: List<Event>,
|
||||
@ -519,7 +518,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
* the thread timeline and /relations api, we should not added it
|
||||
*/
|
||||
private fun addToThreadChunkIfNeeded(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
threadId: String,
|
||||
timelineEventEntity: TimelineEventEntity?,
|
||||
@ -567,7 +566,7 @@ internal class RoomSyncHandler @Inject constructor(
|
||||
)
|
||||
|
||||
private fun handleEphemeral(
|
||||
realm: Realm,
|
||||
realm: MutableRealm,
|
||||
roomId: String,
|
||||
ephemeralEvents: List<Event>,
|
||||
isInitialSync: Boolean,
|
||||
|
||||
@ -151,8 +151,12 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
|
||||
ignored.find {
|
||||
it.userId == initialState.userId
|
||||
} != null
|
||||
}
|
||||
.map {
|
||||
|
||||
}
|
||||
.execute {
|
||||
it
|
||||
copy(isIgnored = it)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user