Skip to content

Commit 15c6a5e

Browse files
Add roomId in InboundSessionEntity for better performance
Add shared history flag to InboundSessionEntity
1 parent 8adabb8 commit 15c6a5e

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ internal class DefaultCryptoService @Inject constructor(
952952
if (!event.isStateEvent()) return
953953
val eventContent = event.content.toModel<RoomHistoryVisibilityContent>()
954954
eventContent?.historyVisibility?.let {
955+
Timber.i("-----> onRoomHistoryVisibilityEvent $it")
955956
cryptoStore.setShouldEncryptForInvitedMembers(roomId, it != RoomHistoryVisibility.JOINED)
956957
}
957958
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ internal class RealmCryptoStore @Inject constructor(
744744
primaryKey = key
745745
sessionId = sessionIdentifier
746746
senderKey = session.senderKey
747+
roomId = session.roomId
747748
putInboundGroupSession(session)
748749
}
749750

@@ -817,11 +818,10 @@ internal class RealmCryptoStore @Inject constructor(
817818
override fun getInboundGroupSessions(roomId: String): List<OlmInboundGroupSessionWrapper2> {
818819
return doWithRealm(realmConfiguration) {
819820
it.where<OlmInboundGroupSessionEntity>()
821+
.equalTo(OlmInboundGroupSessionEntityFields.ROOM_ID, roomId)
820822
.findAll()
821823
.mapNotNull { inboundGroupSessionEntity ->
822824
inboundGroupSessionEntity.getInboundGroupSession()
823-
}.filter { inboundSession ->
824-
inboundSession.roomId == roomId
825825
}
826826
}
827827
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo
3333
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo013
3434
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo014
3535
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo015
36+
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo016
3637
import timber.log.Timber
3738
import javax.inject.Inject
3839

@@ -47,7 +48,7 @@ internal class RealmCryptoStoreMigration @Inject constructor() : RealmMigration
4748
// 0, 1, 2: legacy Riot-Android
4849
// 3: migrate to RiotX schema
4950
// 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6)
50-
val schemaVersion = 15L
51+
val schemaVersion = 16L
5152

5253
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
5354
Timber.d("Migrating Realm Crypto from $oldVersion to $newVersion")
@@ -67,5 +68,7 @@ internal class RealmCryptoStoreMigration @Inject constructor() : RealmMigration
6768
if (oldVersion < 13) MigrateCryptoTo013(realm).perform()
6869
if (oldVersion < 14) MigrateCryptoTo014(realm).perform()
6970
if (oldVersion < 15) MigrateCryptoTo015(realm).perform()
71+
if (oldVersion < 16) MigrateCryptoTo016(realm).perform()
72+
7073
}
7174
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.internal.crypto.store.db.migration
18+
19+
import io.realm.DynamicRealm
20+
import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM
21+
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoRoomEntityFields
22+
import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSessionEntityFields
23+
import org.matrix.android.sdk.internal.util.database.RealmMigrator
24+
25+
// Version 16L enhance OlmInboundGroupSessionEntity to support shared history for MSC3061
26+
internal class MigrateCryptoTo016(realm: DynamicRealm) : RealmMigrator(realm, 16) {
27+
28+
override fun doMigrate(realm: DynamicRealm) {
29+
realm.schema.get("OlmInboundGroupSessionEntity")
30+
?.addField(OlmInboundGroupSessionEntityFields.SHARED_HISTORY, Boolean::class.java)
31+
?.addField(OlmInboundGroupSessionEntityFields.ROOM_ID, String::class.java)
32+
}
33+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OlmInboundGroupSessionEntity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ internal open class OlmInboundGroupSessionEntity(
3030
@PrimaryKey var primaryKey: String? = null,
3131
var sessionId: String? = null,
3232
var senderKey: String? = null,
33+
var roomId: String? = null,
3334
// olmInboundGroupSessionData contains Json
3435
var olmInboundGroupSessionData: String? = null,
36+
// Flag that indicates whether or not the current inboundSession will be shared to
37+
// invited users to decrypt past messages
38+
var sharedHistory: Boolean = false,
3539
// Indicate if the key has been backed up to the homeserver
3640
var backedUp: Boolean = false) :
3741
RealmObject() {

0 commit comments

Comments
 (0)