Adding new field for last seen user agent in DB with migration
This commit is contained in:
parent
3be1513e0f
commit
b23520ea40
@ -624,14 +624,7 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun saveMyDevicesInfo(info: List<DeviceInfo>) {
|
override fun saveMyDevicesInfo(info: List<DeviceInfo>) {
|
||||||
val entities = info.map {
|
val entities = info.map { myDeviceLastSeenInfoEntityMapper.map(it) }
|
||||||
MyDeviceLastSeenInfoEntity(
|
|
||||||
lastSeenTs = it.lastSeenTs,
|
|
||||||
lastSeenIp = it.lastSeenIp,
|
|
||||||
displayName = it.displayName,
|
|
||||||
deviceId = it.deviceId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
doRealmTransactionAsync(realmConfiguration) { realm ->
|
doRealmTransactionAsync(realmConfiguration) { realm ->
|
||||||
realm.where<MyDeviceLastSeenInfoEntity>().findAll().deleteAllFromRealm()
|
realm.where<MyDeviceLastSeenInfoEntity>().findAll().deleteAllFromRealm()
|
||||||
entities.forEach {
|
entities.forEach {
|
||||||
|
@ -36,6 +36,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo
|
|||||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo017
|
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo017
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo018
|
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo018
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo019
|
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo019
|
||||||
|
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo020
|
||||||
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
|
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
|
||||||
import org.matrix.android.sdk.internal.util.time.Clock
|
import org.matrix.android.sdk.internal.util.time.Clock
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -50,7 +51,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(
|
|||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
) : MatrixRealmMigration(
|
) : MatrixRealmMigration(
|
||||||
dbName = "Crypto",
|
dbName = "Crypto",
|
||||||
schemaVersion = 19L,
|
schemaVersion = 20L,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Forces all RealmCryptoStoreMigration instances to be equal.
|
* Forces all RealmCryptoStoreMigration instances to be equal.
|
||||||
@ -79,5 +80,6 @@ internal class RealmCryptoStoreMigration @Inject constructor(
|
|||||||
if (oldVersion < 17) MigrateCryptoTo017(realm).perform()
|
if (oldVersion < 17) MigrateCryptoTo017(realm).perform()
|
||||||
if (oldVersion < 18) MigrateCryptoTo018(realm).perform()
|
if (oldVersion < 18) MigrateCryptoTo018(realm).perform()
|
||||||
if (oldVersion < 19) MigrateCryptoTo019(realm).perform()
|
if (oldVersion < 19) MigrateCryptoTo019(realm).perform()
|
||||||
|
if (oldVersion < 20) MigrateCryptoTo020(realm).perform()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,24 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
internal class MyDeviceLastSeenInfoEntityMapper @Inject constructor() {
|
internal class MyDeviceLastSeenInfoEntityMapper @Inject constructor() {
|
||||||
|
|
||||||
|
// TODO add unit tests
|
||||||
fun map(entity: MyDeviceLastSeenInfoEntity): DeviceInfo {
|
fun map(entity: MyDeviceLastSeenInfoEntity): DeviceInfo {
|
||||||
return DeviceInfo(
|
return DeviceInfo(
|
||||||
deviceId = entity.deviceId,
|
deviceId = entity.deviceId,
|
||||||
lastSeenIp = entity.lastSeenIp,
|
lastSeenIp = entity.lastSeenIp,
|
||||||
lastSeenTs = entity.lastSeenTs,
|
lastSeenTs = entity.lastSeenTs,
|
||||||
displayName = entity.displayName
|
displayName = entity.displayName,
|
||||||
|
unstableLastSeenUserAgent = entity.lastSeenUserAgent,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun map(deviceInfo: DeviceInfo): MyDeviceLastSeenInfoEntity {
|
||||||
|
return MyDeviceLastSeenInfoEntity(
|
||||||
|
deviceId = deviceInfo.deviceId,
|
||||||
|
lastSeenIp = deviceInfo.lastSeenIp,
|
||||||
|
lastSeenTs = deviceInfo.lastSeenTs,
|
||||||
|
displayName = deviceInfo.displayName,
|
||||||
|
lastSeenUserAgent = deviceInfo.getBestLastSeenUserAgent(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import org.matrix.android.sdk.internal.util.database.RealmMigrator
|
|||||||
* mark existing keys as safe.
|
* mark existing keys as safe.
|
||||||
* This migration can take long depending on the account
|
* This migration can take long depending on the account
|
||||||
*/
|
*/
|
||||||
internal class MigrateCryptoTo019(realm: DynamicRealm) : RealmMigrator(realm, 18) {
|
internal class MigrateCryptoTo019(realm: DynamicRealm) : RealmMigrator(realm, 19) {
|
||||||
|
|
||||||
override fun doMigrate(realm: DynamicRealm) {
|
override fun doMigrate(realm: DynamicRealm) {
|
||||||
realm.schema.get("CrossSigningInfoEntity")
|
realm.schema.get("CrossSigningInfoEntity")
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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.
|
||||||
|
* 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.crypto.store.db.migration
|
||||||
|
|
||||||
|
import io.realm.DynamicRealm
|
||||||
|
import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntityFields
|
||||||
|
import org.matrix.android.sdk.internal.util.database.RealmMigrator
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This migration adds a new field into MyDeviceLastSeenInfoEntity corresponding to the last seen user agent.
|
||||||
|
*/
|
||||||
|
internal class MigrateCryptoTo020(realm: DynamicRealm) : RealmMigrator(realm, 20) {
|
||||||
|
|
||||||
|
override fun doMigrate(realm: DynamicRealm) {
|
||||||
|
realm.schema.get("MyDeviceLastSeenInfoEntity")
|
||||||
|
?.addField(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_USER_AGENT, String::class.java)
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,9 @@ internal open class MyDeviceLastSeenInfoEntity(
|
|||||||
/** The last time this device has been seen. */
|
/** The last time this device has been seen. */
|
||||||
var lastSeenTs: Long? = null,
|
var lastSeenTs: Long? = null,
|
||||||
/** The last ip address. */
|
/** The last ip address. */
|
||||||
var lastSeenIp: String? = null
|
var lastSeenIp: String? = null,
|
||||||
|
/** The last user agent. */
|
||||||
|
var lastSeenUserAgent: String? = null,
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user