Move code to TimelineEventEntityQueries.kt (#5810)

This commit is contained in:
Benoit Marty 2022-04-21 14:27:17 +02:00
parent aebdee1070
commit 7f09a37503
2 changed files with 13 additions and 5 deletions

View File

@ -132,3 +132,14 @@ internal fun RealmQuery<TimelineEventEntity>.filterSendStates(sendStates: List<S
val sendStatesStr = sendStates.map { it.name }.toTypedArray()
return `in`(TimelineEventEntityFields.ROOT.SEND_STATE_STR, sendStatesStr)
}
/**
* Find all TimelineEventEntity items where sender is in senderIds collection, excluding state events
*/
internal fun TimelineEventEntity.Companion.findAllFrom(realm: Realm,
senderIds: Collection<String>): RealmResults<TimelineEventEntity> {
return realm.where(TimelineEventEntity::class.java)
.`in`(TimelineEventEntityFields.ROOT.SENDER, senderIds.toTypedArray())
.isNull(TimelineEventEntityFields.ROOT.STATE_KEY)
.findAll()
}

View File

@ -43,10 +43,10 @@ import org.matrix.android.sdk.internal.database.model.PushRulesEntity
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
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.model.UserAccountDataEntity
import org.matrix.android.sdk.internal.database.model.UserAccountDataEntityFields
import org.matrix.android.sdk.internal.database.model.deleteOnCascade
import org.matrix.android.sdk.internal.database.query.findAllFrom
import org.matrix.android.sdk.internal.database.query.getDirectRooms
import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.database.query.where
@ -206,10 +206,7 @@ internal class UserAccountDataSyncHandler @Inject constructor(
// See https://spec.matrix.org/latest/client-server-api/#client-behaviour-22 :
// "Once ignored, the client will no longer receive events sent by that user, with the exception of state events"
// So just delete all non-state events from our local storage.
realm.where(TimelineEventEntity::class.java)
.`in`(TimelineEventEntityFields.ROOT.SENDER, userIds.toTypedArray())
.isNull(TimelineEventEntityFields.ROOT.STATE_KEY)
.findAll()
TimelineEventEntity.findAllFrom(realm, userIds)
.also { Timber.d("Deleting ${it.size} TimelineEventEntity from ignored users") }
.forEach {
it.deleteOnCascade(true)