Confirm signout when it is current session

This commit is contained in:
Maxime NATUREL 2022-09-26 15:26:09 +02:00
parent 0fe5ee68f2
commit 68bee65e97
3 changed files with 20 additions and 2 deletions

View File

@ -40,6 +40,7 @@ import im.vector.app.databinding.FragmentSessionOverviewBinding
import im.vector.app.features.auth.ReAuthActivity
import im.vector.app.features.crypto.recover.SetupMode
import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState
import im.vector.app.features.workers.signout.SignOutUiWorker
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
import javax.inject.Inject
@ -86,12 +87,17 @@ class SessionOverviewFragment :
navigator.open4SSetup(requireActivity(), SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET)
}
is SessionOverviewViewEvent.RequestReAuth -> askForReAuthentication(it)
SessionOverviewViewEvent.ConfirmSignoutCurrentSession -> confirmSignoutCurrentSession()
SessionOverviewViewEvent.SignoutSuccess -> viewNavigator.goBack(requireActivity())
is SessionOverviewViewEvent.SignoutError -> showFailure(it.error)
}
}
}
private fun confirmSignoutCurrentSession() {
activity?.let { SignOutUiWorker(it).perform() }
}
private fun initSessionInfoView() {
views.sessionOverviewInfo.onLearnMoreClickListener = {
Toast.makeText(context, "Learn more verification status", Toast.LENGTH_LONG).show()

View File

@ -28,6 +28,7 @@ sealed class SessionOverviewViewEvent : VectorViewEvents {
val lastErrorCode: String?
) : SessionOverviewViewEvent()
object ConfirmSignoutCurrentSession : SessionOverviewViewEvent()
object SignoutSuccess : SessionOverviewViewEvent()
data class SignoutError(val error: Throwable) : SessionOverviewViewEvent()
}

View File

@ -130,10 +130,21 @@ class SessionOverviewViewModel @AssistedInject constructor(
// TODO add unit tests
private fun handleSignoutSession() = withState { state ->
// TODO for current session: do the same process as sign out button in the general settings
if (state.deviceInfo.invoke()?.isCurrentDevice.orFalse()) {
handleSignoutCurrentSession()
} else {
handleSignoutOtherSession(state.deviceId)
}
}
private fun handleSignoutCurrentSession() {
_viewEvents.post(SessionOverviewViewEvent.ConfirmSignoutCurrentSession)
}
private fun handleSignoutOtherSession(deviceId: String) {
viewModelScope.launch {
setLoading(true)
val signoutResult = signout(state.deviceId)
val signoutResult = signout(deviceId)
setLoading(false)
if (signoutResult.isSuccess) {