Merge pull request #208 from ouchadam/bug/importing-keys-fails-first-time

Room key imports failing the first time
This commit is contained in:
Adam Brown 2022-10-17 23:12:11 +01:00 committed by GitHub
commit 146e30193f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -14,6 +14,8 @@ import com.squareup.sqldelight.TransactionWithoutReturn
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
class OlmPersistence( class OlmPersistence(
private val database: DapkDb, private val database: DapkDb,
@ -83,11 +85,13 @@ class OlmPersistence(
} }
suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) { suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) {
val scope = CoroutineScope(dispatchers.io) val transaction = suspendCoroutine { continuation ->
database.cryptoQueries.transaction { database.cryptoQueries.transaction {
scope.launch { action() } continuation.resume(this)
} }
} }
action(transaction)
}
suspend fun persist(sessionId: SessionId, inboundGroupSession: SerializedObject) { suspend fun persist(sessionId: SessionId, inboundGroupSession: SerializedObject) {
withContext(dispatchers.io) { withContext(dispatchers.io) {