Identity: Bugfix: do not fail when trying to disconnect the current identity server, if there is no token available

This commit is contained in:
Benoit Marty 2020-05-13 17:02:21 +02:00
parent 2914117a8e
commit 789bcc8d77
1 changed files with 13 additions and 1 deletions

View File

@ -17,19 +17,31 @@
package im.vector.matrix.android.internal.session.identity
import im.vector.matrix.android.api.session.identity.IdentityServiceError
import im.vector.matrix.android.internal.di.AuthenticatedIdentity
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.network.token.AccessTokenProvider
import im.vector.matrix.android.internal.task.Task
import timber.log.Timber
import javax.inject.Inject
internal interface IdentityDisconnectTask : Task<Unit, Unit>
internal class DefaultIdentityDisconnectTask @Inject constructor(
private val identityApiProvider: IdentityApiProvider
private val identityApiProvider: IdentityApiProvider,
@AuthenticatedIdentity
private val accessTokenProvider: AccessTokenProvider
) : IdentityDisconnectTask {
override suspend fun execute(params: Unit) {
val identityAPI = identityApiProvider.identityApi ?: throw IdentityServiceError.NoIdentityServerConfigured
// Ensure we have a token.
// We can have an identity server configured, but no token yet.
if (accessTokenProvider.getToken() == null) {
Timber.d("No token to disconnect identity server.")
return
}
executeRequest<Unit>(null) {
apiCall = identityAPI.logout()
}