From 789bcc8d77373dd65b3b70c387a34d91375be130 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 13 May 2020 17:02:21 +0200 Subject: [PATCH] Identity: Bugfix: do not fail when trying to disconnect the current identity server, if there is no token available --- .../session/identity/IdentityDisconnectTask.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/IdentityDisconnectTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/IdentityDisconnectTask.kt index 0d0c24a4b0..abed3962bc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/IdentityDisconnectTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/IdentityDisconnectTask.kt @@ -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 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(null) { apiCall = identityAPI.logout() }