mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Merge pull request #291 from vector-im/feature/start_crypto_earlier
Start crypto manager before handling first sync events
This commit is contained in:
commit
9cdecced57
2 changed files with 9 additions and 9 deletions
|
@ -242,16 +242,16 @@ internal class CryptoManager @Inject constructor(
|
||||||
* @param isInitialSync true if it starts from an initial sync
|
* @param isInitialSync true if it starts from an initial sync
|
||||||
*/
|
*/
|
||||||
fun start(isInitialSync: Boolean) {
|
fun start(isInitialSync: Boolean) {
|
||||||
|
if (isStarted.get() || isStarting.get()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isStarting.set(true)
|
||||||
CoroutineScope(coroutineDispatchers.crypto).launch {
|
CoroutineScope(coroutineDispatchers.crypto).launch {
|
||||||
internalStart(isInitialSync)
|
internalStart(isInitialSync)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun internalStart(isInitialSync: Boolean) {
|
private suspend fun internalStart(isInitialSync: Boolean) {
|
||||||
if (isStarted.get() || isStarting.get()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isStarting.set(true)
|
|
||||||
// Open the store
|
// Open the store
|
||||||
cryptoStore.open()
|
cryptoStore.open()
|
||||||
uploadDeviceKeys()
|
uploadDeviceKeys()
|
||||||
|
|
|
@ -33,6 +33,11 @@ internal class SyncResponseHandler @Inject constructor(private val roomSyncHandl
|
||||||
fun handleResponse(syncResponse: SyncResponse, fromToken: String?, isCatchingUp: Boolean): Try<SyncResponse> {
|
fun handleResponse(syncResponse: SyncResponse, fromToken: String?, isCatchingUp: Boolean): Try<SyncResponse> {
|
||||||
return Try {
|
return Try {
|
||||||
Timber.v("Start handling sync")
|
Timber.v("Start handling sync")
|
||||||
|
val isInitialSync = fromToken == null
|
||||||
|
if (!cryptoManager.isStarted()) {
|
||||||
|
Timber.v("Should start cryptoManager")
|
||||||
|
cryptoManager.start(isInitialSync)
|
||||||
|
}
|
||||||
val measure = measureTimeMillis {
|
val measure = measureTimeMillis {
|
||||||
// Handle the to device events before the room ones
|
// Handle the to device events before the room ones
|
||||||
// to ensure to decrypt them properly
|
// to ensure to decrypt them properly
|
||||||
|
@ -55,11 +60,6 @@ internal class SyncResponseHandler @Inject constructor(private val roomSyncHandl
|
||||||
Timber.v("On sync completed")
|
Timber.v("On sync completed")
|
||||||
cryptoSyncHandler.onSyncCompleted(syncResponse)
|
cryptoSyncHandler.onSyncCompleted(syncResponse)
|
||||||
}
|
}
|
||||||
val isInitialSync = fromToken == null
|
|
||||||
if (!cryptoManager.isStarted()) {
|
|
||||||
Timber.v("Should start cryptoManager")
|
|
||||||
cryptoManager.start(isInitialSync)
|
|
||||||
}
|
|
||||||
Timber.v("Finish handling sync in $measure ms")
|
Timber.v("Finish handling sync in $measure ms")
|
||||||
syncResponse
|
syncResponse
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue