Realm crypto: migrate entity classes
This commit is contained in:
parent
4040593608
commit
462d1bce68
@ -16,15 +16,13 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.Index
|
import io.realm.kotlin.types.annotations.Index
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
|
internal class AuditTrailEntity : RealmObject {
|
||||||
|
var ageLocalTs: Long? = null
|
||||||
|
@Index var type: String? = null
|
||||||
|
var contentJson: String? = null
|
||||||
|
|
||||||
@RealmClass
|
|
||||||
internal open class AuditTrailEntity(
|
|
||||||
var ageLocalTs: Long? = null,
|
|
||||||
@Index var type: String? = null,
|
|
||||||
var contentJson: String? = null
|
|
||||||
) : RealmModel {
|
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
@ -16,20 +16,16 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmList
|
import io.realm.kotlin.ext.realmListOf
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmList
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.RealmClass
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.kotlin.deleteFromRealm
|
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.KeyUsage
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.KeyUsage
|
||||||
import org.matrix.android.sdk.internal.extensions.clearWith
|
|
||||||
|
|
||||||
@RealmClass
|
internal class CrossSigningInfoEntity : RealmObject {
|
||||||
internal open class CrossSigningInfoEntity(
|
@PrimaryKey
|
||||||
@PrimaryKey
|
var userId: String? = null
|
||||||
var userId: String? = null,
|
var crossSigningKeys: RealmList<KeyInfoEntity> = realmListOf()
|
||||||
var crossSigningKeys: RealmList<KeyInfoEntity> = RealmList()
|
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
|
|
||||||
@ -61,7 +57,10 @@ internal open class CrossSigningInfoEntity(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal fun CrossSigningInfoEntity.deleteOnCascade() {
|
internal fun CrossSigningInfoEntity.deleteOnCascade() {
|
||||||
crossSigningKeys.clearWith { it.deleteOnCascade() }
|
crossSigningKeys.clearWith { it.deleteOnCascade() }
|
||||||
deleteFromRealm()
|
deleteFromRealm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
@ -16,46 +16,48 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm
|
import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm
|
||||||
import org.matrix.olm.OlmAccount
|
import org.matrix.olm.OlmAccount
|
||||||
|
|
||||||
@RealmClass
|
internal class CryptoMetadataEntity : RealmObject {
|
||||||
internal open class CryptoMetadataEntity(
|
// The current user id.
|
||||||
// The current user id.
|
@PrimaryKey var userId: String? = null
|
||||||
@PrimaryKey var userId: String? = null,
|
|
||||||
// The current device id.
|
|
||||||
var deviceId: String? = null,
|
|
||||||
// Serialized OlmAccount
|
|
||||||
var olmAccountData: String? = null,
|
|
||||||
// The sync token corresponding to the device list. // TODO?
|
|
||||||
var deviceSyncToken: String? = null,
|
|
||||||
// Settings for blacklisting unverified devices.
|
|
||||||
var globalBlacklistUnverifiedDevices: Boolean = false,
|
|
||||||
// setting to enable or disable key gossiping
|
|
||||||
var globalEnableKeyGossiping: Boolean = true,
|
|
||||||
|
|
||||||
// MSC3061: Sharing room keys for past messages
|
// The current device id.
|
||||||
// If set to true key history will be shared to invited users with respect to room setting
|
var deviceId: String? = null
|
||||||
var enableKeyForwardingOnInvite: Boolean = false,
|
|
||||||
|
|
||||||
// The keys backup version currently used. Null means no backup.
|
// Serialized OlmAccount
|
||||||
var backupVersion: String? = null,
|
var olmAccountData: String? = null
|
||||||
|
|
||||||
// The device keys has been sent to the homeserver
|
// The sync token corresponding to the device list. // TODO?
|
||||||
var deviceKeysSentToServer: Boolean = false,
|
var deviceSyncToken: String? = null
|
||||||
|
|
||||||
var xSignMasterPrivateKey: String? = null,
|
// Settings for blacklisting unverified devices.
|
||||||
var xSignUserPrivateKey: String? = null,
|
var globalBlacklistUnverifiedDevices: Boolean = false
|
||||||
var xSignSelfSignedPrivateKey: String? = null,
|
|
||||||
var keyBackupRecoveryKey: String? = null,
|
// setting to enable or disable key gossiping
|
||||||
var keyBackupRecoveryKeyVersion: String? = null
|
var globalEnableKeyGossiping: Boolean = true
|
||||||
|
|
||||||
|
// MSC3061: Sharing room keys for past messages
|
||||||
|
// If set to true key history will be shared to invited users with respect to room setting
|
||||||
|
var enableKeyForwardingOnInvite: Boolean = false
|
||||||
|
|
||||||
|
// The keys backup version currently used. Null means no backup.
|
||||||
|
var backupVersion: String? = null
|
||||||
|
|
||||||
|
// The device keys has been sent to the homeserver
|
||||||
|
var deviceKeysSentToServer: Boolean = false
|
||||||
|
|
||||||
|
var xSignMasterPrivateKey: String? = null
|
||||||
|
var xSignUserPrivateKey: String? = null
|
||||||
|
var xSignSelfSignedPrivateKey: String? = null
|
||||||
|
var keyBackupRecoveryKey: String? = null
|
||||||
|
var keyBackupRecoveryKeyVersion: String? = null
|
||||||
|
|
||||||
// var crossSigningInfoEntity: CrossSigningInfoEntity? = null
|
// var crossSigningInfoEntity: CrossSigningInfoEntity? = null
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
// Deserialize data
|
// Deserialize data
|
||||||
fun getOlmAccount(): OlmAccount? {
|
fun getOlmAccount(): OlmAccount? {
|
||||||
|
@ -16,27 +16,26 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
|
|
||||||
@RealmClass
|
internal class CryptoRoomEntity : RealmObject {
|
||||||
internal open class CryptoRoomEntity(
|
@PrimaryKey var roomId: String? = null
|
||||||
@PrimaryKey var roomId: String? = null,
|
var algorithm: String? = null
|
||||||
var algorithm: String? = null,
|
var shouldEncryptForInvitedMembers: Boolean? = null
|
||||||
var shouldEncryptForInvitedMembers: Boolean? = null,
|
var blacklistUnverifiedDevices: Boolean = false
|
||||||
var blacklistUnverifiedDevices: Boolean = false,
|
|
||||||
// Determines whether or not room history should be shared on new member invites
|
// Determines whether or not room history should be shared on new member invites
|
||||||
var shouldShareHistory: Boolean = false,
|
var shouldShareHistory: Boolean = false
|
||||||
// Store the current outbound session for this room,
|
|
||||||
// to avoid re-create and re-share at each startup (if rotation not needed..)
|
// Store the current outbound session for this room,
|
||||||
// This is specific to megolm but not sure how to model it better
|
// to avoid re-create and re-share at each startup (if rotation not needed..)
|
||||||
var outboundSessionInfo: OutboundGroupSessionInfoEntity? = null,
|
// This is specific to megolm but not sure how to model it better
|
||||||
// a security to ensure that a room will never revert to not encrypted
|
var outboundSessionInfo: OutboundGroupSessionInfoEntity? = null
|
||||||
// even if a new state event with empty encryption, or state is reset somehow
|
|
||||||
var wasEncryptedOnce: Boolean? = false
|
// a security to ensure that a room will never revert to not encrypted
|
||||||
) :
|
// even if a new state event with empty encryption, or state is reset somehow
|
||||||
RealmModel {
|
var wasEncryptedOnce: Boolean? = false
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
@ -16,42 +16,38 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.RealmResults
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.annotations.LinkingObjects
|
|
||||||
import io.realm.annotations.PrimaryKey
|
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import io.realm.kotlin.deleteFromRealm
|
|
||||||
|
|
||||||
internal fun DeviceInfoEntity.Companion.createPrimaryKey(userId: String, deviceId: String) = "$userId|$deviceId"
|
internal fun DeviceInfoEntity.Companion.createPrimaryKey(userId: String, deviceId: String) = "$userId|$deviceId"
|
||||||
|
|
||||||
@RealmClass
|
internal class DeviceInfoEntity : RealmObject {
|
||||||
internal open class DeviceInfoEntity(
|
@PrimaryKey var primaryKey: String = ""
|
||||||
@PrimaryKey var primaryKey: String = "",
|
var deviceId: String? = null
|
||||||
var deviceId: String? = null,
|
var identityKey: String? = null
|
||||||
var identityKey: String? = null,
|
var userId: String? = null
|
||||||
var userId: String? = null,
|
var isBlocked: Boolean? = null
|
||||||
var isBlocked: Boolean? = null,
|
var algorithmListJson: String? = null
|
||||||
var algorithmListJson: String? = null,
|
var keysMapJson: String? = null
|
||||||
var keysMapJson: String? = null,
|
var signatureMapJson: String? = null
|
||||||
var signatureMapJson: String? = null,
|
|
||||||
// Will contain the device name from unsigned data if present
|
|
||||||
var unsignedMapJson: String? = null,
|
|
||||||
var trustLevelEntity: TrustLevelEntity? = null,
|
|
||||||
/**
|
|
||||||
* We use that to make distinction between old devices (there before mine)
|
|
||||||
* and new ones. Used for example to detect new unverified login
|
|
||||||
*/
|
|
||||||
var firstTimeSeenLocalTs: Long? = null
|
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
@LinkingObjects("devices")
|
// Will contain the device name from unsigned data if present
|
||||||
val users: RealmResults<UserEntity>? = null
|
var unsignedMapJson: String? = null
|
||||||
|
var trustLevelEntity: TrustLevelEntity? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We use that to make distinction between old devices (there before mine)
|
||||||
|
* and new ones. Used for example to detect new unverified login
|
||||||
|
*/
|
||||||
|
var firstTimeSeenLocalTs: Long? = null
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal fun DeviceInfoEntity.deleteOnCascade() {
|
internal fun DeviceInfoEntity.deleteOnCascade() {
|
||||||
trustLevelEntity?.deleteFromRealm()
|
trustLevelEntity?.deleteFromRealm()
|
||||||
deleteFromRealm()
|
deleteFromRealm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
@ -16,25 +16,28 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmList
|
import io.realm.kotlin.ext.realmListOf
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmList
|
||||||
import io.realm.annotations.RealmClass
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.kotlin.deleteFromRealm
|
|
||||||
|
|
||||||
@RealmClass
|
internal class KeyInfoEntity : RealmObject {
|
||||||
internal open class KeyInfoEntity(
|
var publicKeyBase64: String? = null
|
||||||
var publicKeyBase64: String? = null,
|
|
||||||
// var isTrusted: Boolean = false,
|
|
||||||
var usages: RealmList<String> = RealmList(),
|
|
||||||
/**
|
|
||||||
* The signature of this MXDeviceInfo.
|
|
||||||
* A map from "<userId>" to a map from "<key type>:<Publickey>" to "<signature>"
|
|
||||||
*/
|
|
||||||
var signatures: String? = null,
|
|
||||||
var trustLevelEntity: TrustLevelEntity? = null
|
|
||||||
) : RealmModel
|
|
||||||
|
|
||||||
|
// var isTrusted: Boolean = false,
|
||||||
|
var usages: RealmList<String> = realmListOf()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The signature of this MXDeviceInfo.
|
||||||
|
* A map from "<userId>" to a map from "<key type>:<Publickey>" to "<signature>"
|
||||||
|
*/
|
||||||
|
var signatures: String? = null
|
||||||
|
var trustLevelEntity: TrustLevelEntity? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal fun KeyInfoEntity.deleteOnCascade() {
|
internal fun KeyInfoEntity.deleteOnCascade() {
|
||||||
trustLevelEntity?.deleteFromRealm()
|
trustLevelEntity?.deleteFromRealm()
|
||||||
deleteFromRealm()
|
deleteFromRealm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
@ -16,17 +16,15 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||||
|
|
||||||
@RealmClass
|
internal class KeyRequestReplyEntity : RealmObject {
|
||||||
internal open class KeyRequestReplyEntity(
|
var senderId: String? = null
|
||||||
var senderId: String? = null,
|
var fromDevice: String? = null
|
||||||
var fromDevice: String? = null,
|
var eventJson: String? = null
|
||||||
var eventJson: String? = null
|
|
||||||
) : RealmModel {
|
|
||||||
companion object
|
companion object
|
||||||
|
|
||||||
fun getEvent(): Event? {
|
fun getEvent(): Event? {
|
||||||
|
@ -16,17 +16,17 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
|
|
||||||
@RealmClass
|
internal class KeysBackupDataEntity : RealmObject {
|
||||||
internal open class KeysBackupDataEntity(
|
// Primary key to update this object. There is only one object, so it's a constant, please do not set it
|
||||||
// Primary key to update this object. There is only one object, so it's a constant, please do not set it
|
@PrimaryKey
|
||||||
@PrimaryKey
|
var primaryKey: Int = 0
|
||||||
var primaryKey: Int = 0,
|
|
||||||
// The last known hash of the backed up keys on the server
|
// The last known hash of the backed up keys on the server
|
||||||
var backupLastServerHash: String? = null,
|
var backupLastServerHash: String? = null
|
||||||
// The last known number of backed up keys on the server
|
|
||||||
var backupLastServerNumberOfKeys: Int? = null
|
// The last known number of backed up keys on the server
|
||||||
) : RealmModel
|
var backupLastServerNumberOfKeys: Int? = null
|
||||||
|
}
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
|
|
||||||
@RealmClass
|
internal class MyDeviceLastSeenInfoEntity : RealmObject {
|
||||||
internal open class MyDeviceLastSeenInfoEntity(
|
/** The device id. */
|
||||||
/** The device id. */
|
@PrimaryKey var deviceId: String? = null
|
||||||
@PrimaryKey var deviceId: String? = null,
|
|
||||||
/** The device display name. */
|
/** The device display name. */
|
||||||
var displayName: String? = null,
|
var displayName: String? = null
|
||||||
/** The last time this device has been seen. */
|
|
||||||
var lastSeenTs: Long? = null,
|
/** The last time this device has been seen. */
|
||||||
/** The last ip address. */
|
var lastSeenTs: Long? = null
|
||||||
var lastSeenIp: String? = null
|
|
||||||
) : RealmModel {
|
/** The last ip address. */
|
||||||
|
var lastSeenIp: String? = null
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.InboundGroupSessionData
|
import org.matrix.android.sdk.internal.crypto.model.InboundGroupSessionData
|
||||||
import org.matrix.android.sdk.internal.crypto.model.MXInboundMegolmSessionWrapper
|
import org.matrix.android.sdk.internal.crypto.model.MXInboundMegolmSessionWrapper
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
||||||
@ -29,34 +28,32 @@ import timber.log.Timber
|
|||||||
|
|
||||||
internal fun OlmInboundGroupSessionEntity.Companion.createPrimaryKey(sessionId: String?, senderKey: String?) = "$sessionId|$senderKey"
|
internal fun OlmInboundGroupSessionEntity.Companion.createPrimaryKey(sessionId: String?, senderKey: String?) = "$sessionId|$senderKey"
|
||||||
|
|
||||||
@RealmClass
|
internal class OlmInboundGroupSessionEntity : RealmObject {
|
||||||
internal open class OlmInboundGroupSessionEntity(
|
// Combined value to build a primary key
|
||||||
// Combined value to build a primary key
|
@PrimaryKey var primaryKey: String? = null
|
||||||
@PrimaryKey var primaryKey: String? = null,
|
|
||||||
|
|
||||||
// denormalization for faster querying (these fields are in the inboundGroupSessionDataJson)
|
// denormalization for faster querying (these fields are in the inboundGroupSessionDataJson)
|
||||||
var sessionId: String? = null,
|
var sessionId: String? = null
|
||||||
var senderKey: String? = null,
|
var senderKey: String? = null
|
||||||
var roomId: String? = null,
|
var roomId: String? = null
|
||||||
|
|
||||||
// Deprecated, used for migration / olmInboundGroupSessionData contains Json
|
// Deprecated, used for migration / olmInboundGroupSessionData contains Json
|
||||||
// keep it in case of problem to have a chance to recover
|
// keep it in case of problem to have a chance to recover
|
||||||
var olmInboundGroupSessionData: String? = null,
|
var olmInboundGroupSessionData: String? = null
|
||||||
|
|
||||||
// Stores the session data in an extensible format
|
// Stores the session data in an extensible format
|
||||||
// to allow to store data not yet supported for later use
|
// to allow to store data not yet supported for later use
|
||||||
var inboundGroupSessionDataJson: String? = null,
|
var inboundGroupSessionDataJson: String? = null
|
||||||
|
|
||||||
// The pickled session
|
// The pickled session
|
||||||
var serializedOlmInboundGroupSession: String? = null,
|
var serializedOlmInboundGroupSession: String? = null
|
||||||
|
|
||||||
// Flag that indicates whether or not the current inboundSession will be shared to
|
// Flag that indicates whether or not the current inboundSession will be shared to
|
||||||
// invited users to decrypt past messages
|
// invited users to decrypt past messages
|
||||||
var sharedHistory: Boolean = false,
|
var sharedHistory: Boolean = false
|
||||||
// Indicate if the key has been backed up to the homeserver
|
|
||||||
var backedUp: Boolean = false
|
// Indicate if the key has been backed up to the homeserver
|
||||||
) :
|
var backedUp: Boolean = false
|
||||||
RealmModel {
|
|
||||||
|
|
||||||
fun store(wrapper: MXInboundMegolmSessionWrapper) {
|
fun store(wrapper: MXInboundMegolmSessionWrapper) {
|
||||||
this.serializedOlmInboundGroupSession = serializeForRealm(wrapper.session)
|
this.serializedOlmInboundGroupSession = serializeForRealm(wrapper.session)
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm
|
import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm
|
||||||
import org.matrix.olm.OlmSession
|
import org.matrix.olm.OlmSession
|
||||||
@ -26,15 +25,12 @@ import org.matrix.olm.OlmSession
|
|||||||
internal fun OlmSessionEntity.Companion.createPrimaryKey(sessionId: String, deviceKey: String) = "$sessionId|$deviceKey"
|
internal fun OlmSessionEntity.Companion.createPrimaryKey(sessionId: String, deviceKey: String) = "$sessionId|$deviceKey"
|
||||||
|
|
||||||
// olmSessionData is a serialized OlmSession
|
// olmSessionData is a serialized OlmSession
|
||||||
@RealmClass
|
internal class OlmSessionEntity : RealmObject {
|
||||||
internal open class OlmSessionEntity(
|
@PrimaryKey var primaryKey: String = ""
|
||||||
@PrimaryKey var primaryKey: String = "",
|
var sessionId: String? = null
|
||||||
var sessionId: String? = null,
|
var deviceKey: String? = null
|
||||||
var deviceKey: String? = null,
|
var olmSessionData: String? = null
|
||||||
var olmSessionData: String? = null,
|
var lastReceivedMessageTs: Long = 0
|
||||||
var lastReceivedMessageTs: Long = 0
|
|
||||||
) :
|
|
||||||
RealmModel {
|
|
||||||
|
|
||||||
fun getOlmSession(): OlmSession? {
|
fun getOlmSession(): OlmSession? {
|
||||||
return deserializeFromRealm(olmSessionData)
|
return deserializeFromRealm(olmSessionData)
|
||||||
|
@ -16,19 +16,16 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
|
||||||
import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm
|
import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm
|
||||||
import org.matrix.olm.OlmOutboundGroupSession
|
import org.matrix.olm.OlmOutboundGroupSession
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@RealmClass
|
internal class OutboundGroupSessionInfoEntity : RealmObject {
|
||||||
internal open class OutboundGroupSessionInfoEntity(
|
var serializedOutboundSessionData: String? = null
|
||||||
var serializedOutboundSessionData: String? = null,
|
var creationTime: Long? = null
|
||||||
var creationTime: Long? = null,
|
var shouldShareHistory: Boolean = false
|
||||||
var shouldShareHistory: Boolean = false
|
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
fun getOutboundGroupSession(): OlmOutboundGroupSession? {
|
fun getOutboundGroupSession(): OlmOutboundGroupSession? {
|
||||||
return try {
|
return try {
|
||||||
|
@ -18,11 +18,11 @@ package org.matrix.android.sdk.internal.crypto.store.db.model
|
|||||||
|
|
||||||
import com.squareup.moshi.JsonAdapter
|
import com.squareup.moshi.JsonAdapter
|
||||||
import com.squareup.moshi.Types
|
import com.squareup.moshi.Types
|
||||||
import io.realm.RealmList
|
|
||||||
import io.realm.RealmModel
|
|
||||||
import io.realm.annotations.Index
|
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import io.realm.kotlin.deleteFromRealm
|
import io.realm.kotlin.deleteFromRealm
|
||||||
|
import io.realm.kotlin.ext.realmListOf
|
||||||
|
import io.realm.kotlin.types.RealmList
|
||||||
|
import io.realm.kotlin.types.RealmObject
|
||||||
|
import io.realm.kotlin.types.annotations.Index
|
||||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.session.crypto.OutgoingKeyRequest
|
import org.matrix.android.sdk.api.session.crypto.OutgoingKeyRequest
|
||||||
import org.matrix.android.sdk.api.session.crypto.OutgoingRoomKeyRequestState
|
import org.matrix.android.sdk.api.session.crypto.OutgoingRoomKeyRequestState
|
||||||
@ -35,19 +35,17 @@ import org.matrix.android.sdk.api.session.events.model.content.RoomKeyWithHeldCo
|
|||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||||
|
|
||||||
@RealmClass
|
internal class OutgoingKeyRequestEntity : RealmObject {
|
||||||
internal open class OutgoingKeyRequestEntity(
|
@Index var requestId: String? = null
|
||||||
@Index var requestId: String? = null,
|
var requestedIndex: Int? = null
|
||||||
var requestedIndex: Int? = null,
|
var recipientsData: String? = null
|
||||||
var recipientsData: String? = null,
|
var requestedInfoStr: String? = null
|
||||||
var requestedInfoStr: String? = null,
|
var creationTimeStamp: Long? = null
|
||||||
var creationTimeStamp: Long? = null,
|
|
||||||
// de-normalization for better query (if not have to query all and parse json)
|
|
||||||
@Index var roomId: String? = null,
|
|
||||||
@Index var megolmSessionId: String? = null,
|
|
||||||
|
|
||||||
var replies: RealmList<KeyRequestReplyEntity> = RealmList()
|
// de-normalization for better query (if not have to query all and parse json)
|
||||||
) : RealmModel {
|
@Index var roomId: String? = null
|
||||||
|
@Index var megolmSessionId: String? = null
|
||||||
|
var replies: RealmList<KeyRequestReplyEntity> = realmListOf()
|
||||||
|
|
||||||
@Index private var requestStateStr: String = OutgoingRoomKeyRequestState.UNSENT.name
|
@Index private var requestStateStr: String = OutgoingRoomKeyRequestState.UNSENT.name
|
||||||
|
|
||||||
@ -87,11 +85,11 @@ internal open class OutgoingKeyRequestEntity(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addReply(userId: String, fromDevice: String?, event: Event) {
|
fun addReply(userId: String, fromDevice: String?, event: Event) {
|
||||||
val newReply = KeyRequestReplyEntity(
|
val newReply = KeyRequestReplyEntity().apply {
|
||||||
senderId = userId,
|
this.senderId = userId
|
||||||
fromDevice = fromDevice,
|
this.fromDevice = fromDevice
|
||||||
eventJson = MoshiProvider.providesMoshi().adapter(Event::class.java).toJson(event)
|
this.eventJson = MoshiProvider.providesMoshi().adapter(Event::class.java).toJson(event)
|
||||||
)
|
}
|
||||||
replies.add(newReply)
|
replies.add(newReply)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +131,10 @@ internal open class OutgoingKeyRequestEntity(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal fun OutgoingKeyRequestEntity.deleteOnCascade() {
|
internal fun OutgoingKeyRequestEntity.deleteOnCascade() {
|
||||||
replies.deleteAllFromRealm()
|
replies.deleteAllFromRealm()
|
||||||
deleteFromRealm()
|
deleteFromRealm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
@ -16,25 +16,22 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.Index
|
import io.realm.kotlin.types.annotations.Index
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep a record of to whom (user/device) a given session should have been shared.
|
* Keep a record of to whom (user/device) a given session should have been shared.
|
||||||
* It will be used to reply to keyshare requests from other users, in order to see if
|
* It will be used to reply to keyshare requests from other users, in order to see if
|
||||||
* this session was originaly shared with a given user
|
* this session was originaly shared with a given user
|
||||||
*/
|
*/
|
||||||
@RealmClass
|
internal class SharedSessionEntity : RealmObject {
|
||||||
internal open class SharedSessionEntity(
|
var roomId: String? = null
|
||||||
var roomId: String? = null,
|
var algorithm: String? = null
|
||||||
var algorithm: String? = null,
|
@Index var sessionId: String? = null
|
||||||
@Index var sessionId: String? = null,
|
@Index var userId: String? = null
|
||||||
@Index var userId: String? = null,
|
@Index var deviceId: String? = null
|
||||||
@Index var deviceId: String? = null,
|
@Index var deviceIdentityKey: String? = null
|
||||||
@Index var deviceIdentityKey: String? = null,
|
var chainIndex: Int? = null
|
||||||
var chainIndex: Int? = null
|
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,11 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
|
|
||||||
@RealmClass
|
internal class TrustLevelEntity : RealmObject {
|
||||||
internal open class TrustLevelEntity(
|
var crossSignedVerified: Boolean? = null
|
||||||
var crossSignedVerified: Boolean? = null,
|
var locallyVerified: Boolean? = null
|
||||||
var locallyVerified: Boolean? = null
|
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
|
|
||||||
|
@ -16,26 +16,25 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmList
|
import io.realm.kotlin.ext.realmListOf
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmList
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.RealmClass
|
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||||
import io.realm.kotlin.deleteFromRealm
|
|
||||||
import org.matrix.android.sdk.internal.extensions.clearWith
|
|
||||||
|
|
||||||
@RealmClass
|
internal class UserEntity : RealmObject {
|
||||||
internal open class UserEntity(
|
@PrimaryKey var userId: String? = null
|
||||||
@PrimaryKey var userId: String? = null,
|
var devices: RealmList<DeviceInfoEntity> = realmListOf()
|
||||||
var devices: RealmList<DeviceInfoEntity> = RealmList(),
|
var crossSigningInfoEntity: CrossSigningInfoEntity? = null
|
||||||
var crossSigningInfoEntity: CrossSigningInfoEntity? = null,
|
var deviceTrackingStatus: Int = 0
|
||||||
var deviceTrackingStatus: Int = 0
|
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal fun UserEntity.deleteOnCascade() {
|
internal fun UserEntity.deleteOnCascade() {
|
||||||
devices.clearWith { it.deleteOnCascade() }
|
devices.clearWith { it.deleteOnCascade() }
|
||||||
crossSigningInfoEntity?.deleteOnCascade()
|
crossSigningInfoEntity?.deleteOnCascade()
|
||||||
deleteFromRealm()
|
deleteFromRealm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.crypto.store.db.model
|
package org.matrix.android.sdk.internal.crypto.store.db.model
|
||||||
|
|
||||||
import io.realm.RealmModel
|
import io.realm.kotlin.types.RealmObject
|
||||||
import io.realm.annotations.Index
|
import io.realm.kotlin.types.annotations.Index
|
||||||
import io.realm.annotations.RealmClass
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.content.WithHeldCode
|
import org.matrix.android.sdk.api.session.events.model.content.WithHeldCode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,15 +27,13 @@ import org.matrix.android.sdk.api.session.events.model.content.WithHeldCode
|
|||||||
* For example, the sender may have blacklisted certain devices or users,
|
* For example, the sender may have blacklisted certain devices or users,
|
||||||
* or may be choosing to not send the megolm key to devices that they have not verified yet.
|
* or may be choosing to not send the megolm key to devices that they have not verified yet.
|
||||||
*/
|
*/
|
||||||
@RealmClass
|
internal class WithHeldSessionEntity : RealmObject {
|
||||||
internal open class WithHeldSessionEntity(
|
var roomId: String? = null
|
||||||
var roomId: String? = null,
|
var algorithm: String? = null
|
||||||
var algorithm: String? = null,
|
@Index var sessionId: String? = null
|
||||||
@Index var sessionId: String? = null,
|
@Index var senderKey: String? = null
|
||||||
@Index var senderKey: String? = null,
|
var codeString: String? = null
|
||||||
var codeString: String? = null,
|
var reason: String? = null
|
||||||
var reason: String? = null
|
|
||||||
) : RealmModel {
|
|
||||||
|
|
||||||
var code: WithHeldCode?
|
var code: WithHeldCode?
|
||||||
get() {
|
get() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user