Skip to content
Snippets Groups Projects
Commit 0037515c authored by Taras's avatar Taras
Browse files

Change logic for signup stages

parent f90233df
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,8 @@ package org.futo.circles.core ...@@ -2,7 +2,8 @@ package org.futo.circles.core
const val FILE_PROVIDER_AUTHORITY_PREFIX = ".provider" const val FILE_PROVIDER_AUTHORITY_PREFIX = ".provider"
const val REGISTRATION_TOKEN_KEY_PREFIX = "login.registration_token" const val REGISTRATION_TOKEN_KEY_PREFIX = "registration_token"
const val REGISTRATION_SUBSCRIPTION_KEY_PREFIX = "subscription.google"
const val TERMS_URL_EXTENSION = "_matrix/consent" const val TERMS_URL_EXTENSION = "_matrix/consent"
const val VALIDATION_TOKEN_SUBMIT_URL_PREFIX = "_matrix/identity/api/v1/validate/email/submitToken" const val VALIDATION_TOKEN_SUBMIT_URL_PREFIX = "_matrix/identity/api/v1/validate/email/submitToken"
......
...@@ -6,6 +6,7 @@ import kotlinx.coroutines.async ...@@ -6,6 +6,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import org.futo.circles.R import org.futo.circles.R
import org.futo.circles.core.REGISTRATION_SUBSCRIPTION_KEY_PREFIX
import org.futo.circles.core.REGISTRATION_TOKEN_KEY_PREFIX import org.futo.circles.core.REGISTRATION_TOKEN_KEY_PREFIX
import org.futo.circles.core.SingleEventLiveData import org.futo.circles.core.SingleEventLiveData
import org.futo.circles.core.matrix.pass_phrase.create.CreatePassPhraseDataSource import org.futo.circles.core.matrix.pass_phrase.create.CreatePassPhraseDataSource
...@@ -18,7 +19,7 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationResult ...@@ -18,7 +19,7 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationResult
import org.matrix.android.sdk.api.auth.registration.Stage import org.matrix.android.sdk.api.auth.registration.Stage
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
enum class NavigationEvents { TokenValidation, AcceptTerm, ValidateEmail } enum class NavigationEvents { TokenValidation, Subscription, AcceptTerm, ValidateEmail }
class SignUpDataSource( class SignUpDataSource(
private val context: Context, private val context: Context,
...@@ -37,6 +38,8 @@ class SignUpDataSource( ...@@ -37,6 +38,8 @@ class SignUpDataSource(
private set private set
var currentHomeServerUrl: String = "" var currentHomeServerUrl: String = ""
private set
private var passphrase: String = "" private var passphrase: String = ""
private var userName: String = "" private var userName: String = ""
...@@ -44,7 +47,8 @@ class SignUpDataSource( ...@@ -44,7 +47,8 @@ class SignUpDataSource(
stages: List<Stage>, stages: List<Stage>,
name: String, name: String,
password: String, password: String,
homeServerUrl: String homeServerUrl: String,
isSubscription: Boolean
) { ) {
currentStage = null currentStage = null
stagesToComplete.clear() stagesToComplete.clear()
...@@ -52,7 +56,7 @@ class SignUpDataSource( ...@@ -52,7 +56,7 @@ class SignUpDataSource(
passphrase = password passphrase = password
currentHomeServerUrl = homeServerUrl currentHomeServerUrl = homeServerUrl
stagesToComplete.addAll(stages.filter { it.mandatory }) setupStages(stages, isSubscription)
navigateToNextStage() navigateToNextStage()
} }
...@@ -66,6 +70,16 @@ class SignUpDataSource( ...@@ -66,6 +70,16 @@ class SignUpDataSource(
subtitleLiveData.postValue("") subtitleLiveData.postValue("")
} }
private fun setupStages(stages: List<Stage>, isSubscription: Boolean) {
val otherStages = stages.filterIsInstance<Stage.Other>()
val firstStage = otherStages.firstOrNull {
if (isSubscription) it.type.endsWith(REGISTRATION_SUBSCRIPTION_KEY_PREFIX)
else it.type.endsWith(REGISTRATION_TOKEN_KEY_PREFIX)
} ?: throw IllegalArgumentException(context.getString(R.string.wrong_signup_config))
stagesToComplete.add(firstStage)
stagesToComplete.addAll(stages.filter { it.mandatory })
}
private suspend fun finishRegistration(session: Session) = createResult { private suspend fun finishRegistration(session: Session) = createResult {
MatrixInstanceProvider.matrix.authenticationService().reset() MatrixInstanceProvider.matrix.authenticationService().reset()
MatrixSessionProvider.awaitForSessionStart(session) MatrixSessionProvider.awaitForSessionStart(session)
...@@ -103,11 +117,11 @@ class SignUpDataSource( ...@@ -103,11 +117,11 @@ class SignUpDataSource(
private fun handleStageOther(type: String): NavigationEvents = private fun handleStageOther(type: String): NavigationEvents =
if (type.endsWith(REGISTRATION_TOKEN_KEY_PREFIX)) NavigationEvents.TokenValidation if (type.endsWith(REGISTRATION_TOKEN_KEY_PREFIX)) NavigationEvents.TokenValidation
else if (type.endsWith(REGISTRATION_SUBSCRIPTION_KEY_PREFIX)) NavigationEvents.Subscription
else throw IllegalArgumentException( else throw IllegalArgumentException(
context.getString(R.string.not_supported_stage_format, type) context.getString(R.string.not_supported_stage_format, type)
) )
private fun updatePageSubtitle() { private fun updatePageSubtitle() {
val size = stagesToComplete.size val size = stagesToComplete.size
val number = getCurrentStageIndex() + 1 val number = getCurrentStageIndex() + 1
...@@ -115,5 +129,4 @@ class SignUpDataSource( ...@@ -115,5 +129,4 @@ class SignUpDataSource(
subtitleLiveData.postValue(subtitle) subtitleLiveData.postValue(subtitle)
} }
} }
\ No newline at end of file
...@@ -57,6 +57,7 @@ class SignUpFragment : Fragment(R.layout.sign_up_fragment), BackPressOwner { ...@@ -57,6 +57,7 @@ class SignUpFragment : Fragment(R.layout.sign_up_fragment), BackPressOwner {
private fun handleNavigation(event: NavigationEvents) { private fun handleNavigation(event: NavigationEvents) {
val directionId = when (event) { val directionId = when (event) {
NavigationEvents.TokenValidation -> R.id.to_validateToken NavigationEvents.TokenValidation -> R.id.to_validateToken
NavigationEvents.Subscription -> R.id.to_subscriptions
NavigationEvents.AcceptTerm -> R.id.to_acceptTerms NavigationEvents.AcceptTerm -> R.id.to_acceptTerms
NavigationEvents.ValidateEmail -> R.id.to_validateEmail NavigationEvents.ValidateEmail -> R.id.to_validateEmail
} }
......
...@@ -44,7 +44,8 @@ class SelectSignUpTypeDataSource( ...@@ -44,7 +44,8 @@ class SelectSignUpTypeDataSource(
it.flowResult.missingStages, it.flowResult.missingStages,
name, name,
password, password,
homeServerUrl homeServerUrl,
isSubscription
) )
} }
} }
......
...@@ -238,6 +238,7 @@ ...@@ -238,6 +238,7 @@
<string name="enable_cross_signing_message">Confirm auth to enable cross signing</string> <string name="enable_cross_signing_message">Confirm auth to enable cross signing</string>
<string name="device_media">Device media</string> <string name="device_media">Device media</string>
<string name="subscriptions">Subscriptions</string> <string name="subscriptions">Subscriptions</string>
<string name="wrong_signup_config">Wrong signup config!</string>
<string-array name="report_categories"> <string-array name="report_categories">
<item>@string/crude_language</item> <item>@string/crude_language</item>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment