Better archi, better code, less bug...
This commit is contained in:
parent
92e60c939d
commit
e60bda7806
|
@ -18,6 +18,8 @@ package im.vector.matrix.android.internal.session.signout
|
|||
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.BuildConfig
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.failure.MatrixError
|
||||
import im.vector.matrix.android.internal.SessionManager
|
||||
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
||||
import im.vector.matrix.android.internal.crypto.CryptoModule
|
||||
|
@ -32,6 +34,7 @@ import io.realm.Realm
|
|||
import io.realm.RealmConfiguration
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.net.HttpURLConnection
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface SignOutTask : Task<SignOutTask.Params, Unit> {
|
||||
|
@ -54,12 +57,24 @@ internal class DefaultSignOutTask @Inject constructor(private val context: Conte
|
|||
@UserMd5 private val userMd5: String) : SignOutTask {
|
||||
|
||||
override suspend fun execute(params: SignOutTask.Params) {
|
||||
// TODO It should be done even after a soft logout, to be sure the deviceId is deleted on the
|
||||
// TODO homeserver but https://github.com/matrix-org/synapse/issues/5755
|
||||
// It should be done even after a soft logout, to be sure the deviceId is deleted on the
|
||||
if (params.sigOutFromHomeserver) {
|
||||
Timber.d("SignOut: send request...")
|
||||
executeRequest<Unit> {
|
||||
apiCall = signOutAPI.signOut()
|
||||
try {
|
||||
executeRequest<Unit> {
|
||||
apiCall = signOutAPI.signOut()
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
// Maybe due to https://github.com/matrix-org/synapse/issues/5755
|
||||
if (throwable is Failure.ServerError
|
||||
&& throwable.httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */
|
||||
&& throwable.error.code == MatrixError.M_UNKNOWN_TOKEN) {
|
||||
// Also throwable.error.isSoftLogout should be true
|
||||
// Ignore
|
||||
Timber.w("Ignore error due to https://github.com/matrix-org/synapse/issues/5755")
|
||||
} else {
|
||||
throw throwable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,8 +50,6 @@ class LoginWebFragment @Inject constructor(
|
|||
private val assetReader: AssetReader
|
||||
) : AbstractLoginFragment() {
|
||||
|
||||
private val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||
|
||||
override fun getLayoutResId() = R.layout.fragment_login_web
|
||||
|
||||
private var isWebViewLoaded = false
|
||||
|
@ -252,6 +250,7 @@ class LoginWebFragment @Inject constructor(
|
|||
|
||||
private fun notifyViewModel(credentials: Credentials) {
|
||||
if (isForSessionRecovery) {
|
||||
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||
softLogoutViewModel.handle(SoftLogoutAction.WebLoginSuccess(credentials))
|
||||
} else {
|
||||
loginViewModel.handle(LoginAction.WebLoginSuccess(credentials))
|
||||
|
|
|
@ -20,10 +20,17 @@ import im.vector.matrix.android.api.auth.data.Credentials
|
|||
import im.vector.riotx.core.platform.VectorViewModelAction
|
||||
|
||||
sealed class SoftLogoutAction : VectorViewModelAction {
|
||||
// In case of failure to get the login flow
|
||||
object RetryLoginFlow : SoftLogoutAction()
|
||||
|
||||
// For password entering management
|
||||
data class PasswordChanged(val password: String) : SoftLogoutAction()
|
||||
object TogglePassword : SoftLogoutAction()
|
||||
|
||||
data class SignInAgain(val password: String) : SoftLogoutAction()
|
||||
|
||||
// For signing again with SSO
|
||||
data class WebLoginSuccess(val credentials: Credentials) : SoftLogoutAction()
|
||||
|
||||
// To clear the current session
|
||||
object ClearData : SoftLogoutAction()
|
||||
}
|
||||
|
|
|
@ -86,6 +86,11 @@ class SoftLogoutActivity : LoginActivity() {
|
|||
softLogoutViewEvents.newUserId)
|
||||
)
|
||||
}
|
||||
is SoftLogoutViewEvents.ClearData -> {
|
||||
MainActivity.restartApp(this, MainActivityArgs(
|
||||
clearCredentials = true
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,11 +114,7 @@ class SoftLogoutFragment @Inject constructor(
|
|||
.setMessage(messageResId)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.soft_logout_clear_data_submit) { _, _ ->
|
||||
MainActivity.restartApp(requireActivity(), MainActivityArgs(
|
||||
clearCache = true,
|
||||
clearCredentials = true,
|
||||
isUserLoggedOut = true
|
||||
))
|
||||
softLogoutViewModel.handle(SoftLogoutAction.ClearData)
|
||||
}
|
||||
.show()
|
||||
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
|
||||
|
|
|
@ -23,4 +23,5 @@ package im.vector.riotx.features.signout.soft
|
|||
sealed class SoftLogoutViewEvents {
|
||||
data class ErrorNotSameUser(val currentUserId: String, val newUserId: String) : SoftLogoutViewEvents()
|
||||
data class Error(val throwable: Throwable) : SoftLogoutViewEvents()
|
||||
object ClearData : SoftLogoutViewEvents()
|
||||
}
|
||||
|
|
|
@ -130,8 +130,6 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
private fun notSupported() {
|
||||
// Should not happen since it's a re-logout
|
||||
// Notify the UI
|
||||
// _viewEvents.post(LoginViewEvents.OutdatedHomeserver)
|
||||
|
||||
setState {
|
||||
copy(
|
||||
asyncHomeServerLoginFlowRequest = Fail(IllegalStateException("Should not happen"))
|
||||
|
@ -144,13 +142,19 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
override fun handle(action: SoftLogoutAction) {
|
||||
when (action) {
|
||||
is SoftLogoutAction.RetryLoginFlow -> getSupportedLoginFlow()
|
||||
is SoftLogoutAction.SignInAgain -> handleSignInAgain(action)
|
||||
is SoftLogoutAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
||||
is SoftLogoutAction.PasswordChanged -> handlePasswordChange(action)
|
||||
is SoftLogoutAction.TogglePassword -> handleTogglePassword()
|
||||
is SoftLogoutAction.SignInAgain -> handleSignInAgain(action)
|
||||
is SoftLogoutAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
||||
is SoftLogoutAction.ClearData -> handleClearData()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleClearData() {
|
||||
// Notify the Activity
|
||||
_viewEvents.post(SoftLogoutViewEvents.ClearData)
|
||||
}
|
||||
|
||||
private fun handlePasswordChange(action: SoftLogoutAction.PasswordChanged) {
|
||||
setState {
|
||||
copy(
|
||||
|
|
Loading…
Reference in New Issue