|
17 | 17 | package io.element.android.features.logout.impl |
18 | 18 |
|
19 | 19 | import com.squareup.anvil.annotations.ContributesBinding |
20 | | -import dagger.assisted.Assisted |
21 | | -import dagger.assisted.AssistedFactory |
22 | | -import dagger.assisted.AssistedInject |
23 | 20 | import io.element.android.features.logout.api.LogoutUseCase |
24 | 21 | import io.element.android.libraries.di.AppScope |
25 | 22 | import io.element.android.libraries.matrix.api.MatrixClientProvider |
26 | | -import io.element.android.libraries.matrix.api.core.SessionId |
| 23 | +import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService |
| 24 | +import javax.inject.Inject |
27 | 25 |
|
28 | | -class DefaultLogoutUseCase @AssistedInject constructor( |
29 | | - @Assisted private val sessionId: String, |
| 26 | +@ContributesBinding(AppScope::class) |
| 27 | +class DefaultLogoutUseCase @Inject constructor( |
| 28 | + private val authenticationService: MatrixAuthenticationService, |
30 | 29 | private val matrixClientProvider: MatrixClientProvider, |
31 | 30 | ) : LogoutUseCase { |
32 | | - @ContributesBinding(AppScope::class) |
33 | | - @AssistedFactory |
34 | | - interface Factory : LogoutUseCase.Factory { |
35 | | - override fun create(sessionId: String): DefaultLogoutUseCase |
36 | | - } |
37 | | - |
38 | 31 | override suspend fun logout(ignoreSdkError: Boolean): String? { |
39 | | - val matrixClient = matrixClientProvider.getOrRestore(SessionId(sessionId)).getOrThrow() |
40 | | - val result = matrixClient.logout(ignoreSdkError = ignoreSdkError) |
41 | | - return result |
| 32 | + val currentSession = authenticationService.getLatestSessionId() |
| 33 | + return if (currentSession != null) { |
| 34 | + matrixClientProvider.getOrRestore(currentSession) |
| 35 | + .getOrThrow() |
| 36 | + .logout(ignoreSdkError = true) |
| 37 | + } else { |
| 38 | + error("No session to sign out") |
| 39 | + } |
42 | 40 | } |
43 | 41 | } |
0 commit comments