Identity: Bugfix: do not fail when trying to disconnect the current identity server, if there is no token available
This commit is contained in:
parent
2914117a8e
commit
789bcc8d77
|
@ -17,19 +17,31 @@
|
||||||
package im.vector.matrix.android.internal.session.identity
|
package im.vector.matrix.android.internal.session.identity
|
||||||
|
|
||||||
import im.vector.matrix.android.api.session.identity.IdentityServiceError
|
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.executeRequest
|
||||||
|
import im.vector.matrix.android.internal.network.token.AccessTokenProvider
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface IdentityDisconnectTask : Task<Unit, Unit>
|
internal interface IdentityDisconnectTask : Task<Unit, Unit>
|
||||||
|
|
||||||
internal class DefaultIdentityDisconnectTask @Inject constructor(
|
internal class DefaultIdentityDisconnectTask @Inject constructor(
|
||||||
private val identityApiProvider: IdentityApiProvider
|
private val identityApiProvider: IdentityApiProvider,
|
||||||
|
@AuthenticatedIdentity
|
||||||
|
private val accessTokenProvider: AccessTokenProvider
|
||||||
) : IdentityDisconnectTask {
|
) : IdentityDisconnectTask {
|
||||||
|
|
||||||
override suspend fun execute(params: Unit) {
|
override suspend fun execute(params: Unit) {
|
||||||
val identityAPI = identityApiProvider.identityApi ?: throw IdentityServiceError.NoIdentityServerConfigured
|
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) {
|
executeRequest<Unit>(null) {
|
||||||
apiCall = identityAPI.logout()
|
apiCall = identityAPI.logout()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue