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 var olmMachine: OlmMachine? = null
// The verification service.
private var verificationService: RustVerificationService? = null
@ -361,7 +362,7 @@ internal class DefaultCryptoService @Inject constructor(
* devices.
*
*/
suspend fun start() {
fun start() {
internalStart()
// Just update
fetchDevicesList(NoOpMatrixCallback())
@ -383,7 +384,7 @@ internal class DefaultCryptoService @Inject constructor(
}
}
private suspend fun internalStart() {
private fun internalStart() {
if (isStarted.get() || isStarting.get()) {
return
}
@ -392,8 +393,8 @@ internal class DefaultCryptoService @Inject constructor(
try {
setRustLogger()
val machine = OlmMachine(userId, deviceId!!, dataDir, deviceObserver)
this.olmMachine = machine
this.verificationService = RustVerificationService(machine, this.sender)
olmMachine = machine
verificationService = RustVerificationService(machine, this.sender)
Timber.v(
"## CRYPTO | Successfully started up an Olm machine for " +
"${userId}, ${deviceId}, identity keys: ${this.olmMachine?.identityKeys()}")
@ -404,18 +405,8 @@ internal class DefaultCryptoService @Inject constructor(
// Open the store
cryptoStore.open()
runCatching {
}.fold(
{
isStarting.set(false)
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
// above conclusion is correct.
if (verificationService == null) {
runBlocking {
internalStart()
}
}
return verificationService!!
}
@ -800,7 +789,8 @@ internal class DefaultCryptoService @Inject constructor(
is Request.KeysClaim -> {
claimKeys(request)
}
else -> {}
else -> {
}
}
}
}