Delete messages from just ignored users from our database (#1899)

This commit is contained in:
Benoit Marty 2022-04-15 10:57:04 +02:00
parent ff28cb4349
commit 6ed1516d90

View file

@ -39,6 +39,8 @@ import org.matrix.android.sdk.internal.database.model.IgnoredUserEntity
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
@ -189,7 +191,19 @@ internal class UserAccountDataSyncHandler @Inject constructor(
.deleteAllFromRealm()
// And save the new received list
userIds.forEach { realm.createObject(IgnoredUserEntity::class.java).apply { userId = it } }
// TODO If not initial sync, we should execute a init sync
// Delete all the TimelineEvents for all the ignored users
// 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()
.also { Timber.d("Deleting ${it.size} TimelineEventEntity from ignored users") }
.forEach {
it.deleteOnCascade(true)
}
}
private fun handleBreadcrumbs(realm: Realm, event: UserAccountDataEvent) {