Convert AccountDataService to suspend functions
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
This commit is contained in:
parent
b70585016c
commit
7aba3cff66
@ -17,9 +17,7 @@
|
||||
package org.matrix.android.sdk.api.session.accountdata
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.events.model.Content
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
|
||||
interface AccountDataService {
|
||||
@ -48,5 +46,5 @@ interface AccountDataService {
|
||||
/**
|
||||
* Update the account data with the provided type and the provided account data content
|
||||
*/
|
||||
fun updateAccountData(type: String, content: Content, callback: MatrixCallback<Unit>? = null): Cancelable
|
||||
suspend fun updateAccountData(type: String, content: Content)
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ import org.matrix.android.sdk.internal.di.UserId
|
||||
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||
import org.matrix.olm.OlmPkMessage
|
||||
import java.security.SecureRandom
|
||||
import javax.crypto.Cipher
|
||||
@ -85,9 +84,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||
)
|
||||
} ?: storageKeyContent
|
||||
|
||||
awaitCallback<Unit> {
|
||||
accountDataService.updateAccountData("$KEY_ID_BASE.$keyId", signedContent.toContent(), it)
|
||||
}
|
||||
accountDataService.updateAccountData("$KEY_ID_BASE.$keyId", signedContent.toContent())
|
||||
SsssKeyCreationInfo(
|
||||
keyId = keyId,
|
||||
content = storageKeyContent,
|
||||
@ -116,13 +113,10 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||
)
|
||||
} ?: storageKeyContent
|
||||
|
||||
awaitCallback<Unit> {
|
||||
accountDataService.updateAccountData(
|
||||
"$KEY_ID_BASE.$keyId",
|
||||
signedContent.toContent(),
|
||||
it
|
||||
)
|
||||
}
|
||||
accountDataService.updateAccountData(
|
||||
"$KEY_ID_BASE.$keyId",
|
||||
signedContent.toContent()
|
||||
)
|
||||
SsssKeyCreationInfo(
|
||||
keyId = keyId,
|
||||
content = storageKeyContent,
|
||||
@ -149,12 +143,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||
override suspend fun setDefaultKey(keyId: String) {
|
||||
val existingKey = getKey(keyId)
|
||||
if (existingKey is KeyInfoResult.Success) {
|
||||
awaitCallback<Unit> {
|
||||
accountDataService.updateAccountData(DEFAULT_KEY_ID,
|
||||
mapOf("key" to keyId),
|
||||
it
|
||||
)
|
||||
}
|
||||
accountDataService.updateAccountData(DEFAULT_KEY_ID, mapOf("key" to keyId))
|
||||
} else {
|
||||
throw SharedSecretStorageError.UnknownKey(keyId)
|
||||
}
|
||||
@ -189,15 +178,10 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
awaitCallback<Unit> {
|
||||
accountDataService.updateAccountData(
|
||||
type = name,
|
||||
content = mapOf(
|
||||
"encrypted" to encryptedContents
|
||||
),
|
||||
callback = it
|
||||
)
|
||||
}
|
||||
accountDataService.updateAccountData(
|
||||
type = name,
|
||||
content = mapOf("encrypted" to encryptedContents)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,16 +18,15 @@ package org.matrix.android.sdk.internal.session.user.accountdata
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
||||
import org.matrix.android.sdk.api.session.events.model.Content
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.session.sync.UserAccountDataSyncHandler
|
||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent
|
||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
||||
import org.matrix.android.sdk.internal.task.configureWith
|
||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultAccountDataService @Inject constructor(
|
||||
@ -54,26 +53,18 @@ internal class DefaultAccountDataService @Inject constructor(
|
||||
return accountDataDataSource.getLiveAccountDataEvents(types)
|
||||
}
|
||||
|
||||
override fun updateAccountData(type: String, content: Content, callback: MatrixCallback<Unit>?): Cancelable {
|
||||
return updateUserAccountDataTask.configureWith(UpdateUserAccountDataTask.AnyParams(
|
||||
type = type,
|
||||
any = content
|
||||
)) {
|
||||
this.retryCount = 5
|
||||
this.callback = object : MatrixCallback<Unit> {
|
||||
override fun onSuccess(data: Unit) {
|
||||
// TODO Move that to the task (but it created a circular dependencies...)
|
||||
monarchy.runTransactionSync { realm ->
|
||||
userAccountDataSyncHandler.handleGenericAccountData(realm, type, content)
|
||||
}
|
||||
callback?.onSuccess(data)
|
||||
}
|
||||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
callback?.onFailure(failure)
|
||||
}
|
||||
override suspend fun updateAccountData(type: String, content: Content) {
|
||||
val params = UpdateUserAccountDataTask.AnyParams(type = type, any = content)
|
||||
awaitCallback<Unit> { callback ->
|
||||
updateUserAccountDataTask.configureWith(params) {
|
||||
this.retryCount = 5 // TODO: Need to refactor retrying out into a helper method.
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
}
|
||||
// TODO Move that to the task (but it created a circular dependencies...)
|
||||
monarchy.runTransactionSync { realm ->
|
||||
userAccountDataSyncHandler.handleGenericAccountData(realm, type, content)
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import im.vector.app.core.platform.VectorViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent
|
||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||
import org.matrix.android.sdk.rx.rx
|
||||
|
||||
data class AccountDataViewState(
|
||||
@ -58,9 +57,7 @@ class AccountDataViewModel @AssistedInject constructor(@Assisted initialState: A
|
||||
|
||||
private fun handleDeleteAccountData(action: AccountDataAction.DeleteAccountData) {
|
||||
viewModelScope.launch {
|
||||
awaitCallback {
|
||||
session.updateAccountData(action.type, emptyMap(), it)
|
||||
}
|
||||
session.updateAccountData(action.type, emptyMap())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,11 +283,12 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
|
||||
"type" to "m.widget"
|
||||
)
|
||||
)
|
||||
session.updateAccountData(
|
||||
type = UserAccountDataTypes.TYPE_WIDGETS,
|
||||
content = addUserWidgetBody,
|
||||
callback = createWidgetAPICallback(widgetPostAPIMediator, eventData)
|
||||
)
|
||||
launchWidgetAPIAction(widgetPostAPIMediator, eventData) {
|
||||
session.updateAccountData(
|
||||
type = UserAccountDataTypes.TYPE_WIDGETS,
|
||||
content = addUserWidgetBody
|
||||
)
|
||||
}
|
||||
} else {
|
||||
session.widgetService().createRoomWidget(
|
||||
roomId = roomId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user