Merge pull request #3069 from Dominaezzz/suspend_functions_1

Convert IdentityService to suspend functions
This commit is contained in:
Benoit Marty 2021-03-30 09:48:03 +02:00 committed by GitHub
commit 842a430d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 167 deletions

View File

@ -16,9 +16,6 @@
package org.matrix.android.sdk.api.session.identity package org.matrix.android.sdk.api.session.identity
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Cancelable
/** /**
* Provides access to the identity server configuration and services identity server can provide * Provides access to the identity server configuration and services identity server can provide
*/ */
@ -40,55 +37,55 @@ interface IdentityService {
* See https://matrix.org/docs/spec/identity_service/latest#status-check * See https://matrix.org/docs/spec/identity_service/latest#status-check
* RiotX SDK only supports identity server API v2 * RiotX SDK only supports identity server API v2
*/ */
fun isValidIdentityServer(url: String, callback: MatrixCallback<Unit>): Cancelable suspend fun isValidIdentityServer(url: String)
/** /**
* Update the identity server url. * Update the identity server url.
* If successful, any previous identity server will be disconnected. * If successful, any previous identity server will be disconnected.
* In case of error, any previous identity server will remain configured. * In case of error, any previous identity server will remain configured.
* @param url the new url. * @param url the new url.
* @param callback will notify the user if change is successful. The String will be the final url of the identity server. * @return The String will be the final url of the identity server.
* The SDK can prepend "https://" for instance. * The SDK can prepend "https://" for instance.
*/ */
fun setNewIdentityServer(url: String, callback: MatrixCallback<String>): Cancelable suspend fun setNewIdentityServer(url: String): String
/** /**
* Disconnect (logout) from the current identity server * Disconnect (logout) from the current identity server
*/ */
fun disconnect(callback: MatrixCallback<Unit>): Cancelable suspend fun disconnect()
/** /**
* This will ask the identity server to send an email or an SMS to let the user confirm he owns the ThreePid * This will ask the identity server to send an email or an SMS to let the user confirm he owns the ThreePid
*/ */
fun startBindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable suspend fun startBindThreePid(threePid: ThreePid)
/** /**
* This will cancel a pending binding of threePid. * This will cancel a pending binding of threePid.
*/ */
fun cancelBindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable suspend fun cancelBindThreePid(threePid: ThreePid)
/** /**
* This will ask the identity server to send an new email or a new SMS to let the user confirm he owns the ThreePid * This will ask the identity server to send an new email or a new SMS to let the user confirm he owns the ThreePid
*/ */
fun sendAgainValidationCode(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable suspend fun sendAgainValidationCode(threePid: ThreePid)
/** /**
* Submit the code that the identity server has sent to the user (in email or SMS) * Submit the code that the identity server has sent to the user (in email or SMS)
* Once successful, you will have to call [finalizeBindThreePid] * Once successful, you will have to call [finalizeBindThreePid]
* @param code the code sent to the user * @param code the code sent to the user
*/ */
fun submitValidationToken(threePid: ThreePid, code: String, callback: MatrixCallback<Unit>): Cancelable suspend fun submitValidationToken(threePid: ThreePid, code: String)
/** /**
* This will perform the actual association of ThreePid and Matrix account * This will perform the actual association of ThreePid and Matrix account
*/ */
fun finalizeBindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable suspend fun finalizeBindThreePid(threePid: ThreePid)
/** /**
* Unbind a threePid * Unbind a threePid
* The request will actually be done on the homeserver * The request will actually be done on the homeserver
*/ */
fun unbindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable suspend fun unbindThreePid(threePid: ThreePid)
/** /**
* Search MatrixId of users providing email and phone numbers * Search MatrixId of users providing email and phone numbers
@ -96,7 +93,7 @@ interface IdentityService {
* Application has to explicitly ask for the user consent, and the answer can be stored using [setUserConsent] * Application has to explicitly ask for the user consent, and the answer can be stored using [setUserConsent]
* Please see https://support.google.com/googleplay/android-developer/answer/9888076?hl=en for more details. * Please see https://support.google.com/googleplay/android-developer/answer/9888076?hl=en for more details.
*/ */
fun lookUp(threePids: List<ThreePid>, callback: MatrixCallback<List<FoundThreePid>>): Cancelable suspend fun lookUp(threePids: List<ThreePid>): List<FoundThreePid>
/** /**
* Return the current user consent for the current identity server, which has been stored using [setUserConsent]. * Return the current user consent for the current identity server, which has been stored using [setUserConsent].
@ -120,9 +117,9 @@ interface IdentityService {
* A lookup will be performed, but also pending binding state will be restored * A lookup will be performed, but also pending binding state will be restored
* *
* @param threePids the list of threePid the user owns (retrieved form the homeserver) * @param threePids the list of threePid the user owns (retrieved form the homeserver)
* @param callback onSuccess will be called with a map of ThreePid -> SharedState * @return a map of ThreePid -> SharedState
*/ */
fun getShareStatus(threePids: List<ThreePid>, callback: MatrixCallback<Map<ThreePid, SharedState>>): Cancelable suspend fun getShareStatus(threePids: List<ThreePid>): Map<ThreePid, SharedState>
fun addListener(listener: IdentityServiceListener) fun addListener(listener: IdentityServiceListener)
fun removeListener(listener: IdentityServiceListener) fun removeListener(listener: IdentityServiceListener)

View File

@ -20,7 +20,6 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry import androidx.lifecycle.LifecycleRegistry
import dagger.Lazy import dagger.Lazy
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.auth.data.SessionParams import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
@ -33,8 +32,6 @@ import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener import org.matrix.android.sdk.api.session.identity.IdentityServiceListener
import org.matrix.android.sdk.api.session.identity.SharedState import org.matrix.android.sdk.api.session.identity.SharedState
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.api.util.NoOpCancellable
import org.matrix.android.sdk.internal.di.AuthenticatedIdentity import org.matrix.android.sdk.internal.di.AuthenticatedIdentity
import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate
import org.matrix.android.sdk.internal.extensions.observeNotNull import org.matrix.android.sdk.internal.extensions.observeNotNull
@ -49,8 +46,6 @@ import org.matrix.android.sdk.internal.session.sync.model.accountdata.IdentitySe
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
import org.matrix.android.sdk.internal.session.user.accountdata.AccountDataDataSource import org.matrix.android.sdk.internal.session.user.accountdata.AccountDataDataSource
import org.matrix.android.sdk.internal.session.user.accountdata.UpdateUserAccountDataTask import org.matrix.android.sdk.internal.session.user.accountdata.UpdateUserAccountDataTask
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.launchToCallback
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
import org.matrix.android.sdk.internal.util.ensureProtocol import org.matrix.android.sdk.internal.util.ensureProtocol
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -83,8 +78,7 @@ internal class DefaultIdentityService @Inject constructor(
private val identityApiProvider: IdentityApiProvider, private val identityApiProvider: IdentityApiProvider,
private val accountDataDataSource: AccountDataDataSource, private val accountDataDataSource: AccountDataDataSource,
private val homeServerCapabilitiesService: HomeServerCapabilitiesService, private val homeServerCapabilitiesService: HomeServerCapabilitiesService,
private val sessionParams: SessionParams, private val sessionParams: SessionParams
private val taskExecutor: TaskExecutor
) : IdentityService, SessionLifecycleObserver { ) : IdentityService, SessionLifecycleObserver {
private val lifecycleOwner: LifecycleOwner = LifecycleOwner { lifecycleRegistry } private val lifecycleOwner: LifecycleOwner = LifecycleOwner { lifecycleRegistry }
@ -136,79 +130,59 @@ internal class DefaultIdentityService @Inject constructor(
return identityStore.getIdentityData()?.identityServerUrl return identityStore.getIdentityData()?.identityServerUrl
} }
override fun startBindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable { override suspend fun startBindThreePid(threePid: ThreePid) {
if (homeServerCapabilitiesService.getHomeServerCapabilities().lastVersionIdentityServerSupported.not()) { if (homeServerCapabilitiesService.getHomeServerCapabilities().lastVersionIdentityServerSupported.not()) {
callback.onFailure(IdentityServiceError.OutdatedHomeServer) throw IdentityServiceError.OutdatedHomeServer
return NoOpCancellable
} }
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
identityRequestTokenForBindingTask.execute(IdentityRequestTokenForBindingTask.Params(threePid, false)) identityRequestTokenForBindingTask.execute(IdentityRequestTokenForBindingTask.Params(threePid, false))
} }
}
override fun cancelBindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable { override suspend fun cancelBindThreePid(threePid: ThreePid) {
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
identityStore.deletePendingBinding(threePid) identityStore.deletePendingBinding(threePid)
} }
}
override fun sendAgainValidationCode(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable { override suspend fun sendAgainValidationCode(threePid: ThreePid) {
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
identityRequestTokenForBindingTask.execute(IdentityRequestTokenForBindingTask.Params(threePid, true)) identityRequestTokenForBindingTask.execute(IdentityRequestTokenForBindingTask.Params(threePid, true))
} }
}
override fun finalizeBindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable { override suspend fun finalizeBindThreePid(threePid: ThreePid) {
if (homeServerCapabilitiesService.getHomeServerCapabilities().lastVersionIdentityServerSupported.not()) { if (homeServerCapabilitiesService.getHomeServerCapabilities().lastVersionIdentityServerSupported.not()) {
callback.onFailure(IdentityServiceError.OutdatedHomeServer) throw IdentityServiceError.OutdatedHomeServer
return NoOpCancellable
} }
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
bindThreePidsTask.execute(BindThreePidsTask.Params(threePid)) bindThreePidsTask.execute(BindThreePidsTask.Params(threePid))
} }
}
override fun submitValidationToken(threePid: ThreePid, code: String, callback: MatrixCallback<Unit>): Cancelable { override suspend fun submitValidationToken(threePid: ThreePid, code: String) {
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
submitTokenForBindingTask.execute(IdentitySubmitTokenForBindingTask.Params(threePid, code)) submitTokenForBindingTask.execute(IdentitySubmitTokenForBindingTask.Params(threePid, code))
} }
}
override fun unbindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable { override suspend fun unbindThreePid(threePid: ThreePid) {
if (homeServerCapabilitiesService.getHomeServerCapabilities().lastVersionIdentityServerSupported.not()) { if (homeServerCapabilitiesService.getHomeServerCapabilities().lastVersionIdentityServerSupported.not()) {
callback.onFailure(IdentityServiceError.OutdatedHomeServer) throw IdentityServiceError.OutdatedHomeServer
return NoOpCancellable
} }
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
unbindThreePidsTask.execute(UnbindThreePidsTask.Params(threePid)) unbindThreePidsTask.execute(UnbindThreePidsTask.Params(threePid))
} }
}
override fun isValidIdentityServer(url: String, callback: MatrixCallback<Unit>): Cancelable { override suspend fun isValidIdentityServer(url: String) {
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
val api = retrofitFactory.create(unauthenticatedOkHttpClient, url).create(IdentityAuthAPI::class.java) val api = retrofitFactory.create(unauthenticatedOkHttpClient, url).create(IdentityAuthAPI::class.java)
identityPingTask.execute(IdentityPingTask.Params(api)) identityPingTask.execute(IdentityPingTask.Params(api))
} }
}
override fun disconnect(callback: MatrixCallback<Unit>): Cancelable { override suspend fun disconnect() {
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
identityDisconnectTask.execute(Unit) identityDisconnectTask.execute(Unit)
identityStore.setUrl(null) identityStore.setUrl(null)
updateIdentityAPI(null) updateIdentityAPI(null)
updateAccountData(null) updateAccountData(null)
} }
}
override fun setNewIdentityServer(url: String, callback: MatrixCallback<String>): Cancelable { override suspend fun setNewIdentityServer(url: String): String {
val urlCandidate = url.ensureProtocol() val urlCandidate = url.ensureProtocol()
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
val current = getCurrentIdentityServerUrl() val current = getCurrentIdentityServerUrl()
if (urlCandidate == current) { if (urlCandidate == current) {
// Nothing to do // Nothing to do
@ -229,8 +203,8 @@ internal class DefaultIdentityService @Inject constructor(
updateAccountData(urlCandidate) updateAccountData(urlCandidate)
} }
urlCandidate
} return urlCandidate
} }
private suspend fun updateAccountData(url: String?) { private suspend fun updateAccountData(url: String?) {
@ -252,35 +226,29 @@ internal class DefaultIdentityService @Inject constructor(
identityStore.setUserConsent(newValue) identityStore.setUserConsent(newValue)
} }
override fun lookUp(threePids: List<ThreePid>, callback: MatrixCallback<List<FoundThreePid>>): Cancelable { override suspend fun lookUp(threePids: List<ThreePid>): List<FoundThreePid> {
if (!getUserConsent()) { if (!getUserConsent()) {
callback.onFailure(IdentityServiceError.UserConsentNotProvided) throw IdentityServiceError.UserConsentNotProvided
return NoOpCancellable
} }
if (threePids.isEmpty()) { if (threePids.isEmpty()) {
callback.onSuccess(emptyList()) return emptyList()
return NoOpCancellable
} }
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) { return lookUpInternal(true, threePids)
lookUpInternal(true, threePids)
}
} }
override fun getShareStatus(threePids: List<ThreePid>, callback: MatrixCallback<Map<ThreePid, SharedState>>): Cancelable { override suspend fun getShareStatus(threePids: List<ThreePid>): Map<ThreePid, SharedState> {
// Note: we do not require user consent here, because it is used for emails and phone numbers that the user has already sent // Note: we do not require user consent here, because it is used for emails and phone numbers that the user has already sent
// to the home server, and not emails and phone numbers from the contact book of the user // to the home server, and not emails and phone numbers from the contact book of the user
if (threePids.isEmpty()) { if (threePids.isEmpty()) {
callback.onSuccess(emptyMap()) return emptyMap()
return NoOpCancellable
} }
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
val lookupResult = lookUpInternal(true, threePids) val lookupResult = lookUpInternal(true, threePids)
threePids.associateWith { threePid -> return threePids.associateWith { threePid ->
// If not in lookup result, check if there is a pending binding // If not in lookup result, check if there is a pending binding
if (lookupResult.firstOrNull { it.threePid == threePid } == null) { if (lookupResult.firstOrNull { it.threePid == threePid } == null) {
if (identityStore.getPendingBinding(threePid) == null) { if (identityStore.getPendingBinding(threePid) == null) {
@ -293,7 +261,6 @@ internal class DefaultIdentityService @Inject constructor(
} }
} }
} }
}
private suspend fun lookUpInternal(canRetry: Boolean, threePids: List<ThreePid>): List<FoundThreePid> { private suspend fun lookUpInternal(canRetry: Boolean, threePids: List<ThreePid>): List<FoundThreePid> {
ensureIdentityTokenTask.execute(Unit) ensureIdentityTokenTask.execute(Unit)

View File

@ -33,9 +33,7 @@ import im.vector.app.core.platform.EmptyViewEvents
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.identity.FoundThreePid
import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import timber.log.Timber import timber.log.Timber
@ -101,17 +99,19 @@ class ContactsBookViewModel @AssistedInject constructor(@Assisted
} }
} }
private fun performLookup(data: List<MappedContact>) { private fun performLookup(contacts: List<MappedContact>) {
if (!session.identityService().getUserConsent()) { if (!session.identityService().getUserConsent()) {
return return
} }
viewModelScope.launch { viewModelScope.launch {
val threePids = data.flatMap { contact -> val threePids = contacts.flatMap { contact ->
contact.emails.map { ThreePid.Email(it.email) } + contact.emails.map { ThreePid.Email(it.email) } +
contact.msisdns.map { ThreePid.Msisdn(it.phoneNumber) } contact.msisdns.map { ThreePid.Msisdn(it.phoneNumber) }
} }
session.identityService().lookUp(threePids, object : MatrixCallback<List<FoundThreePid>> {
override fun onFailure(failure: Throwable) { val data = try {
session.identityService().lookUp(threePids)
} catch (failure: Throwable) {
Timber.w(failure, "Unable to perform the lookup") Timber.w(failure, "Unable to perform the lookup")
// Should not happen, but just to be sure // Should not happen, but just to be sure
@ -120,9 +120,9 @@ class ContactsBookViewModel @AssistedInject constructor(@Assisted
copy(userConsent = false) copy(userConsent = false)
} }
} }
return@launch
} }
override fun onSuccess(data: List<FoundThreePid>) {
mappedContacts = allContacts.map { contactModel -> mappedContacts = allContacts.map { contactModel ->
contactModel.copy( contactModel.copy(
emails = contactModel.emails.map { email -> emails = contactModel.emails.map { email ->
@ -150,8 +150,6 @@ class ContactsBookViewModel @AssistedInject constructor(@Assisted
updateFilteredMappedContacts() updateFilteredMappedContacts()
} }
})
}
} }
private fun updateFilteredMappedContacts() = withState { state -> private fun updateFilteredMappedContacts() = withState { state ->

View File

@ -35,7 +35,6 @@ import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener import org.matrix.android.sdk.api.session.identity.IdentityServiceListener
import org.matrix.android.sdk.api.session.identity.SharedState import org.matrix.android.sdk.api.session.identity.SharedState
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.internal.util.awaitCallback
import org.matrix.android.sdk.rx.rx import org.matrix.android.sdk.rx.rx
class DiscoverySettingsViewModel @AssistedInject constructor( class DiscoverySettingsViewModel @AssistedInject constructor(
@ -123,7 +122,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
awaitCallback<Unit> { session.identityService().disconnect(it) } session.identityService().disconnect()
setState { setState {
copy( copy(
identityServer = Success(null), identityServer = Success(null),
@ -141,9 +140,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
val data = awaitCallback<String?> { val data = session.identityService().setNewIdentityServer(action.url)
session.identityService().setNewIdentityServer(action.url, it)
}
setState { setState {
copy( copy(
identityServer = Success(data), identityServer = Success(data),
@ -163,7 +160,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
awaitCallback<Unit> { identityService.startBindThreePid(action.threePid, it) } identityService.startBindThreePid(action.threePid)
changeThreePidState(action.threePid, Success(SharedState.BINDING_IN_PROGRESS)) changeThreePidState(action.threePid, Success(SharedState.BINDING_IN_PROGRESS))
} catch (failure: Throwable) { } catch (failure: Throwable) {
_viewEvents.post(DiscoverySettingsViewEvents.Failure(failure)) _viewEvents.post(DiscoverySettingsViewEvents.Failure(failure))
@ -240,7 +237,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
awaitCallback<Unit> { identityService.unbindThreePid(threePid, it) } identityService.unbindThreePid(threePid)
changeThreePidState(threePid, Success(SharedState.NOT_SHARED)) changeThreePidState(threePid, Success(SharedState.NOT_SHARED))
} catch (failure: Throwable) { } catch (failure: Throwable) {
_viewEvents.post(DiscoverySettingsViewEvents.Failure(failure)) _viewEvents.post(DiscoverySettingsViewEvents.Failure(failure))
@ -256,7 +253,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
awaitCallback<Unit> { identityService.unbindThreePid(threePid, it) } identityService.unbindThreePid(threePid)
changeThreePidState(threePid, Success(SharedState.NOT_SHARED)) changeThreePidState(threePid, Success(SharedState.NOT_SHARED))
} catch (failure: Throwable) { } catch (failure: Throwable) {
_viewEvents.post(DiscoverySettingsViewEvents.Failure(failure)) _viewEvents.post(DiscoverySettingsViewEvents.Failure(failure))
@ -268,7 +265,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
private fun cancelBinding(action: DiscoverySettingsAction.CancelBinding) { private fun cancelBinding(action: DiscoverySettingsAction.CancelBinding) {
viewModelScope.launch { viewModelScope.launch {
try { try {
awaitCallback<Unit> { identityService.cancelBindThreePid(action.threePid, it) } identityService.cancelBindThreePid(action.threePid)
changeThreePidState(action.threePid, Success(SharedState.NOT_SHARED)) changeThreePidState(action.threePid, Success(SharedState.NOT_SHARED))
changeThreePidSubmitState(action.threePid, Uninitialized) changeThreePidSubmitState(action.threePid, Uninitialized)
} catch (failure: Throwable) { } catch (failure: Throwable) {
@ -304,9 +301,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
val data = awaitCallback<Map<ThreePid, SharedState>> { val data = identityService.getShareStatus(threePids)
identityService.getShareStatus(threePids, it)
}
setState { setState {
copy( copy(
emailList = Success(data.filter { it.key is ThreePid.Email }.toPidInfoList()), emailList = Success(data.filter { it.key is ThreePid.Email }.toPidInfoList()),
@ -346,9 +341,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
awaitCallback<Unit> { identityService.submitValidationToken(action.threePid, action.code)
identityService.submitValidationToken(action.threePid, action.code, it)
}
changeThreePidSubmitState(action.threePid, Uninitialized) changeThreePidSubmitState(action.threePid, Uninitialized)
finalizeBind3pid(DiscoverySettingsAction.FinalizeBind3pid(action.threePid), true) finalizeBind3pid(DiscoverySettingsAction.FinalizeBind3pid(action.threePid), true)
} catch (failure: Throwable) { } catch (failure: Throwable) {
@ -371,7 +364,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
awaitCallback<Unit> { identityService.finalizeBindThreePid(threePid, it) } identityService.finalizeBindThreePid(threePid)
changeThreePidSubmitState(action.threePid, Uninitialized) changeThreePidSubmitState(action.threePid, Uninitialized)
changeThreePidState(action.threePid, Success(SharedState.SHARED)) changeThreePidState(action.threePid, Success(SharedState.SHARED))
} catch (failure: Throwable) { } catch (failure: Throwable) {

View File

@ -33,7 +33,6 @@ import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.terms.TermsService import org.matrix.android.sdk.api.session.terms.TermsService
import org.matrix.android.sdk.internal.util.awaitCallback
import java.net.UnknownHostException import java.net.UnknownHostException
class SetIdentityServerViewModel @AssistedInject constructor( class SetIdentityServerViewModel @AssistedInject constructor(
@ -97,9 +96,7 @@ class SetIdentityServerViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
// First ping the identity server v2 API // First ping the identity server v2 API
awaitCallback<Unit> { mxSession.identityService().isValidIdentityServer(baseUrl)
mxSession.identityService().isValidIdentityServer(baseUrl, it)
}
// Ok, next step // Ok, next step
checkTerms(baseUrl) checkTerms(baseUrl)
} catch (failure: Throwable) { } catch (failure: Throwable) {