mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Login screens: save isRegistrationStarted in DB
This commit is contained in:
parent
0a19ded167
commit
aa51764068
8 changed files with 24 additions and 18 deletions
|
@ -40,4 +40,7 @@ interface RegistrationWizard {
|
||||||
fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable
|
fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable
|
||||||
|
|
||||||
val currentThreePid: String?
|
val currentThreePid: String?
|
||||||
|
|
||||||
|
// True when login and password has been sent with success to the homeserver
|
||||||
|
val isRegistrationStarted: Boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,6 @@ internal data class PendingSessionData(
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
|
||||||
val currentSession: String? = null,
|
val currentSession: String? = null,
|
||||||
|
val isRegistrationStarted: Boolean = false,
|
||||||
val currentThreePidData: ThreePidData? = null
|
val currentThreePidData: ThreePidData? = null
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,5 +24,6 @@ internal open class PendingSessionEntity(
|
||||||
var sendAttempt: Int = 0,
|
var sendAttempt: Int = 0,
|
||||||
var resetPasswordDataJson: String? = null,
|
var resetPasswordDataJson: String? = null,
|
||||||
var currentSession: String? = null,
|
var currentSession: String? = null,
|
||||||
|
var isRegistrationStarted: Boolean = false,
|
||||||
var currentThreePidDataJson: String? = null
|
var currentThreePidDataJson: String? = null
|
||||||
) : RealmObject()
|
) : RealmObject()
|
||||||
|
|
|
@ -43,6 +43,7 @@ internal class PendingSessionMapper @Inject constructor(moshi: Moshi) {
|
||||||
sendAttempt = entity.sendAttempt,
|
sendAttempt = entity.sendAttempt,
|
||||||
resetPasswordData = resetPasswordData,
|
resetPasswordData = resetPasswordData,
|
||||||
currentSession = entity.currentSession,
|
currentSession = entity.currentSession,
|
||||||
|
isRegistrationStarted = entity.isRegistrationStarted,
|
||||||
currentThreePidData = threePidData)
|
currentThreePidData = threePidData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +62,7 @@ internal class PendingSessionMapper @Inject constructor(moshi: Moshi) {
|
||||||
sendAttempt = sessionData.sendAttempt,
|
sendAttempt = sessionData.sendAttempt,
|
||||||
resetPasswordDataJson = resetPasswordDataJson,
|
resetPasswordDataJson = resetPasswordDataJson,
|
||||||
currentSession = sessionData.currentSession,
|
currentSession = sessionData.currentSession,
|
||||||
|
isRegistrationStarted = sessionData.isRegistrationStarted,
|
||||||
currentThreePidDataJson = currentThreePidDataJson
|
currentThreePidDataJson = currentThreePidDataJson
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,9 @@ internal class DefaultRegistrationWizard(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val isRegistrationStarted: Boolean
|
||||||
|
get() = pendingSessionData.isRegistrationStarted
|
||||||
|
|
||||||
override fun getRegistrationFlow(callback: MatrixCallback<RegistrationResult>): Cancelable {
|
override fun getRegistrationFlow(callback: MatrixCallback<RegistrationResult>): Cancelable {
|
||||||
val params = RegistrationParams()
|
val params = RegistrationParams()
|
||||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||||
|
@ -85,6 +88,10 @@ internal class DefaultRegistrationWizard(
|
||||||
)
|
)
|
||||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||||
performRegistrationRequest(params)
|
performRegistrationRequest(params)
|
||||||
|
.also {
|
||||||
|
pendingSessionData = pendingSessionData.copy(isRegistrationStarted = true)
|
||||||
|
.also { pendingSessionStore.savePendingSessionData(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,8 +147,8 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||||
// Display a popup to propose use web fallback
|
// Display a popup to propose use web fallback
|
||||||
onRegistrationStageNotSupported()
|
onRegistrationStageNotSupported()
|
||||||
} else {
|
} else {
|
||||||
// Go on with registration flow
|
if (loginViewEvents.isRegistrationStarted) {
|
||||||
if (loginViewModel.isRegistrationStarted) {
|
// Go on with registration flow
|
||||||
handleRegistrationNavigation(loginViewEvents.flowResult)
|
handleRegistrationNavigation(loginViewEvents.flowResult)
|
||||||
} else {
|
} else {
|
||||||
// First ask for login and password
|
// First ask for login and password
|
||||||
|
|
|
@ -23,7 +23,7 @@ import im.vector.matrix.android.api.auth.registration.FlowResult
|
||||||
* Transient events for Login
|
* Transient events for Login
|
||||||
*/
|
*/
|
||||||
sealed class LoginViewEvents {
|
sealed class LoginViewEvents {
|
||||||
data class RegistrationFlowResult(val flowResult: FlowResult) : LoginViewEvents()
|
data class RegistrationFlowResult(val flowResult: FlowResult, val isRegistrationStarted: Boolean) : LoginViewEvents()
|
||||||
data class Error(val throwable: Throwable) : LoginViewEvents()
|
data class Error(val throwable: Throwable) : LoginViewEvents()
|
||||||
object OutdatedHomeserver : LoginViewEvents()
|
object OutdatedHomeserver : LoginViewEvents()
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import im.vector.matrix.android.api.auth.registration.RegistrationWizard
|
||||||
import im.vector.matrix.android.api.auth.registration.Stage
|
import im.vector.matrix.android.api.auth.registration.Stage
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.matrix.android.api.session.Session
|
||||||
import im.vector.matrix.android.api.util.Cancelable
|
import im.vector.matrix.android.api.util.Cancelable
|
||||||
import im.vector.matrix.android.api.util.MatrixCallbackDelegate
|
|
||||||
import im.vector.matrix.android.internal.auth.data.LoginFlowTypes
|
import im.vector.matrix.android.internal.auth.data.LoginFlowTypes
|
||||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||||
import im.vector.riotx.core.extensions.configureAndStart
|
import im.vector.riotx.core.extensions.configureAndStart
|
||||||
|
@ -69,9 +68,9 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
||||||
val currentThreePid: String?
|
val currentThreePid: String?
|
||||||
get() = registrationWizard?.currentThreePid
|
get() = registrationWizard?.currentThreePid
|
||||||
|
|
||||||
// True when login and password are sent with success to the homeserver
|
// True when login and password has been sent with success to the homeserver
|
||||||
var isRegistrationStarted: Boolean = false
|
val isRegistrationStarted: Boolean
|
||||||
private set
|
get() = registrationWizard?.isRegistrationStarted == true
|
||||||
|
|
||||||
private val registrationWizard: RegistrationWizard?
|
private val registrationWizard: RegistrationWizard?
|
||||||
get() = authenticationService.getRegistrationWizard()
|
get() = authenticationService.getRegistrationWizard()
|
||||||
|
@ -225,14 +224,8 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
||||||
action.username,
|
action.username,
|
||||||
action.password,
|
action.password,
|
||||||
action.initialDeviceName,
|
action.initialDeviceName,
|
||||||
object : MatrixCallbackDelegate<RegistrationResult>(registrationCallback) {
|
registrationCallback
|
||||||
override fun onSuccess(data: RegistrationResult) {
|
)
|
||||||
isRegistrationStarted = true
|
|
||||||
// Not sure that this will work:
|
|
||||||
// super.onSuccess(data)
|
|
||||||
registrationCallback.onSuccess(data)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleCaptchaDone(action: LoginAction.CaptchaDone) {
|
private fun handleCaptchaDone(action: LoginAction.CaptchaDone) {
|
||||||
|
@ -247,8 +240,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
||||||
|
|
||||||
when (action) {
|
when (action) {
|
||||||
LoginAction.ResetLogin -> {
|
LoginAction.ResetLogin -> {
|
||||||
isRegistrationStarted = false
|
// TODO Clear wizard here?
|
||||||
|
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
asyncLoginAction = Uninitialized,
|
asyncLoginAction = Uninitialized,
|
||||||
|
@ -466,7 +458,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
||||||
handleRegisterDummy()
|
handleRegisterDummy()
|
||||||
} else {
|
} else {
|
||||||
// Notify the user
|
// Notify the user
|
||||||
_viewEvents.post(LoginViewEvents.RegistrationFlowResult(flowResult))
|
_viewEvents.post(LoginViewEvents.RegistrationFlowResult(flowResult, isRegistrationStarted))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue