mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-29 18:39:27 +01:00
Code review
This commit is contained in:
parent
4b3c5d5135
commit
19990b27bb
@ -89,7 +89,6 @@ internal class MXOlmDevice @Inject constructor(
|
||||
Timber.e(e, "MXOlmDevice : cannot initialize olmAccount")
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
olmUtility = OlmUtility()
|
||||
} catch (e: Exception) {
|
||||
@ -98,13 +97,13 @@ internal class MXOlmDevice @Inject constructor(
|
||||
}
|
||||
|
||||
try {
|
||||
deviceCurve25519Key = store.getAccount().identityKeys()[OlmAccount.JSON_KEY_IDENTITY_KEY]
|
||||
deviceCurve25519Key = store.getOlmAccount().identityKeys()[OlmAccount.JSON_KEY_IDENTITY_KEY]
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## MXOlmDevice : cannot find ${OlmAccount.JSON_KEY_IDENTITY_KEY} with error")
|
||||
}
|
||||
|
||||
try {
|
||||
deviceEd25519Key = store.getAccount().identityKeys()[OlmAccount.JSON_KEY_FINGER_PRINT_KEY]
|
||||
deviceEd25519Key = store.getOlmAccount().identityKeys()[OlmAccount.JSON_KEY_FINGER_PRINT_KEY]
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## MXOlmDevice : cannot find ${OlmAccount.JSON_KEY_FINGER_PRINT_KEY} with error")
|
||||
}
|
||||
@ -115,7 +114,7 @@ internal class MXOlmDevice @Inject constructor(
|
||||
*/
|
||||
fun getOneTimeKeys(): Map<String, Map<String, String>>? {
|
||||
try {
|
||||
return store.getAccount().oneTimeKeys()
|
||||
return store.getOlmAccount().oneTimeKeys()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## getOneTimeKeys() : failed")
|
||||
}
|
||||
@ -127,7 +126,7 @@ internal class MXOlmDevice @Inject constructor(
|
||||
* @return The maximum number of one-time keys the olm account can store.
|
||||
*/
|
||||
fun getMaxNumberOfOneTimeKeys(): Long {
|
||||
return store.getAccount().maxOneTimeKeys()
|
||||
return store.getOlmAccount().maxOneTimeKeys()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,7 +144,7 @@ internal class MXOlmDevice @Inject constructor(
|
||||
*/
|
||||
fun signMessage(message: String): String? {
|
||||
try {
|
||||
return store.getAccount().signMessage(message)
|
||||
return store.getOlmAccount().signMessage(message)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## signMessage() : failed")
|
||||
}
|
||||
@ -158,8 +157,8 @@ internal class MXOlmDevice @Inject constructor(
|
||||
*/
|
||||
fun markKeysAsPublished() {
|
||||
try {
|
||||
store.getAccount().markOneTimeKeysAsPublished()
|
||||
store.saveAccount()
|
||||
store.getOlmAccount().markOneTimeKeysAsPublished()
|
||||
store.saveOlmAccount()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## markKeysAsPublished() : failed")
|
||||
}
|
||||
@ -172,8 +171,8 @@ internal class MXOlmDevice @Inject constructor(
|
||||
*/
|
||||
fun generateOneTimeKeys(numKeys: Int) {
|
||||
try {
|
||||
store.getAccount().generateOneTimeKeys(numKeys)
|
||||
store.saveAccount()
|
||||
store.getOlmAccount().generateOneTimeKeys(numKeys)
|
||||
store.saveOlmAccount()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## generateOneTimeKeys() : failed")
|
||||
}
|
||||
@ -193,7 +192,7 @@ internal class MXOlmDevice @Inject constructor(
|
||||
|
||||
try {
|
||||
olmSession = OlmSession()
|
||||
olmSession.initOutboundSession(store.getAccount(), theirIdentityKey, theirOneTimeKey)
|
||||
olmSession.initOutboundSession(store.getOlmAccount(), theirIdentityKey, theirOneTimeKey)
|
||||
|
||||
val olmSessionWrapper = OlmSessionWrapper(olmSession, 0)
|
||||
|
||||
@ -233,7 +232,7 @@ internal class MXOlmDevice @Inject constructor(
|
||||
try {
|
||||
try {
|
||||
olmSession = OlmSession()
|
||||
olmSession.initInboundSessionFrom(store.getAccount(), theirDeviceIdentityKey, ciphertext)
|
||||
olmSession.initInboundSessionFrom(store.getOlmAccount(), theirDeviceIdentityKey, ciphertext)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## createInboundSession() : the session creation failed")
|
||||
return null
|
||||
@ -242,8 +241,8 @@ internal class MXOlmDevice @Inject constructor(
|
||||
Timber.v("## createInboundSession() : sessionId: ${olmSession.sessionIdentifier()}")
|
||||
|
||||
try {
|
||||
store.getAccount().removeOneTimeKeys(olmSession)
|
||||
store.saveAccount()
|
||||
store.getOlmAccount().removeOneTimeKeys(olmSession)
|
||||
store.saveOlmAccount()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## createInboundSession() : removeOneTimeKeys failed")
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ internal interface IMXCryptoStore {
|
||||
/**
|
||||
* @return the olm account
|
||||
*/
|
||||
fun getAccount(): OlmAccount
|
||||
|
||||
fun getOlmAccount(): OlmAccount
|
||||
|
||||
fun getOrCreateOlmAccount(): OlmAccount
|
||||
|
||||
@ -162,7 +161,7 @@ internal interface IMXCryptoStore {
|
||||
*
|
||||
* @param account the account to save
|
||||
*/
|
||||
fun saveAccount()
|
||||
fun saveOlmAccount()
|
||||
|
||||
/**
|
||||
* Store a device for a user.
|
||||
|
@ -122,7 +122,6 @@ internal class RealmCryptoStore @Inject constructor(
|
||||
.setRealmConfiguration(realmConfiguration)
|
||||
.build()
|
||||
|
||||
|
||||
init {
|
||||
// Ensure CryptoMetadataEntity is inserted in DB
|
||||
doRealmTransaction(realmConfiguration) { realm ->
|
||||
@ -205,13 +204,13 @@ internal class RealmCryptoStore @Inject constructor(
|
||||
}?.deviceId ?: ""
|
||||
}
|
||||
|
||||
override fun saveAccount() {
|
||||
override fun saveOlmAccount() {
|
||||
doRealmTransaction(realmConfiguration) {
|
||||
it.where<CryptoMetadataEntity>().findFirst()?.putOlmAccount(olmAccount)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAccount(): OlmAccount {
|
||||
override fun getOlmAccount(): OlmAccount {
|
||||
return olmAccount!!
|
||||
}
|
||||
|
||||
@ -232,7 +231,6 @@ internal class RealmCryptoStore @Inject constructor(
|
||||
return olmAccount!!
|
||||
}
|
||||
|
||||
|
||||
override fun storeUserDevice(userId: String?, deviceInfo: CryptoDeviceInfo?) {
|
||||
if (userId == null || deviceInfo == null) {
|
||||
return
|
||||
|
@ -51,7 +51,7 @@ internal class DefaultUploadKeysTask @Inject constructor(
|
||||
oneTimeKeys = params.oneTimeKeys
|
||||
)
|
||||
|
||||
Timber.i("## Uploading device keys -> ${body}")
|
||||
Timber.i("## Uploading device keys -> $body")
|
||||
|
||||
return executeRequest(eventBus) {
|
||||
apiCall = if (encodedDeviceId.isBlank()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user