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 android.content.Context
|
||||||
import im.vector.matrix.android.BuildConfig
|
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.SessionManager
|
||||||
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
||||||
import im.vector.matrix.android.internal.crypto.CryptoModule
|
import im.vector.matrix.android.internal.crypto.CryptoModule
|
||||||
|
@ -32,6 +34,7 @@ import io.realm.Realm
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.net.HttpURLConnection
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface SignOutTask : Task<SignOutTask.Params, Unit> {
|
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 {
|
@UserMd5 private val userMd5: String) : SignOutTask {
|
||||||
|
|
||||||
override suspend fun execute(params: SignOutTask.Params) {
|
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
|
// 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
|
|
||||||
if (params.sigOutFromHomeserver) {
|
if (params.sigOutFromHomeserver) {
|
||||||
Timber.d("SignOut: send request...")
|
Timber.d("SignOut: send request...")
|
||||||
executeRequest<Unit> {
|
try {
|
||||||
apiCall = signOutAPI.signOut()
|
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
|
private val assetReader: AssetReader
|
||||||
) : AbstractLoginFragment() {
|
) : AbstractLoginFragment() {
|
||||||
|
|
||||||
private val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
|
||||||
|
|
||||||
override fun getLayoutResId() = R.layout.fragment_login_web
|
override fun getLayoutResId() = R.layout.fragment_login_web
|
||||||
|
|
||||||
private var isWebViewLoaded = false
|
private var isWebViewLoaded = false
|
||||||
|
@ -252,6 +250,7 @@ class LoginWebFragment @Inject constructor(
|
||||||
|
|
||||||
private fun notifyViewModel(credentials: Credentials) {
|
private fun notifyViewModel(credentials: Credentials) {
|
||||||
if (isForSessionRecovery) {
|
if (isForSessionRecovery) {
|
||||||
|
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||||
softLogoutViewModel.handle(SoftLogoutAction.WebLoginSuccess(credentials))
|
softLogoutViewModel.handle(SoftLogoutAction.WebLoginSuccess(credentials))
|
||||||
} else {
|
} else {
|
||||||
loginViewModel.handle(LoginAction.WebLoginSuccess(credentials))
|
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
|
import im.vector.riotx.core.platform.VectorViewModelAction
|
||||||
|
|
||||||
sealed class SoftLogoutAction : VectorViewModelAction {
|
sealed class SoftLogoutAction : VectorViewModelAction {
|
||||||
|
// In case of failure to get the login flow
|
||||||
object RetryLoginFlow : SoftLogoutAction()
|
object RetryLoginFlow : SoftLogoutAction()
|
||||||
|
|
||||||
|
// For password entering management
|
||||||
data class PasswordChanged(val password: String) : SoftLogoutAction()
|
data class PasswordChanged(val password: String) : SoftLogoutAction()
|
||||||
object TogglePassword : SoftLogoutAction()
|
object TogglePassword : SoftLogoutAction()
|
||||||
|
|
||||||
data class SignInAgain(val password: String) : SoftLogoutAction()
|
data class SignInAgain(val password: String) : SoftLogoutAction()
|
||||||
|
|
||||||
|
// For signing again with SSO
|
||||||
data class WebLoginSuccess(val credentials: Credentials) : SoftLogoutAction()
|
data class WebLoginSuccess(val credentials: Credentials) : SoftLogoutAction()
|
||||||
|
|
||||||
|
// To clear the current session
|
||||||
|
object ClearData : SoftLogoutAction()
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,11 @@ class SoftLogoutActivity : LoginActivity() {
|
||||||
softLogoutViewEvents.newUserId)
|
softLogoutViewEvents.newUserId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
is SoftLogoutViewEvents.ClearData -> {
|
||||||
|
MainActivity.restartApp(this, MainActivityArgs(
|
||||||
|
clearCredentials = true
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,11 +114,7 @@ class SoftLogoutFragment @Inject constructor(
|
||||||
.setMessage(messageResId)
|
.setMessage(messageResId)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.setPositiveButton(R.string.soft_logout_clear_data_submit) { _, _ ->
|
.setPositiveButton(R.string.soft_logout_clear_data_submit) { _, _ ->
|
||||||
MainActivity.restartApp(requireActivity(), MainActivityArgs(
|
softLogoutViewModel.handle(SoftLogoutAction.ClearData)
|
||||||
clearCache = true,
|
|
||||||
clearCredentials = true,
|
|
||||||
isUserLoggedOut = true
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
|
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
|
||||||
|
|
|
@ -23,4 +23,5 @@ package im.vector.riotx.features.signout.soft
|
||||||
sealed class SoftLogoutViewEvents {
|
sealed class SoftLogoutViewEvents {
|
||||||
data class ErrorNotSameUser(val currentUserId: String, val newUserId: String) : SoftLogoutViewEvents()
|
data class ErrorNotSameUser(val currentUserId: String, val newUserId: String) : SoftLogoutViewEvents()
|
||||||
data class Error(val throwable: Throwable) : SoftLogoutViewEvents()
|
data class Error(val throwable: Throwable) : SoftLogoutViewEvents()
|
||||||
|
object ClearData : SoftLogoutViewEvents()
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,6 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
||||||
private fun notSupported() {
|
private fun notSupported() {
|
||||||
// Should not happen since it's a re-logout
|
// Should not happen since it's a re-logout
|
||||||
// Notify the UI
|
// Notify the UI
|
||||||
// _viewEvents.post(LoginViewEvents.OutdatedHomeserver)
|
|
||||||
|
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
asyncHomeServerLoginFlowRequest = Fail(IllegalStateException("Should not happen"))
|
asyncHomeServerLoginFlowRequest = Fail(IllegalStateException("Should not happen"))
|
||||||
|
@ -144,13 +142,19 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
||||||
override fun handle(action: SoftLogoutAction) {
|
override fun handle(action: SoftLogoutAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
is SoftLogoutAction.RetryLoginFlow -> getSupportedLoginFlow()
|
is SoftLogoutAction.RetryLoginFlow -> getSupportedLoginFlow()
|
||||||
is SoftLogoutAction.SignInAgain -> handleSignInAgain(action)
|
|
||||||
is SoftLogoutAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
|
||||||
is SoftLogoutAction.PasswordChanged -> handlePasswordChange(action)
|
is SoftLogoutAction.PasswordChanged -> handlePasswordChange(action)
|
||||||
is SoftLogoutAction.TogglePassword -> handleTogglePassword()
|
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) {
|
private fun handlePasswordChange(action: SoftLogoutAction.PasswordChanged) {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
|
|
Loading…
Reference in New Issue