mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Merge pull request #5258 from vector-im/feature/mna/5218-crash-at-registration
#5218: Fix crash at registration when redirecting to Web View
This commit is contained in:
commit
5dced8b6bd
7 changed files with 31 additions and 46 deletions
1
changelog.d/5218.bugfix
Normal file
1
changelog.d/5218.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fix crash during account registration when redirecting to Web View
|
|
@ -51,7 +51,7 @@ class LoginWebFragment @Inject constructor(
|
|||
private val assetReader: AssetReader
|
||||
) : AbstractLoginFragment<FragmentLoginWebBinding>() {
|
||||
|
||||
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||
private val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLoginWebBinding {
|
||||
return FragmentLoginWebBinding.inflate(inflater, container, false)
|
||||
|
|
|
@ -56,7 +56,7 @@ class LoginWebFragment2 @Inject constructor(
|
|||
return FragmentLoginWebBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||
private val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||
|
||||
private var isWebViewLoaded = false
|
||||
private var isForSessionRecovery = false
|
||||
|
@ -82,7 +82,7 @@ class LoginWebFragment2 @Inject constructor(
|
|||
private fun setupTitle(state: LoginViewState2) {
|
||||
toolbar?.title = when (state.signMode) {
|
||||
SignMode2.SignIn -> getString(R.string.login_signin)
|
||||
else -> getString(R.string.login_signup)
|
||||
else -> getString(R.string.login_signup)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import im.vector.app.features.login.LoginConfig
|
|||
import im.vector.app.features.login.ServerType
|
||||
import im.vector.app.features.login.SignMode
|
||||
import org.matrix.android.sdk.api.auth.data.Credentials
|
||||
import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
|
||||
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
|
||||
import org.matrix.android.sdk.internal.network.ssl.Fingerprint
|
||||
|
||||
|
@ -71,11 +70,6 @@ sealed class OnboardingAction : VectorViewModelAction {
|
|||
// Homeserver history
|
||||
object ClearHomeServerHistory : OnboardingAction()
|
||||
|
||||
// For the soft logout case
|
||||
data class SetupSsoForSessionRecovery(val homeServerUrl: String,
|
||||
val deviceId: String,
|
||||
val ssoIdentityProviders: List<SsoIdentityProvider>?) : OnboardingAction()
|
||||
|
||||
data class PostViewEvent(val viewEvent: OnboardingViewEvents) : OnboardingAction()
|
||||
|
||||
data class UserAcceptCertificate(val fingerprint: Fingerprint) : OnboardingAction()
|
||||
|
|
|
@ -143,7 +143,6 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
is OnboardingAction.ResetPasswordMailConfirmed -> handleResetPasswordMailConfirmed()
|
||||
is OnboardingAction.RegisterAction -> handleRegisterAction(action)
|
||||
is OnboardingAction.ResetAction -> handleResetAction(action)
|
||||
is OnboardingAction.SetupSsoForSessionRecovery -> handleSetupSsoForSessionRecovery(action)
|
||||
is OnboardingAction.UserAcceptCertificate -> handleUserAcceptCertificate(action)
|
||||
OnboardingAction.ClearHomeServerHistory -> handleClearHomeServerHistory()
|
||||
is OnboardingAction.PostViewEvent -> _viewEvents.post(action.viewEvent)
|
||||
|
@ -249,18 +248,6 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleSetupSsoForSessionRecovery(action: OnboardingAction.SetupSsoForSessionRecovery) {
|
||||
setState {
|
||||
copy(
|
||||
signMode = SignMode.SignIn,
|
||||
loginMode = LoginMode.Sso(action.ssoIdentityProviders),
|
||||
homeServerUrlFromUser = action.homeServerUrl,
|
||||
homeServerUrl = action.homeServerUrl,
|
||||
deviceId = action.deviceId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleRegisterAction(action: OnboardingAction.RegisterAction) {
|
||||
when (action) {
|
||||
is OnboardingAction.CaptchaDone -> handleCaptchaDone(action)
|
||||
|
|
|
@ -30,7 +30,6 @@ import android.view.ViewGroup
|
|||
import android.webkit.SslErrorHandler
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.utils.AssetReader
|
||||
|
@ -40,8 +39,6 @@ import im.vector.app.features.login.SignMode
|
|||
import im.vector.app.features.onboarding.OnboardingAction
|
||||
import im.vector.app.features.onboarding.OnboardingViewEvents
|
||||
import im.vector.app.features.onboarding.OnboardingViewState
|
||||
import im.vector.app.features.signout.soft.SoftLogoutAction
|
||||
import im.vector.app.features.signout.soft.SoftLogoutViewModel
|
||||
import org.matrix.android.sdk.api.auth.data.Credentials
|
||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||
import timber.log.Timber
|
||||
|
@ -56,14 +53,11 @@ class FtueAuthWebFragment @Inject constructor(
|
|||
private val assetReader: AssetReader
|
||||
) : AbstractFtueAuthFragment<FragmentLoginWebBinding>() {
|
||||
|
||||
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLoginWebBinding {
|
||||
return FragmentLoginWebBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
private var isWebViewLoaded = false
|
||||
private var isForSessionRecovery = false
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
@ -75,8 +69,6 @@ class FtueAuthWebFragment @Inject constructor(
|
|||
override fun updateWithState(state: OnboardingViewState) {
|
||||
setupTitle(state)
|
||||
|
||||
isForSessionRecovery = state.deviceId?.isNotBlank() == true
|
||||
|
||||
if (!isWebViewLoaded) {
|
||||
setupWebView(state)
|
||||
isWebViewLoaded = true
|
||||
|
@ -239,11 +231,7 @@ class FtueAuthWebFragment @Inject constructor(
|
|||
}
|
||||
|
||||
private fun notifyViewModel(credentials: Credentials) {
|
||||
if (isForSessionRecovery) {
|
||||
softLogoutViewModel.handle(SoftLogoutAction.WebLoginSuccess(credentials))
|
||||
} else {
|
||||
viewModel.handle(OnboardingAction.WebLoginSuccess(credentials))
|
||||
}
|
||||
viewModel.handle(OnboardingAction.WebLoginSuccess(credentials))
|
||||
}
|
||||
|
||||
override fun resetViewModel() {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package im.vector.app.features.signout.soft
|
||||
|
||||
import com.airbnb.mvrx.ActivityViewModelContext
|
||||
import com.airbnb.mvrx.Fail
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||
|
@ -26,8 +25,10 @@ import com.airbnb.mvrx.ViewModelContext
|
|||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import dagger.hilt.EntryPoints
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||
import im.vector.app.core.di.SingletonEntryPoint
|
||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||
import im.vector.app.core.extensions.hasUnsavedKeys
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
|
@ -55,16 +56,30 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
|
||||
companion object : MavericksViewModelFactory<SoftLogoutViewModel, SoftLogoutViewState> by hiltMavericksViewModelFactory() {
|
||||
|
||||
override fun initialState(viewModelContext: ViewModelContext): SoftLogoutViewState? {
|
||||
val activity: SoftLogoutActivity = (viewModelContext as ActivityViewModelContext).activity()
|
||||
val userId = activity.session.myUserId
|
||||
return SoftLogoutViewState(
|
||||
homeServerUrl = activity.session.sessionParams.homeServerUrl,
|
||||
userId = userId,
|
||||
deviceId = activity.session.sessionParams.deviceId ?: "",
|
||||
userDisplayName = activity.session.getUser(userId)?.displayName ?: userId,
|
||||
hasUnsavedKeys = activity.session.hasUnsavedKeys()
|
||||
)
|
||||
override fun initialState(viewModelContext: ViewModelContext): SoftLogoutViewState {
|
||||
val sessionHolder = EntryPoints.get(viewModelContext.app(), SingletonEntryPoint::class.java)
|
||||
.activeSessionHolder()
|
||||
|
||||
return if (sessionHolder.hasActiveSession()) {
|
||||
val session = sessionHolder.getActiveSession()
|
||||
val userId = session.myUserId
|
||||
|
||||
SoftLogoutViewState(
|
||||
homeServerUrl = session.sessionParams.homeServerUrl,
|
||||
userId = userId,
|
||||
deviceId = session.sessionParams.deviceId.orEmpty(),
|
||||
userDisplayName = session.getUser(userId)?.displayName ?: userId,
|
||||
hasUnsavedKeys = session.hasUnsavedKeys()
|
||||
)
|
||||
} else {
|
||||
SoftLogoutViewState(
|
||||
homeServerUrl = "",
|
||||
userId = "",
|
||||
deviceId = "",
|
||||
userDisplayName = "",
|
||||
hasUnsavedKeys = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue