File tree Expand file tree Collapse file tree 6 files changed +53
-12
lines changed
matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db Expand file tree Collapse file tree 6 files changed +53
-12
lines changed Original file line number Diff line number Diff line change @@ -624,14 +624,7 @@ internal class RealmCryptoStore @Inject constructor(
624
624
}
625
625
626
626
override fun saveMyDevicesInfo (info : List <DeviceInfo >) {
627
- val entities = info.map {
628
- MyDeviceLastSeenInfoEntity (
629
- lastSeenTs = it.lastSeenTs,
630
- lastSeenIp = it.lastSeenIp,
631
- displayName = it.displayName,
632
- deviceId = it.deviceId
633
- )
634
- }
627
+ val entities = info.map { myDeviceLastSeenInfoEntityMapper.map(it) }
635
628
doRealmTransactionAsync(realmConfiguration) { realm ->
636
629
realm.where<MyDeviceLastSeenInfoEntity >().findAll().deleteAllFromRealm()
637
630
entities.forEach {
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo
36
36
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo017
37
37
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo018
38
38
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo019
39
+ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo020
39
40
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
40
41
import org.matrix.android.sdk.internal.util.time.Clock
41
42
import javax.inject.Inject
@@ -50,7 +51,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(
50
51
private val clock : Clock ,
51
52
) : MatrixRealmMigration(
52
53
dbName = " Crypto" ,
53
- schemaVersion = 19L ,
54
+ schemaVersion = 20L ,
54
55
) {
55
56
/* *
56
57
* Forces all RealmCryptoStoreMigration instances to be equal.
@@ -79,5 +80,6 @@ internal class RealmCryptoStoreMigration @Inject constructor(
79
80
if (oldVersion < 17 ) MigrateCryptoTo017 (realm).perform()
80
81
if (oldVersion < 18 ) MigrateCryptoTo018 (realm).perform()
81
82
if (oldVersion < 19 ) MigrateCryptoTo019 (realm).perform()
83
+ if (oldVersion < 20 ) MigrateCryptoTo020 (realm).perform()
82
84
}
83
85
}
Original file line number Diff line number Diff line change @@ -22,12 +22,24 @@ import javax.inject.Inject
22
22
23
23
internal class MyDeviceLastSeenInfoEntityMapper @Inject constructor() {
24
24
25
+ // TODO add unit tests
25
26
fun map (entity : MyDeviceLastSeenInfoEntity ): DeviceInfo {
26
27
return DeviceInfo (
27
28
deviceId = entity.deviceId,
28
29
lastSeenIp = entity.lastSeenIp,
29
30
lastSeenTs = entity.lastSeenTs,
30
- displayName = entity.displayName
31
+ displayName = entity.displayName,
32
+ unstableLastSeenUserAgent = entity.lastSeenUserAgent,
33
+ )
34
+ }
35
+
36
+ fun map (deviceInfo : DeviceInfo ): MyDeviceLastSeenInfoEntity {
37
+ return MyDeviceLastSeenInfoEntity (
38
+ deviceId = deviceInfo.deviceId,
39
+ lastSeenIp = deviceInfo.lastSeenIp,
40
+ lastSeenTs = deviceInfo.lastSeenTs,
41
+ displayName = deviceInfo.displayName,
42
+ lastSeenUserAgent = deviceInfo.getBestLastSeenUserAgent(),
31
43
)
32
44
}
33
45
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ import org.matrix.android.sdk.internal.util.database.RealmMigrator
30
30
* mark existing keys as safe.
31
31
* This migration can take long depending on the account
32
32
*/
33
- internal class MigrateCryptoTo019 (realm : DynamicRealm ) : RealmMigrator(realm, 18 ) {
33
+ internal class MigrateCryptoTo019 (realm : DynamicRealm ) : RealmMigrator(realm, 19 ) {
34
34
35
35
override fun doMigrate (realm : DynamicRealm ) {
36
36
realm.schema.get(" CrossSigningInfoEntity" )
Original file line number Diff line number Diff line change
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.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntityFields
21
+ import org.matrix.android.sdk.internal.util.database.RealmMigrator
22
+
23
+ /* *
24
+ * This migration adds a new field into MyDeviceLastSeenInfoEntity corresponding to the last seen user agent.
25
+ */
26
+ internal class MigrateCryptoTo020 (realm : DynamicRealm ) : RealmMigrator(realm, 20 ) {
27
+
28
+ override fun doMigrate (realm : DynamicRealm ) {
29
+ realm.schema.get(" MyDeviceLastSeenInfoEntity" )
30
+ ?.addField(MyDeviceLastSeenInfoEntityFields .LAST_SEEN_USER_AGENT , String ::class .java)
31
+ }
32
+ }
Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ internal open class MyDeviceLastSeenInfoEntity(
27
27
/* * The last time this device has been seen. */
28
28
var lastSeenTs : Long? = null ,
29
29
/* * The last ip address. */
30
- var lastSeenIp : String? = null
30
+ var lastSeenIp : String? = null ,
31
+ /* * The last user agent. */
32
+ var lastSeenUserAgent : String? = null ,
31
33
) : RealmObject() {
32
34
33
35
companion object
You can’t perform that action at this time.
0 commit comments