From cfdfd3a8af11974a379676f6156b40acf1878aec Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 2 Feb 2021 21:22:54 +0100 Subject: [PATCH 01/15] internal --- .../sdk/internal/crypto/crosssigning/Extensions.kt | 6 +++--- .../sdk/internal/crypto/model/CryptoCrossSigningKey.kt | 4 ++-- .../org/matrix/android/sdk/internal/crypto/tools/Tools.kt | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/Extensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/Extensions.kt index e494cb5b31..cf2d6aa269 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/Extensions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/Extensions.kt @@ -21,11 +21,11 @@ import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.internal.util.JsonCanonicalizer import timber.log.Timber -fun CryptoDeviceInfo.canonicalSignable(): String { +internal fun CryptoDeviceInfo.canonicalSignable(): String { return JsonCanonicalizer.getCanonicalJson(Map::class.java, signalableJSONDictionary()) } -fun CryptoCrossSigningKey.canonicalSignable(): String { +internal fun CryptoCrossSigningKey.canonicalSignable(): String { return JsonCanonicalizer.getCanonicalJson(Map::class.java, signalableJSONDictionary()) } @@ -40,7 +40,7 @@ fun String.fromBase64(): ByteArray { /** * Decode the base 64. Return null in case of bad format. Should be used when parsing received data from external source */ -fun String.fromBase64Safe(): ByteArray? { +internal fun String.fromBase64Safe(): ByteArray? { return try { Base64.decode(this, Base64.DEFAULT) } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/CryptoCrossSigningKey.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/CryptoCrossSigningKey.kt index 202aa55624..606d2e3fc0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/CryptoCrossSigningKey.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/CryptoCrossSigningKey.kt @@ -63,7 +63,7 @@ data class CryptoCrossSigningKey( ) } - data class Builder( + internal data class Builder( val userId: String, val usage: KeyUsage, private var base64Pkey: String? = null, @@ -97,7 +97,7 @@ data class CryptoCrossSigningKey( } } -enum class KeyUsage(val value: String) { +internal enum class KeyUsage(val value: String) { MASTER("master"), SELF_SIGNING("self_signing"), USER_SIGNING("user_signing") diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tools/Tools.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tools/Tools.kt index 4c1e896a21..052b3f4e72 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tools/Tools.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tools/Tools.kt @@ -21,7 +21,7 @@ import org.matrix.olm.OlmPkEncryption import org.matrix.olm.OlmPkSigning import org.matrix.olm.OlmUtility -fun withOlmEncryption(block: (OlmPkEncryption) -> T): T { +internal fun withOlmEncryption(block: (OlmPkEncryption) -> T): T { val olmPkEncryption = OlmPkEncryption() try { return block(olmPkEncryption) @@ -30,7 +30,7 @@ fun withOlmEncryption(block: (OlmPkEncryption) -> T): T { } } -fun withOlmDecryption(block: (OlmPkDecryption) -> T): T { +internal fun withOlmDecryption(block: (OlmPkDecryption) -> T): T { val olmPkDecryption = OlmPkDecryption() try { return block(olmPkDecryption) @@ -39,7 +39,7 @@ fun withOlmDecryption(block: (OlmPkDecryption) -> T): T { } } -fun withOlmSigning(block: (OlmPkSigning) -> T): T { +internal fun withOlmSigning(block: (OlmPkSigning) -> T): T { val olmPkSigning = OlmPkSigning() try { return block(olmPkSigning) @@ -48,7 +48,7 @@ fun withOlmSigning(block: (OlmPkSigning) -> T): T { } } -fun withOlmUtility(block: (OlmUtility) -> T): T { +internal fun withOlmUtility(block: (OlmUtility) -> T): T { val olmUtility = OlmUtility() try { return block(olmUtility) From 3b65761110996b97f5e3957849b52d66d68b270d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 2 Feb 2021 21:23:16 +0100 Subject: [PATCH 02/15] Delete on cascade --- CHANGES.md | 1 + .../crypto/store/db/RealmCryptoStore.kt | 8 +++++--- .../store/db/model/CrossSigningInfoEntity.kt | 7 ++++++- .../crypto/store/db/model/DeviceInfoEntity.kt | 5 +++++ .../crypto/store/db/model/KeyInfoEntity.kt | 8 +++++++- .../crypto/store/db/model/UserEntity.kt | 10 ++++++++-- .../store/db/query/UserEntitiesQueries.kt | 6 +++--- .../sdk/internal/database/DatabaseCleaner.kt | 17 ++--------------- .../database/helper/ChunkEntityHelper.kt | 6 ------ .../database/helper/RoomEntityHelper.kt | 7 +------ .../helper/TimelineEventEntityHelper.kt | 9 --------- .../sdk/internal/database/model/ChunkEntity.kt | 10 ++++++++++ .../model/EventAnnotationsSummaryEntity.kt | 8 ++++++++ .../internal/database/model/PushRuleEntity.kt | 5 +++++ .../internal/database/model/PushRulesEntity.kt | 5 +++++ .../sdk/internal/database/model/PusherEntity.kt | 7 ++++++- .../database/model/ReadReceiptsSummaryEntity.kt | 5 +++++ .../database/model/TimelineEventEntity.kt | 11 +++++++++++ .../internal/session/pushers/GetPushersTask.kt | 3 ++- .../session/pushers/SavePushRulesTask.kt | 2 +- .../room/timeline/TokenChunkEventPersistor.kt | 9 ++++----- .../internal/session/sync/RoomSyncHandler.kt | 10 +++++----- .../session/sync/UserAccountDataSyncHandler.kt | 2 +- 23 files changed, 101 insertions(+), 60 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index fcf6659d92..9c72ff3574 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Bugfix 🐛: - Widgets: Support $matrix_widget_id parameter (#2748) - Data for Worker overload (#2721) - Fix multiple tasks + - Object deletion in database is not complete (#2759) Translations 🗣: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt index 369a4976c9..8dbccb061b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt @@ -293,7 +293,8 @@ internal class RealmCryptoStore @Inject constructor( realm.insertOrUpdate(entity) } // Ensure all other devices are deleted - u.devices.deleteAllFromRealm() + u.devices.toList().forEach { it.deleteOnCascade() } + u.devices.clear() u.devices.addAll(new) } } @@ -309,7 +310,7 @@ internal class RealmCryptoStore @Inject constructor( .let { userEntity -> if (masterKey == null || selfSigningKey == null) { // The user has disabled cross signing? - userEntity.crossSigningInfoEntity?.deleteFromRealm() + userEntity.crossSigningInfoEntity?.deleteOnCascade() userEntity.crossSigningInfoEntity = null } else { var shouldResetMyDevicesLocalTrust = false @@ -1633,7 +1634,8 @@ internal class RealmCryptoStore @Inject constructor( } else { // Just override existing, caller should check and untrust id needed val existing = CrossSigningInfoEntity.getOrCreate(realm, userId) - existing.crossSigningKeys.deleteAllFromRealm() + existing.crossSigningKeys.toList().forEach { it.deleteOnCascade() } + existing.crossSigningKeys.clear() existing.crossSigningKeys.addAll( info.crossSigningKeys.map { crossSigningKeysMapper.map(it) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt index fdd3e94754..5a14ede0ad 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt @@ -16,10 +16,10 @@ package org.matrix.android.sdk.internal.crypto.store.db.model -import org.matrix.android.sdk.internal.crypto.model.KeyUsage import io.realm.RealmList import io.realm.RealmObject import io.realm.annotations.PrimaryKey +import org.matrix.android.sdk.internal.crypto.model.KeyUsage internal open class CrossSigningInfoEntity( @PrimaryKey @@ -29,6 +29,11 @@ internal open class CrossSigningInfoEntity( companion object + fun deleteOnCascade() { + crossSigningKeys.toList().forEach { it.deleteOnCascade() } + deleteFromRealm() + } + fun getMasterKey() = crossSigningKeys.firstOrNull { it.usages.contains(KeyUsage.MASTER.value) } fun setMasterKey(info: KeyInfoEntity?) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt index 571b9bb05f..eddf0b81c6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt @@ -46,4 +46,9 @@ internal open class DeviceInfoEntity( val users: RealmResults? = null companion object + + fun deleteOnCascade() { + trustLevelEntity?.deleteFromRealm() + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt index 8f2357223e..527adaf847 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt @@ -29,4 +29,10 @@ internal open class KeyInfoEntity( */ var signatures: String? = null, var trustLevelEntity: TrustLevelEntity? = null -) : RealmObject() +) : RealmObject() { + + fun deleteOnCascade() { + trustLevelEntity?.deleteFromRealm() + deleteFromRealm() + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt index 52c30a27cc..a5336ea848 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt @@ -24,8 +24,14 @@ internal open class UserEntity( @PrimaryKey var userId: String? = null, var devices: RealmList = RealmList(), var crossSigningInfoEntity: CrossSigningInfoEntity? = null, - var deviceTrackingStatus: Int = 0) - : RealmObject() { + var deviceTrackingStatus: Int = 0 +) : RealmObject() { companion object + + fun deleteOnCascade() { + devices.toList().forEach { it.deleteOnCascade() } + crossSigningInfoEntity?.deleteOnCascade() + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt index a1f8bd7262..4db03e123e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt @@ -16,11 +16,11 @@ package org.matrix.android.sdk.internal.crypto.store.db.query -import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity -import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntityFields import io.realm.Realm import io.realm.kotlin.createObject import io.realm.kotlin.where +import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity +import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntityFields /** * Get or create a user @@ -39,5 +39,5 @@ internal fun UserEntity.Companion.delete(realm: Realm, userId: String) { realm.where() .equalTo(UserEntityFields.USER_ID, userId) .findFirst() - ?.deleteFromRealm() + ?.deleteOnCascade() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt index e305c7ea38..e780702229 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt @@ -56,7 +56,7 @@ internal class DatabaseCleaner @Inject constructor(@SessionDatabase private val } } - private suspend fun cleanUp(realm: Realm, threshold: Long) { + private fun cleanUp(realm: Realm, threshold: Long) { val numberOfEvents = realm.where(EventEntity::class.java).findAll().size val numberOfTimelineEvents = realm.where(TimelineEventEntity::class.java).findAll().size Timber.v("Number of events in db: $numberOfEvents | Number of timeline events in db: $numberOfTimelineEvents") @@ -76,20 +76,7 @@ internal class DatabaseCleaner @Inject constructor(@SessionDatabase private val chunk.numberOfTimelineEvents = chunk.numberOfTimelineEvents - eventsToRemove.size eventsToRemove.forEach { val canDeleteRoot = it.root?.stateKey == null - if (canDeleteRoot) { - it.root?.deleteFromRealm() - } - it.readReceipts?.readReceipts?.deleteAllFromRealm() - it.readReceipts?.deleteFromRealm() - it.annotations?.apply { - editSummary?.deleteFromRealm() - pollResponseSummary?.deleteFromRealm() - referencesSummaryEntity?.deleteFromRealm() - reactionsSummary.deleteAllFromRealm() - } - it.annotations?.deleteFromRealm() - it.readReceipts?.deleteFromRealm() - it.deleteFromRealm() + it.deleteOnCascade(canDeleteRoot) } // We reset the prevToken so we will need to fetch again. chunk.prevToken = null diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt index f764c4da4b..b4935cfdcc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt @@ -38,12 +38,6 @@ import io.realm.Sort import io.realm.kotlin.createObject import timber.log.Timber -internal fun ChunkEntity.deleteOnCascade() { - assertIsManaged() - this.timelineEvents.deleteAllFromRealm() - this.deleteFromRealm() -} - internal fun ChunkEntity.merge(roomId: String, chunkToMerge: ChunkEntity, direction: PaginationDirection) { assertIsManaged() val localRealm = this.realm diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/RoomEntityHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/RoomEntityHelper.kt index a4108f0966..724f307e3b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/RoomEntityHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/RoomEntityHelper.kt @@ -19,12 +19,7 @@ package org.matrix.android.sdk.internal.database.helper import org.matrix.android.sdk.internal.database.model.ChunkEntity import org.matrix.android.sdk.internal.database.model.RoomEntity -internal fun RoomEntity.deleteOnCascade(chunkEntity: ChunkEntity) { - chunks.remove(chunkEntity) - chunkEntity.deleteOnCascade() -} - -internal fun RoomEntity.addOrUpdate(chunkEntity: ChunkEntity) { +internal fun RoomEntity.addIfNecessary(chunkEntity: ChunkEntity) { if (!chunks.contains(chunkEntity)) { chunks.add(chunkEntity) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/TimelineEventEntityHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/TimelineEventEntityHelper.kt index 6f4dac182c..90e867749e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/TimelineEventEntityHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/TimelineEventEntityHelper.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.database.helper import org.matrix.android.sdk.internal.database.model.TimelineEventEntity import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields -import org.matrix.android.sdk.internal.extensions.assertIsManaged import io.realm.Realm internal fun TimelineEventEntity.Companion.nextId(realm: Realm): Long { @@ -29,11 +28,3 @@ internal fun TimelineEventEntity.Companion.nextId(realm: Realm): Long { currentIdNum.toLong() + 1 } } - -internal fun TimelineEventEntity.deleteOnCascade() { - assertIsManaged() - root?.deleteFromRealm() - annotations?.deleteFromRealm() - readReceipts?.deleteFromRealm() - deleteFromRealm() -} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt index 9770352a95..de7333bef2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt @@ -21,6 +21,7 @@ import io.realm.RealmObject import io.realm.RealmResults import io.realm.annotations.Index import io.realm.annotations.LinkingObjects +import org.matrix.android.sdk.internal.extensions.assertIsManaged internal open class ChunkEntity(@Index var prevToken: String? = null, // Because of gaps we can have several chunks with nextToken == null @@ -42,4 +43,13 @@ internal open class ChunkEntity(@Index var prevToken: String? = null, val room: RealmResults? = null companion object + + fun deleteOnCascade(deleteStateEvents: Boolean, canDeleteRoot: Boolean) { + assertIsManaged() + if (deleteStateEvents) { + stateEvents.deleteAllFromRealm() + } + timelineEvents.forEach { it.deleteOnCascade(canDeleteRoot) } + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt index 3e5e277613..4caf6bdd0d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt @@ -30,4 +30,12 @@ internal open class EventAnnotationsSummaryEntity( ) : RealmObject() { companion object + + fun deleteOnCascade() { + reactionsSummary.deleteAllFromRealm() + editSummary?.deleteFromRealm() + referencesSummaryEntity?.deleteFromRealm() + pollResponseSummary?.deleteFromRealm() + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt index 85375c8064..2a24208d97 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt @@ -39,4 +39,9 @@ internal open class PushRuleEntity( val parent: RealmResults? = null companion object + + fun deleteOnCascade() { + conditions?.forEach { it.deleteFromRealm() } + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt index 21e3510cd2..52fd97b408 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt @@ -34,4 +34,9 @@ internal open class PushRulesEntity( } companion object + + fun deleteOnCascade() { + pushRules.toList().forEach { it.deleteOnCascade() } + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt index f85c01c48a..e4fb474599 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt @@ -15,8 +15,8 @@ */ package org.matrix.android.sdk.internal.database.model -import org.matrix.android.sdk.api.session.pushers.PusherState import io.realm.RealmObject +import org.matrix.android.sdk.api.session.pushers.PusherState // TODO // at java.lang.Thread.run(Thread.java:764) @@ -53,4 +53,9 @@ internal open class PusherEntity( } companion object + + fun deleteOnCascade() { + data?.deleteFromRealm() + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt index 98b4329076..a3693720e4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt @@ -33,4 +33,9 @@ internal open class ReadReceiptsSummaryEntity( val timelineEvent: RealmResults? = null companion object + + fun deleteOnCascade() { + readReceipts.deleteAllFromRealm() + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt index 7bd0dbbb8f..fbafb9c5eb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt @@ -20,6 +20,7 @@ import io.realm.RealmObject import io.realm.RealmResults import io.realm.annotations.Index import io.realm.annotations.LinkingObjects +import org.matrix.android.sdk.internal.extensions.assertIsManaged internal open class TimelineEventEntity(var localId: Long = 0, @Index var eventId: String = "", @@ -38,4 +39,14 @@ internal open class TimelineEventEntity(var localId: Long = 0, val chunk: RealmResults? = null companion object + + fun deleteOnCascade(canDeleteRoot: Boolean) { + assertIsManaged() + if (canDeleteRoot) { + root?.deleteFromRealm() + } + annotations?.deleteOnCascade() + readReceipts?.deleteOnCascade() + deleteFromRealm() + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt index 4c7d370446..b66e04b4cd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt @@ -41,7 +41,8 @@ internal class DefaultGetPushersTask @Inject constructor( monarchy.awaitTransaction { realm -> // clear existings? realm.where(PusherEntity::class.java) - .findAll().deleteAllFromRealm() + .findAll() + .forEach { it.deleteOnCascade() } response.pushers?.forEach { jsonPusher -> jsonPusher.toEntity().also { it.state = PusherState.REGISTERED diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt index 6ba769a3b7..fd433c0803 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt @@ -40,7 +40,7 @@ internal class DefaultSavePushRulesTask @Inject constructor(@SessionDatabase pri // clear current push rules realm.where(PushRulesEntity::class.java) .findAll() - .deleteAllFromRealm() + .forEach { it.deleteOnCascade() } // Save only global rules for the moment val globalRules = params.pushRules.global diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt index 1a497b8835..19572edc80 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt @@ -22,10 +22,9 @@ import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.RoomMemberContent import org.matrix.android.sdk.api.session.room.send.SendState -import org.matrix.android.sdk.internal.database.helper.addOrUpdate +import org.matrix.android.sdk.internal.database.helper.addIfNecessary import org.matrix.android.sdk.internal.database.helper.addStateEvent import org.matrix.android.sdk.internal.database.helper.addTimelineEvent -import org.matrix.android.sdk.internal.database.helper.deleteOnCascade import org.matrix.android.sdk.internal.database.helper.merge import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.model.ChunkEntity @@ -172,7 +171,7 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri val currentLastForwardChunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomId) if (currentChunk != currentLastForwardChunk) { currentChunk.isLastForward = true - currentLastForwardChunk?.deleteOnCascade() + currentLastForwardChunk?.deleteOnCascade(deleteStateEvents = false, canDeleteRoot = false) RoomSummaryEntity.where(realm, roomId).findFirst()?.apply { latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId) } @@ -235,7 +234,7 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri } } chunksToDelete.forEach { - it.deleteOnCascade() + it.deleteOnCascade(deleteStateEvents = false, canDeleteRoot = false) } val roomSummaryEntity = RoomSummaryEntity.getOrCreate(realm, roomId) val shouldUpdateSummary = roomSummaryEntity.latestPreviewableEvent == null @@ -244,7 +243,7 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri roomSummaryEntity.latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId) } if (currentChunk.isValid) { - RoomEntity.where(realm, roomId).findFirst()?.addOrUpdate(currentChunk) + RoomEntity.where(realm, roomId).findFirst()?.addIfNecessary(currentChunk) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt index 456b0f9c26..4fb7708ed1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt @@ -30,9 +30,8 @@ import org.matrix.android.sdk.api.session.room.send.SendState import org.matrix.android.sdk.internal.crypto.DefaultCryptoService import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult -import org.matrix.android.sdk.internal.database.helper.addOrUpdate +import org.matrix.android.sdk.internal.database.helper.addIfNecessary import org.matrix.android.sdk.internal.database.helper.addTimelineEvent -import org.matrix.android.sdk.internal.database.helper.deleteOnCascade import org.matrix.android.sdk.internal.database.mapper.asDomain import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.model.ChunkEntity @@ -175,7 +174,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle syncLocalTimestampMillis, isInitialSync ) - roomEntity.addOrUpdate(chunkEntity) + roomEntity.addIfNecessary(chunkEntity) } val hasRoomMember = roomSync.state?.events?.firstOrNull { it.type == EventType.STATE_ROOM_MEMBER @@ -263,7 +262,8 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle val leftMember = RoomMemberSummaryEntity.where(realm, roomId, userId).findFirst() val membership = leftMember?.membership ?: Membership.LEAVE roomEntity.membership = membership - roomEntity.chunks.deleteAllFromRealm() + roomEntity.chunks.forEach { it.deleteOnCascade(deleteStateEvents = true, canDeleteRoot = true) } + roomEntity.chunks.clear() roomTypingUsersHandler.handle(realm, roomId, null) roomChangeMembershipStateDataSource.setMembershipFromSync(roomId, Membership.LEAVE) roomSummaryUpdater.update(realm, roomId, membership, roomSync.summary, roomSync.unreadNotifications) @@ -340,7 +340,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle } } // Finally delete the local echo - sendingEventEntity.deleteOnCascade() + sendingEventEntity.deleteOnCascade(true) } else { Timber.v("Can't find corresponding local echo for tx:$it") } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt index 0e549172f3..880dbdcb88 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt @@ -113,7 +113,7 @@ internal class UserAccountDataSyncHandler @Inject constructor( val pushRules = event.content.toModel() ?: return realm.where(PushRulesEntity::class.java) .findAll() - .deleteAllFromRealm() + .forEach { it.deleteOnCascade() } // Save only global rules for the moment val globalRules = pushRules.global From 424035f56f3014686feff8a7ee6177ecd7af126b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 3 Feb 2021 09:07:41 +0100 Subject: [PATCH 03/15] Better clearing of RealmLists --- .../sdk/internal/crypto/store/db/RealmCryptoStore.kt | 7 +++---- .../crypto/store/db/model/CrossSigningInfoEntity.kt | 3 ++- .../sdk/internal/crypto/store/db/model/UserEntity.kt | 3 ++- .../android/sdk/internal/database/model/ChunkEntity.kt | 3 ++- .../sdk/internal/database/model/PushRuleEntity.kt | 2 +- .../sdk/internal/database/model/PushRulesEntity.kt | 3 ++- .../android/sdk/internal/extensions/RealmExtensions.kt | 10 ++++++++++ .../sdk/internal/session/sync/RoomSyncHandler.kt | 4 ++-- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt index 8dbccb061b..bb14180baa 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt @@ -94,6 +94,7 @@ import org.matrix.android.sdk.internal.di.CryptoDatabase import org.matrix.android.sdk.internal.di.DeviceId import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.extensions.clearWith import org.matrix.android.sdk.internal.session.SessionScope import org.matrix.olm.OlmAccount import org.matrix.olm.OlmException @@ -293,8 +294,7 @@ internal class RealmCryptoStore @Inject constructor( realm.insertOrUpdate(entity) } // Ensure all other devices are deleted - u.devices.toList().forEach { it.deleteOnCascade() } - u.devices.clear() + u.devices.clearWith { it.deleteOnCascade() } u.devices.addAll(new) } } @@ -1634,8 +1634,7 @@ internal class RealmCryptoStore @Inject constructor( } else { // Just override existing, caller should check and untrust id needed val existing = CrossSigningInfoEntity.getOrCreate(realm, userId) - existing.crossSigningKeys.toList().forEach { it.deleteOnCascade() } - existing.crossSigningKeys.clear() + existing.crossSigningKeys.clearWith { it.deleteOnCascade() } existing.crossSigningKeys.addAll( info.crossSigningKeys.map { crossSigningKeysMapper.map(it) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt index 5a14ede0ad..2d91c32d90 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt @@ -20,6 +20,7 @@ import io.realm.RealmList import io.realm.RealmObject import io.realm.annotations.PrimaryKey import org.matrix.android.sdk.internal.crypto.model.KeyUsage +import org.matrix.android.sdk.internal.extensions.clearWith internal open class CrossSigningInfoEntity( @PrimaryKey @@ -30,7 +31,7 @@ internal open class CrossSigningInfoEntity( companion object fun deleteOnCascade() { - crossSigningKeys.toList().forEach { it.deleteOnCascade() } + crossSigningKeys.clearWith { it.deleteOnCascade() } deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt index a5336ea848..a815efd8cb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt @@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.crypto.store.db.model import io.realm.RealmList import io.realm.RealmObject import io.realm.annotations.PrimaryKey +import org.matrix.android.sdk.internal.extensions.clearWith internal open class UserEntity( @PrimaryKey var userId: String? = null, @@ -30,7 +31,7 @@ internal open class UserEntity( companion object fun deleteOnCascade() { - devices.toList().forEach { it.deleteOnCascade() } + devices.clearWith { it.deleteOnCascade() } crossSigningInfoEntity?.deleteOnCascade() deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt index de7333bef2..567cb3ca32 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt @@ -22,6 +22,7 @@ import io.realm.RealmResults import io.realm.annotations.Index import io.realm.annotations.LinkingObjects import org.matrix.android.sdk.internal.extensions.assertIsManaged +import org.matrix.android.sdk.internal.extensions.clearWith internal open class ChunkEntity(@Index var prevToken: String? = null, // Because of gaps we can have several chunks with nextToken == null @@ -49,7 +50,7 @@ internal open class ChunkEntity(@Index var prevToken: String? = null, if (deleteStateEvents) { stateEvents.deleteAllFromRealm() } - timelineEvents.forEach { it.deleteOnCascade(canDeleteRoot) } + timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) } deleteFromRealm() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt index 2a24208d97..cf824ba85d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt @@ -41,7 +41,7 @@ internal open class PushRuleEntity( companion object fun deleteOnCascade() { - conditions?.forEach { it.deleteFromRealm() } + conditions?.deleteAllFromRealm() deleteFromRealm() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt index 52fd97b408..3728856663 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt @@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.database.model import org.matrix.android.sdk.api.pushrules.RuleKind import io.realm.RealmList import io.realm.RealmObject +import org.matrix.android.sdk.internal.extensions.clearWith internal open class PushRulesEntity( var scope: String = "", @@ -36,7 +37,7 @@ internal open class PushRulesEntity( companion object fun deleteOnCascade() { - pushRules.toList().forEach { it.deleteOnCascade() } + pushRules.clearWith { it.deleteOnCascade() } deleteFromRealm() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt index 0718096fd5..e52e32e16a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/extensions/RealmExtensions.kt @@ -16,8 +16,18 @@ package org.matrix.android.sdk.internal.extensions +import io.realm.RealmList import io.realm.RealmObject internal fun RealmObject.assertIsManaged() { check(isManaged) { "${javaClass.simpleName} entity should be managed to use this function" } } + +/** + * Clear a RealmList by deleting all its items calling the provided lambda + */ +internal fun RealmList.clearWith(delete: (T) -> Unit) { + while (!isEmpty()) { + first()?.let { delete.invoke(it) } + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt index 4fb7708ed1..2daaf5d81c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt @@ -47,6 +47,7 @@ import org.matrix.android.sdk.internal.database.query.getOrNull import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.di.UserId +import org.matrix.android.sdk.internal.extensions.clearWith import org.matrix.android.sdk.internal.session.DefaultInitialSyncProgressService import org.matrix.android.sdk.internal.session.mapWithProgress import org.matrix.android.sdk.internal.session.room.membership.RoomChangeMembershipStateDataSource @@ -262,8 +263,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle val leftMember = RoomMemberSummaryEntity.where(realm, roomId, userId).findFirst() val membership = leftMember?.membership ?: Membership.LEAVE roomEntity.membership = membership - roomEntity.chunks.forEach { it.deleteOnCascade(deleteStateEvents = true, canDeleteRoot = true) } - roomEntity.chunks.clear() + roomEntity.chunks.clearWith { it.deleteOnCascade(deleteStateEvents = true, canDeleteRoot = true) } roomTypingUsersHandler.handle(realm, roomId, null) roomChangeMembershipStateDataSource.setMembershipFromSync(roomId, Membership.LEAVE) roomSummaryUpdater.update(realm, roomId, membership, roomSync.summary, roomSync.unreadNotifications) From 407134a89f29ed3587f8bb8651c9eabab56eae52 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 5 Feb 2021 19:56:39 +0100 Subject: [PATCH 04/15] RTL: some arrows should be rotated in RTL (#2757) --- CHANGES.md | 1 + .../main/res/drawable-ldrtl/ic_arrow_right.xml | 16 ++++++++++++++++ .../src/main/res/drawable/ic_arrow_right.xml | 18 ++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 vector/src/main/res/drawable-ldrtl/ic_arrow_right.xml diff --git a/CHANGES.md b/CHANGES.md index 6cf6d306e9..a262150e51 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Improvements 🙌: Bugfix 🐛: - Duplicate thumbs | Mobile reactions for 👍 and 👎 are not the same as web (#2776) - Join room by alias other federation error (#2778) + - RTL: some arrows should be rotated in RTL (#2757) Translations 🗣: - diff --git a/vector/src/main/res/drawable-ldrtl/ic_arrow_right.xml b/vector/src/main/res/drawable-ldrtl/ic_arrow_right.xml new file mode 100644 index 0000000000..b783231437 --- /dev/null +++ b/vector/src/main/res/drawable-ldrtl/ic_arrow_right.xml @@ -0,0 +1,16 @@ + + + diff --git a/vector/src/main/res/drawable/ic_arrow_right.xml b/vector/src/main/res/drawable/ic_arrow_right.xml index c314196b66..76f2757723 100644 --- a/vector/src/main/res/drawable/ic_arrow_right.xml +++ b/vector/src/main/res/drawable/ic_arrow_right.xml @@ -1,14 +1,16 @@ - + From 5e2e6dcfc39d51a3fe2c1a333a45635193bceab2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 5 Feb 2021 20:01:24 +0100 Subject: [PATCH 05/15] Fix another RTL issue --- vector/src/main/res/layout/fragment_home_drawer.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/vector/src/main/res/layout/fragment_home_drawer.xml b/vector/src/main/res/layout/fragment_home_drawer.xml index d56bae4678..e627882d96 100644 --- a/vector/src/main/res/layout/fragment_home_drawer.xml +++ b/vector/src/main/res/layout/fragment_home_drawer.xml @@ -84,6 +84,7 @@ android:insetRight="0dp" android:insetBottom="0dp" android:padding="0dp" + android:rotationY="@integer/rtl_mirror_flip" app:cornerRadius="17dp" app:icon="@drawable/ic_qr_code_add" app:iconGravity="textStart" From 41e4e823fb7cadb54ade1370aca2708b9d926903 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 5 Feb 2021 20:40:57 +0100 Subject: [PATCH 06/15] HTML unescaping for URL preview (#2766) --- CHANGES.md | 1 + .../session/media/GetPreviewUrlTask.kt | 7 +++--- .../matrix/android/sdk/internal/util/Html.kt | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt diff --git a/CHANGES.md b/CHANGES.md index 6cf6d306e9..f1f1d8dcaf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Improvements 🙌: Bugfix 🐛: - Duplicate thumbs | Mobile reactions for 👍 and 👎 are not the same as web (#2776) - Join room by alias other federation error (#2778) + - HTML unescaping for URL preview (#2766) Translations 🗣: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt index a218f3f93c..d85e471f1d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction +import org.matrix.android.sdk.internal.util.unescapeHtml import java.util.Date import javax.inject.Inject @@ -73,9 +74,9 @@ internal class DefaultGetPreviewUrlTask @Inject constructor( private fun JsonDict.toPreviewUrlData(url: String): PreviewUrlData { return PreviewUrlData( url = (get("og:url") as? String) ?: url, - siteName = get("og:site_name") as? String, - title = get("og:title") as? String, - description = get("og:description") as? String, + siteName = (get("og:site_name") as? String)?.unescapeHtml(), + title = (get("og:title") as? String)?.unescapeHtml(), + description = (get("og:description") as? String)?.unescapeHtml(), mxcUrl = get("og:image") as? String ) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt new file mode 100644 index 0000000000..943b8428d5 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * 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 + * + * 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. + */ + +package org.matrix.android.sdk.internal.util + +import androidx.core.text.HtmlCompat + +internal fun String.unescapeHtml(): String { + return HtmlCompat.fromHtml(this, HtmlCompat.FROM_HTML_MODE_LEGACY).toString() +} From f6ad67f1c8140e6e5fa52a574c5f9a761dcf290c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sun, 7 Feb 2021 14:29:27 +0100 Subject: [PATCH 07/15] Use the navigator facility --- .../app/features/navigation/DefaultNavigator.kt | 3 +-- .../features/roomprofile/RoomProfileFragment.kt | 17 ++++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index fded8602c4..c32b5626be 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -262,8 +262,7 @@ class DefaultNavigator @Inject constructor( ?.let { avatarUrl -> val intent = BigImageViewerActivity.newIntent(activity, matrixItem.getBestName(), avatarUrl) val options = sharedElement?.let { - ActivityOptionsCompat.makeSceneTransitionAnimation(activity, it, ViewCompat.getTransitionName(it) - ?: "") + ActivityOptionsCompat.makeSceneTransitionAnimation(activity, it, ViewCompat.getTransitionName(it) ?: "") } activity.startActivity(intent, options?.toBundle()) } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index 58fd78e26a..0cb57fda4f 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -25,9 +25,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.app.ActivityOptionsCompat import androidx.core.content.pm.ShortcutManagerCompat -import androidx.core.view.ViewCompat import androidx.core.view.isVisible import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel @@ -52,7 +50,6 @@ import im.vector.app.features.home.room.list.actions.RoomListActionsArgs import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedAction import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel -import im.vector.app.features.media.BigImageViewerActivity import kotlinx.parcelize.Parcelize import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState import org.matrix.android.sdk.api.util.MatrixItem @@ -103,8 +100,8 @@ class RoomProfileFragment @Inject constructor( appBarStateChangeListener = MatrixItemAppBarStateChangeListener( headerView, listOf(views.matrixProfileToolbarAvatarImageView, - views.matrixProfileToolbarTitleView, - views.matrixProfileDecorationToolbarAvatarImageView) + views.matrixProfileToolbarTitleView, + views.matrixProfileDecorationToolbarAvatarImageView) ) views.matrixProfileAppBarLayout.addOnOffsetChangedListener(appBarStateChangeListener) roomProfileViewModel.observeViewEvents { @@ -289,13 +286,7 @@ class RoomProfileFragment @Inject constructor( ) } - private fun onAvatarClicked(view: View, matrixItem: MatrixItem.RoomItem) = withState(roomProfileViewModel) { - matrixItem.avatarUrl - ?.takeIf { it.isNotEmpty() } - ?.let { avatarUrl -> - val intent = BigImageViewerActivity.newIntent(requireContext(), matrixItem.getBestName(), avatarUrl) - val options = ActivityOptionsCompat.makeSceneTransitionAnimation(requireActivity(), view, ViewCompat.getTransitionName(view) ?: "") - startActivity(intent, options.toBundle()) - } + private fun onAvatarClicked(view: View, matrixItem: MatrixItem.RoomItem) { + navigator.openBigImageViewer(requireActivity(), view, matrixItem) } } From ed99b503f5c5672ca4e9476a3f715e6dfb252ddb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sun, 7 Feb 2021 15:00:07 +0100 Subject: [PATCH 08/15] Open image from URL Preview (#2705) --- CHANGES.md | 2 +- .../home/room/detail/RoomDetailFragment.kt | 4 ++++ .../detail/timeline/TimelineEventController.kt | 1 + .../room/detail/timeline/url/PreviewUrlView.kt | 14 ++++++++++++++ .../app/features/navigation/DefaultNavigator.kt | 7 +++---- .../im/vector/app/features/navigation/Navigator.kt | 6 +++++- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f1f1d8dcaf..09ee32a127 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features ✨: - Improvements 🙌: - - + - Open image from URL Preview (#2705) Bugfix 🐛: - Duplicate thumbs | Mobile reactions for 👍 and 👎 are not the same as web (#2776) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 2d2059377c..aeb1c30f4b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -1687,6 +1687,10 @@ class RoomDetailFragment @Inject constructor( roomDetailViewModel.handle(RoomDetailAction.DoNotShowPreviewUrlFor(eventId, url)) } + override fun onPreviewUrlImageClicked(sharedView: View?, mxcUrl: String?, title: String?) { + navigator.openBigImageViewer(requireActivity(), sharedView, mxcUrl, title) + } + private fun onShareActionClicked(action: EventSharedAction.Share) { if (action.messageContent is MessageTextContent) { shareText(requireContext(), action.messageContent.body) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt index ba3ffe3174..1e108a2062 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt @@ -130,6 +130,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec interface PreviewUrlCallback { fun onPreviewUrlClicked(url: String) fun onPreviewUrlCloseClicked(eventId: String, url: String) + fun onPreviewUrlImageClicked(sharedView: View?, mxcUrl: String?, title: String?) } // Map eventId to adapter position diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt index a36b1281ba..0acf704595 100755 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt @@ -80,6 +80,19 @@ class PreviewUrlView @JvmOverloads constructor( } } + private fun onImageClick() { + when (val finalState = state) { + is PreviewUrlUiState.Data -> { + delegate?.onPreviewUrlImageClicked( + sharedView = views.urlPreviewImage, + mxcUrl = finalState.previewUrlData.mxcUrl, + title = finalState.previewUrlData.title + ) + } + else -> Unit + } + } + private fun onCloseClick() { when (val finalState = state) { is PreviewUrlUiState.Data -> delegate?.onPreviewUrlCloseClicked(finalState.eventId, finalState.url) @@ -94,6 +107,7 @@ class PreviewUrlView @JvmOverloads constructor( views = UrlPreviewBinding.bind(this) setOnClickListener(this) + views.urlPreviewImage.setOnClickListener { onImageClick() } views.urlPreviewClose.setOnClickListener { onCloseClick() } } diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index c32b5626be..43a3f748a5 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -73,7 +73,6 @@ import org.matrix.android.sdk.api.session.room.model.thirdparty.RoomDirectoryDat import org.matrix.android.sdk.api.session.terms.TermsService import org.matrix.android.sdk.api.session.widgets.model.Widget import org.matrix.android.sdk.api.session.widgets.model.WidgetType -import org.matrix.android.sdk.api.util.MatrixItem import javax.inject.Inject import javax.inject.Singleton @@ -256,11 +255,11 @@ class DefaultNavigator @Inject constructor( context.startActivity(RoomProfileActivity.newIntent(context, roomId, directAccess)) } - override fun openBigImageViewer(activity: Activity, sharedElement: View?, matrixItem: MatrixItem) { - matrixItem.avatarUrl + override fun openBigImageViewer(activity: Activity, sharedElement: View?, mxcUrl: String?, title: String?) { + mxcUrl ?.takeIf { it.isNotBlank() } ?.let { avatarUrl -> - val intent = BigImageViewerActivity.newIntent(activity, matrixItem.getBestName(), avatarUrl) + val intent = BigImageViewerActivity.newIntent(activity, title, avatarUrl) val options = sharedElement?.let { ActivityOptionsCompat.makeSceneTransitionAnimation(activity, it, ViewCompat.getTransitionName(it) ?: "") } diff --git a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt index 504fccb63a..dda071795b 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt @@ -80,7 +80,11 @@ interface Navigator { fun openRoomProfile(context: Context, roomId: String, directAccess: Int? = null) - fun openBigImageViewer(activity: Activity, sharedElement: View?, matrixItem: MatrixItem) + fun openBigImageViewer(activity: Activity, sharedElement: View?, matrixItem: MatrixItem) { + openBigImageViewer(activity, sharedElement, matrixItem.avatarUrl, matrixItem.getBestName()) + } + + fun openBigImageViewer(activity: Activity, sharedElement: View?, mxcUrl: String?, title: String?) fun openPinCode(context: Context, activityResultLauncher: ActivityResultLauncher, From 07220d7a5964178fe1f9b6eda51af5e5c303e94c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sun, 7 Feb 2021 15:21:07 +0100 Subject: [PATCH 09/15] URL preview on reply fallback (#2756) --- CHANGES.md | 1 + .../org/matrix/android/sdk/api/util/ContentUtils.kt | 6 +++--- .../sdk/internal/session/media/UrlsExtractor.kt | 10 +++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 09ee32a127..63672ff840 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Bugfix 🐛: - Duplicate thumbs | Mobile reactions for 👍 and 👎 are not the same as web (#2776) - Join room by alias other federation error (#2778) - HTML unescaping for URL preview (#2766) + - URL preview on reply fallback (#2756) Translations 🗣: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/ContentUtils.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/ContentUtils.kt index c82a929ee0..1a00b85ff4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/ContentUtils.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/ContentUtils.kt @@ -20,7 +20,7 @@ object ContentUtils { val lines = repliedBody.lines() var wellFormed = repliedBody.startsWith(">") var endOfPreviousFound = false - val usefullines = ArrayList() + val usefulLines = ArrayList() lines.forEach { if (it == "") { endOfPreviousFound = true @@ -29,10 +29,10 @@ object ContentUtils { if (!endOfPreviousFound) { wellFormed = wellFormed && it.startsWith(">") } else { - usefullines.add(it) + usefulLines.add(it) } } - return usefullines.joinToString("\n").takeIf { wellFormed } ?: repliedBody + return usefulLines.joinToString("\n").takeIf { wellFormed } ?: repliedBody } fun extractUsefulTextFromHtmlReply(repliedBody: String): String { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt index 6137b4152c..83a5a724cc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt @@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.room.model.message.MessageType import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent +import org.matrix.android.sdk.api.util.ContentUtils import javax.inject.Inject internal class UrlsExtractor @Inject constructor() { @@ -35,7 +36,14 @@ internal class UrlsExtractor @Inject constructor() { || it.msgType == MessageType.MSGTYPE_NOTICE || it.msgType == MessageType.MSGTYPE_EMOTE } - ?.body + ?.let { messageContent -> + if (messageContent.relatesTo?.inReplyTo?.eventId != null) { + // This is a reply, strip the reply fallback + ContentUtils.extractUsefulTextFromReply(messageContent.body) + } else { + messageContent.body + } + } ?.let { urlRegex.findAll(it) } ?.map { it.value } ?.filter { it.startsWith("https://") || it.startsWith("http://") } From af30ff50f0c10e775c73bc15ec9deff570bcdc51 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sun, 7 Feb 2021 15:24:10 +0100 Subject: [PATCH 10/15] Naming convention --- .../home/room/detail/timeline/url/PreviewUrlView.kt | 8 ++++---- .../res/layout/{url_preview.xml => view_url_preview.xml} | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename vector/src/main/res/layout/{url_preview.xml => view_url_preview.xml} (100%) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt index 0acf704595..f5d09efd18 100755 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlView.kt @@ -23,7 +23,7 @@ import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isVisible import im.vector.app.R import im.vector.app.core.extensions.setTextOrHide -import im.vector.app.databinding.UrlPreviewBinding +import im.vector.app.databinding.ViewUrlPreviewBinding import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.media.ImageContentRenderer @@ -39,7 +39,7 @@ class PreviewUrlView @JvmOverloads constructor( defStyleAttr: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr), View.OnClickListener { - private lateinit var views: UrlPreviewBinding + private lateinit var views: ViewUrlPreviewBinding var delegate: TimelineEventController.PreviewUrlCallback? = null @@ -103,8 +103,8 @@ class PreviewUrlView @JvmOverloads constructor( // PRIVATE METHODS **************************************************************************************************************************************** private fun setupView() { - inflate(context, R.layout.url_preview, this) - views = UrlPreviewBinding.bind(this) + inflate(context, R.layout.view_url_preview, this) + views = ViewUrlPreviewBinding.bind(this) setOnClickListener(this) views.urlPreviewImage.setOnClickListener { onImageClick() } diff --git a/vector/src/main/res/layout/url_preview.xml b/vector/src/main/res/layout/view_url_preview.xml similarity index 100% rename from vector/src/main/res/layout/url_preview.xml rename to vector/src/main/res/layout/view_url_preview.xml From b0e5d5d3e5749c907fccee8eb6062bac7fe61f29 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sun, 7 Feb 2021 20:21:31 +0100 Subject: [PATCH 11/15] Copyright --- .../src/main/java/org/matrix/android/sdk/internal/util/Html.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt index 943b8428d5..329b100497 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Html.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 New Vector Ltd + * Copyright 2021 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 8363eba32e34b282219d494a58bcd848e29cb1f7 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 8 Feb 2021 09:57:19 +0100 Subject: [PATCH 12/15] Better test of a reply --- .../android/sdk/internal/session/media/UrlsExtractor.kt | 3 ++- .../app/features/home/room/detail/RoomDetailViewModel.kt | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt index 83a5a724cc..d1fb5b98ff 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt @@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.room.model.message.MessageType import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent +import org.matrix.android.sdk.api.session.room.timeline.isReply import org.matrix.android.sdk.api.util.ContentUtils import javax.inject.Inject @@ -37,7 +38,7 @@ internal class UrlsExtractor @Inject constructor() { || it.msgType == MessageType.MSGTYPE_EMOTE } ?.let { messageContent -> - if (messageContent.relatesTo?.inReplyTo?.eventId != null) { + if (event.isReply()) { // This is a reply, strip the reply fallback ContentUtils.extractUsefulTextFromReply(messageContent.body) } else { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 09179a9458..a5961b2647 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -87,11 +87,11 @@ import org.matrix.android.sdk.api.session.room.read.ReadService import org.matrix.android.sdk.api.session.room.send.UserDraft import org.matrix.android.sdk.api.session.room.timeline.Timeline import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent +import org.matrix.android.sdk.api.session.room.timeline.getRelationContent import org.matrix.android.sdk.api.session.room.timeline.getTextEditableContent import org.matrix.android.sdk.api.session.widgets.model.Widget import org.matrix.android.sdk.api.session.widgets.model.WidgetType import org.matrix.android.sdk.api.util.toOptional -import org.matrix.android.sdk.internal.crypto.model.event.EncryptedEventContent import org.matrix.android.sdk.internal.crypto.model.event.WithHeldCode import org.matrix.android.sdk.internal.util.awaitCallback import org.matrix.android.sdk.rx.rx @@ -749,8 +749,7 @@ class RoomDetailViewModel @AssistedInject constructor( } is SendMode.EDIT -> { // is original event a reply? - val inReplyTo = state.sendMode.timelineEvent.root.getClearContent().toModel()?.relatesTo?.inReplyTo?.eventId - ?: state.sendMode.timelineEvent.root.content.toModel()?.relatesTo?.inReplyTo?.eventId + val inReplyTo = state.sendMode.timelineEvent.getRelationContent()?.inReplyTo?.eventId if (inReplyTo != null) { // TODO check if same content? room.getTimeLineEvent(inReplyTo)?.let { From 30be44077490f19262cacfa05d06577343d812fe Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 8 Feb 2021 12:37:38 +0100 Subject: [PATCH 13/15] Sugar: defined extensions fo deleteOnCascade() methods, as they have to be called in a transaction --- .../store/db/model/CrossSigningInfoEntity.kt | 10 +++++----- .../crypto/store/db/model/DeviceInfoEntity.kt | 10 +++++----- .../crypto/store/db/model/KeyInfoEntity.kt | 9 ++++----- .../crypto/store/db/model/UserEntity.kt | 12 +++++------ .../internal/database/model/ChunkEntity.kt | 18 ++++++++--------- .../model/EventAnnotationsSummaryEntity.kt | 16 +++++++-------- .../internal/database/model/PushRuleEntity.kt | 10 +++++----- .../database/model/PushRulesEntity.kt | 10 +++++----- .../internal/database/model/PusherEntity.kt | 10 +++++----- .../model/ReadReceiptsSummaryEntity.kt | 10 +++++----- .../database/model/TimelineEventEntity.kt | 20 +++++++++---------- 11 files changed, 67 insertions(+), 68 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt index 2d91c32d90..8599c972e9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CrossSigningInfoEntity.kt @@ -30,11 +30,6 @@ internal open class CrossSigningInfoEntity( companion object - fun deleteOnCascade() { - crossSigningKeys.clearWith { it.deleteOnCascade() } - deleteFromRealm() - } - fun getMasterKey() = crossSigningKeys.firstOrNull { it.usages.contains(KeyUsage.MASTER.value) } fun setMasterKey(info: KeyInfoEntity?) { @@ -62,3 +57,8 @@ internal open class CrossSigningInfoEntity( info?.let { crossSigningKeys.add(it) } } } + +internal fun CrossSigningInfoEntity.deleteOnCascade() { + crossSigningKeys.clearWith { it.deleteOnCascade() } + deleteFromRealm() +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt index eddf0b81c6..61870ec486 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/DeviceInfoEntity.kt @@ -46,9 +46,9 @@ internal open class DeviceInfoEntity( val users: RealmResults? = null companion object - - fun deleteOnCascade() { - trustLevelEntity?.deleteFromRealm() - deleteFromRealm() - } +} + +internal fun DeviceInfoEntity.deleteOnCascade() { + trustLevelEntity?.deleteFromRealm() + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt index 527adaf847..9133413589 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/KeyInfoEntity.kt @@ -29,10 +29,9 @@ internal open class KeyInfoEntity( */ var signatures: String? = null, var trustLevelEntity: TrustLevelEntity? = null -) : RealmObject() { +) : RealmObject() - fun deleteOnCascade() { - trustLevelEntity?.deleteFromRealm() - deleteFromRealm() - } +internal fun KeyInfoEntity.deleteOnCascade() { + trustLevelEntity?.deleteFromRealm() + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt index a815efd8cb..df9482bf96 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/UserEntity.kt @@ -29,10 +29,10 @@ internal open class UserEntity( ) : RealmObject() { companion object - - fun deleteOnCascade() { - devices.clearWith { it.deleteOnCascade() } - crossSigningInfoEntity?.deleteOnCascade() - deleteFromRealm() - } +} + +internal fun UserEntity.deleteOnCascade() { + devices.clearWith { it.deleteOnCascade() } + crossSigningInfoEntity?.deleteOnCascade() + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt index 567cb3ca32..68533a3c19 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt @@ -44,13 +44,13 @@ internal open class ChunkEntity(@Index var prevToken: String? = null, val room: RealmResults? = null companion object - - fun deleteOnCascade(deleteStateEvents: Boolean, canDeleteRoot: Boolean) { - assertIsManaged() - if (deleteStateEvents) { - stateEvents.deleteAllFromRealm() - } - timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) } - deleteFromRealm() - } +} + +internal fun ChunkEntity.deleteOnCascade(deleteStateEvents: Boolean, canDeleteRoot: Boolean) { + assertIsManaged() + if (deleteStateEvents) { + stateEvents.deleteAllFromRealm() + } + timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) } + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt index 4caf6bdd0d..33f26d439f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/EventAnnotationsSummaryEntity.kt @@ -30,12 +30,12 @@ internal open class EventAnnotationsSummaryEntity( ) : RealmObject() { companion object - - fun deleteOnCascade() { - reactionsSummary.deleteAllFromRealm() - editSummary?.deleteFromRealm() - referencesSummaryEntity?.deleteFromRealm() - pollResponseSummary?.deleteFromRealm() - deleteFromRealm() - } +} + +internal fun EventAnnotationsSummaryEntity.deleteOnCascade() { + reactionsSummary.deleteAllFromRealm() + editSummary?.deleteFromRealm() + referencesSummaryEntity?.deleteFromRealm() + pollResponseSummary?.deleteFromRealm() + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt index cf824ba85d..5bfe2833f8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRuleEntity.kt @@ -39,9 +39,9 @@ internal open class PushRuleEntity( val parent: RealmResults? = null companion object - - fun deleteOnCascade() { - conditions?.deleteAllFromRealm() - deleteFromRealm() - } +} + +internal fun PushRuleEntity.deleteOnCascade() { + conditions?.deleteAllFromRealm() + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt index 3728856663..571bc71c27 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PushRulesEntity.kt @@ -35,9 +35,9 @@ internal open class PushRulesEntity( } companion object - - fun deleteOnCascade() { - pushRules.clearWith { it.deleteOnCascade() } - deleteFromRealm() - } +} + +internal fun PushRulesEntity.deleteOnCascade() { + pushRules.clearWith { it.deleteOnCascade() } + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt index e4fb474599..af8e4f2d37 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt @@ -53,9 +53,9 @@ internal open class PusherEntity( } companion object - - fun deleteOnCascade() { - data?.deleteFromRealm() - deleteFromRealm() - } +} + +internal fun PusherEntity.deleteOnCascade() { + data?.deleteFromRealm() + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt index a3693720e4..9ca4adc33e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ReadReceiptsSummaryEntity.kt @@ -33,9 +33,9 @@ internal open class ReadReceiptsSummaryEntity( val timelineEvent: RealmResults? = null companion object - - fun deleteOnCascade() { - readReceipts.deleteAllFromRealm() - deleteFromRealm() - } +} + +internal fun ReadReceiptsSummaryEntity.deleteOnCascade() { + readReceipts.deleteAllFromRealm() + deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt index fbafb9c5eb..30bbde70c2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/TimelineEventEntity.kt @@ -39,14 +39,14 @@ internal open class TimelineEventEntity(var localId: Long = 0, val chunk: RealmResults? = null companion object - - fun deleteOnCascade(canDeleteRoot: Boolean) { - assertIsManaged() - if (canDeleteRoot) { - root?.deleteFromRealm() - } - annotations?.deleteOnCascade() - readReceipts?.deleteOnCascade() - deleteFromRealm() - } +} + +internal fun TimelineEventEntity.deleteOnCascade(canDeleteRoot: Boolean) { + assertIsManaged() + if (canDeleteRoot) { + root?.deleteFromRealm() + } + annotations?.deleteOnCascade() + readReceipts?.deleteOnCascade() + deleteFromRealm() } From 1212bb8d701e7de81d584bcba434304a12e2d7ca Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 8 Feb 2021 12:39:35 +0100 Subject: [PATCH 14/15] Change app name from "Element (Riot.im)" to "Element" --- CHANGES.md | 4 ++-- vector/build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index dfce79d260..c192577baf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -Changes in Element 1.X.X (2020-XX-XX) +Changes in Element 1.0.17 (2020-XX-XX) =================================================== Features ✨: @@ -25,7 +25,7 @@ Test: - Other changes: - - + - Change app name from "Element (Riot.im)" to "Element" Changes in Element 1.0.16 (2020-02-04) =================================================== diff --git a/vector/build.gradle b/vector/build.gradle index 95f4238a7c..486e1b0ab8 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -210,7 +210,7 @@ android { } release { - resValue "string", "app_name", "Element (Riot.im)" + resValue "string", "app_name", "Element" resValue "bool", "debug_mode", "false" buildConfigField "boolean", "LOW_PRIVACY_LOG_ENABLE", "false" From f2619df13d40b9e869ca94c997a8d938f5dce8f5 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 8 Feb 2021 14:25:33 +0100 Subject: [PATCH 15/15] Import and cleanup --- .../sdk/internal/crypto/store/db/RealmCryptoStore.kt | 1 + .../crypto/store/db/query/UserEntitiesQueries.kt | 1 + .../android/sdk/internal/database/DatabaseCleaner.kt | 9 +++++---- .../sdk/internal/session/pushers/GetPushersTask.kt | 1 + .../sdk/internal/session/pushers/SavePushRulesTask.kt | 1 + .../session/room/timeline/TokenChunkEventPersistor.kt | 1 + .../android/sdk/internal/session/sync/RoomSyncHandler.kt | 1 + .../internal/session/sync/UserAccountDataSyncHandler.kt | 9 ++++----- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt index bb14180baa..b9213ba758 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt @@ -83,6 +83,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntityFields import org.matrix.android.sdk.internal.crypto.store.db.model.WithHeldSessionEntity import org.matrix.android.sdk.internal.crypto.store.db.model.createPrimaryKey +import org.matrix.android.sdk.internal.crypto.store.db.model.deleteOnCascade import org.matrix.android.sdk.internal.crypto.store.db.query.create import org.matrix.android.sdk.internal.crypto.store.db.query.delete import org.matrix.android.sdk.internal.crypto.store.db.query.get diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt index 4db03e123e..5a3b8e5397 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/query/UserEntitiesQueries.kt @@ -21,6 +21,7 @@ import io.realm.kotlin.createObject import io.realm.kotlin.where import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntityFields +import org.matrix.android.sdk.internal.crypto.store.db.model.deleteOnCascade /** * Get or create a user diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt index e780702229..8b4ce6106b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt @@ -16,6 +16,10 @@ package org.matrix.android.sdk.internal.database +import io.realm.Realm +import io.realm.RealmConfiguration +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import org.matrix.android.sdk.internal.database.helper.nextDisplayIndex import org.matrix.android.sdk.internal.database.model.ChunkEntity import org.matrix.android.sdk.internal.database.model.ChunkEntityFields @@ -23,14 +27,11 @@ 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.TimelineEventEntity import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields +import org.matrix.android.sdk.internal.database.model.deleteOnCascade import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.session.SessionLifecycleObserver import org.matrix.android.sdk.internal.session.room.timeline.PaginationDirection import org.matrix.android.sdk.internal.task.TaskExecutor -import io.realm.Realm -import io.realm.RealmConfiguration -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import timber.log.Timber import javax.inject.Inject diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt index b66e04b4cd..125c8f0022 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt @@ -19,6 +19,7 @@ import com.zhuinden.monarchy.Monarchy import org.matrix.android.sdk.api.session.pushers.PusherState import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.model.PusherEntity +import org.matrix.android.sdk.internal.database.model.deleteOnCascade import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt index fd433c0803..6a4b891ecf 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/SavePushRulesTask.kt @@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.pushrules.RuleSetKey import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse import org.matrix.android.sdk.internal.database.mapper.PushRulesMapper import org.matrix.android.sdk.internal.database.model.PushRulesEntity +import org.matrix.android.sdk.internal.database.model.deleteOnCascade import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt index 19572edc80..c38dcd00a7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt @@ -31,6 +31,7 @@ import org.matrix.android.sdk.internal.database.model.ChunkEntity import org.matrix.android.sdk.internal.database.model.EventInsertType import org.matrix.android.sdk.internal.database.model.RoomEntity import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity +import org.matrix.android.sdk.internal.database.model.deleteOnCascade import org.matrix.android.sdk.internal.database.query.copyToRealmOrIgnore import org.matrix.android.sdk.internal.database.query.create import org.matrix.android.sdk.internal.database.query.find diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt index 2daaf5d81c..6d1b3ae034 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomSyncHandler.kt @@ -39,6 +39,7 @@ import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity import org.matrix.android.sdk.internal.database.model.EventInsertType import org.matrix.android.sdk.internal.database.model.RoomEntity import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity +import org.matrix.android.sdk.internal.database.model.deleteOnCascade import org.matrix.android.sdk.internal.database.query.copyToRealmOrIgnore import org.matrix.android.sdk.internal.database.query.find import org.matrix.android.sdk.internal.database.query.findLastForwardChunkOfRoom diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt index 880dbdcb88..449d47abe5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/UserAccountDataSyncHandler.kt @@ -16,8 +16,10 @@ package org.matrix.android.sdk.internal.session.sync -import com.squareup.moshi.Moshi import com.zhuinden.monarchy.Monarchy +import io.realm.Realm +import io.realm.RealmList +import io.realm.kotlin.where import org.matrix.android.sdk.api.pushrules.RuleScope import org.matrix.android.sdk.api.pushrules.RuleSetKey import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse @@ -37,6 +39,7 @@ 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.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.getDirectRooms import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.database.query.where @@ -50,9 +53,6 @@ import org.matrix.android.sdk.internal.session.sync.model.accountdata.IgnoredUse import org.matrix.android.sdk.internal.session.sync.model.accountdata.UserAccountDataSync import org.matrix.android.sdk.internal.session.user.accountdata.DirectChatsHelper import org.matrix.android.sdk.internal.session.user.accountdata.UpdateUserAccountDataTask -import io.realm.Realm -import io.realm.RealmList -import io.realm.kotlin.where import timber.log.Timber import javax.inject.Inject @@ -60,7 +60,6 @@ internal class UserAccountDataSyncHandler @Inject constructor( @SessionDatabase private val monarchy: Monarchy, @UserId private val userId: String, private val directChatsHelper: DirectChatsHelper, - private val moshi: Moshi, private val updateUserAccountDataTask: UpdateUserAccountDataTask) { fun handle(realm: Realm, accountData: UserAccountDataSync?) {