Small cleanup and format

This commit is contained in:
Benoit Marty 2021-07-08 17:14:45 +02:00
parent d4090c4b0a
commit 54c3b4192e

View file

@ -228,6 +228,7 @@ internal class DefaultCryptoService @Inject constructor(
private val isStarted = AtomicBoolean(false) private val isStarted = AtomicBoolean(false)
private var olmMachine: OlmMachine? = null private var olmMachine: OlmMachine? = null
// The verification service. // The verification service.
private var verificationService: RustVerificationService? = null private var verificationService: RustVerificationService? = null
@ -361,7 +362,7 @@ internal class DefaultCryptoService @Inject constructor(
* devices. * devices.
* *
*/ */
suspend fun start() { fun start() {
internalStart() internalStart()
// Just update // Just update
fetchDevicesList(NoOpMatrixCallback()) fetchDevicesList(NoOpMatrixCallback())
@ -383,7 +384,7 @@ internal class DefaultCryptoService @Inject constructor(
} }
} }
private suspend fun internalStart() { private fun internalStart() {
if (isStarted.get() || isStarting.get()) { if (isStarted.get() || isStarting.get()) {
return return
} }
@ -392,8 +393,8 @@ internal class DefaultCryptoService @Inject constructor(
try { try {
setRustLogger() setRustLogger()
val machine = OlmMachine(userId, deviceId!!, dataDir, deviceObserver) val machine = OlmMachine(userId, deviceId!!, dataDir, deviceObserver)
this.olmMachine = machine olmMachine = machine
this.verificationService = RustVerificationService(machine, this.sender) verificationService = RustVerificationService(machine, this.sender)
Timber.v( Timber.v(
"## CRYPTO | Successfully started up an Olm machine for " + "## CRYPTO | Successfully started up an Olm machine for " +
"${userId}, ${deviceId}, identity keys: ${this.olmMachine?.identityKeys()}") "${userId}, ${deviceId}, identity keys: ${this.olmMachine?.identityKeys()}")
@ -404,18 +405,8 @@ internal class DefaultCryptoService @Inject constructor(
// Open the store // Open the store
cryptoStore.open() cryptoStore.open()
runCatching {
}.fold(
{
isStarting.set(false) isStarting.set(false)
isStarted.set(true) isStarted.set(true)
},
{
isStarting.set(false)
isStarted.set(false)
Timber.e(it, "Start failed")
}
)
} }
/** /**
@ -456,10 +447,8 @@ internal class DefaultCryptoService @Inject constructor(
// Let's initialize here as a workaround until we figure out if the // Let's initialize here as a workaround until we figure out if the
// above conclusion is correct. // above conclusion is correct.
if (verificationService == null) { if (verificationService == null) {
runBlocking {
internalStart() internalStart()
} }
}
return verificationService!! return verificationService!!
} }
@ -800,7 +789,8 @@ internal class DefaultCryptoService @Inject constructor(
is Request.KeysClaim -> { is Request.KeysClaim -> {
claimKeys(request) claimKeys(request)
} }
else -> {} else -> {
}
} }
} }
} }