mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Better handling of push timeouts during registration.
This commit is contained in:
@@ -73,11 +73,11 @@ class ChangeNumberVerifyFragment : LoggingFragment(R.layout.fragment_change_phon
|
||||
return@subscribe
|
||||
}
|
||||
|
||||
val processor = (result as RequestCodeResult.RequestedVerificationCode).processor
|
||||
val processor: RegistrationSessionProcessor = (result as RequestCodeResult.RequestedVerificationCode).processor
|
||||
|
||||
if (processor.hasResult()) {
|
||||
findNavController().safeNavigate(R.id.action_changePhoneNumberVerifyFragment_to_changeNumberEnterCodeFragment)
|
||||
} else if (processor.captchaRequired()) {
|
||||
} else if (processor.captchaRequired(viewModel.excludedChallenges)) {
|
||||
Log.i(TAG, "Unable to request sms code due to captcha required")
|
||||
findNavController().safeNavigate(R.id.action_changePhoneNumberVerifyFragment_to_captchaFragment, getCaptchaArguments())
|
||||
requestingCaptcha = true
|
||||
|
||||
@@ -27,10 +27,6 @@ sealed class RegistrationSessionProcessor(response: ServiceResponse<Registration
|
||||
val REQUESTABLE_INFORMATION = listOf(PUSH_CHALLENGE_KEY, CAPTCHA_KEY)
|
||||
}
|
||||
|
||||
public override fun captchaRequired(): Boolean {
|
||||
return super.captchaRequired() || (hasResult() && CAPTCHA_KEY == getChallenge(emptyList()))
|
||||
}
|
||||
|
||||
public override fun rateLimit(): Boolean {
|
||||
return error is RateLimitException
|
||||
}
|
||||
@@ -39,9 +35,17 @@ sealed class RegistrationSessionProcessor(response: ServiceResponse<Registration
|
||||
return super.getError()
|
||||
}
|
||||
|
||||
fun captchaRequired(excludedChallenges: List<String>): Boolean {
|
||||
return response.status == 402 || (hasResult() && CAPTCHA_KEY == getChallenge(excludedChallenges))
|
||||
}
|
||||
|
||||
fun pushChallengeTimedOut(): Boolean {
|
||||
val state: RegistrationSessionState = response.result.get().state ?: return false
|
||||
return state.pushChallengeTimedOut
|
||||
if (response.result.isEmpty) {
|
||||
return false
|
||||
} else {
|
||||
val state: RegistrationSessionState = response.result.get().state ?: return false
|
||||
return state.pushChallengeTimedOut
|
||||
}
|
||||
}
|
||||
|
||||
fun isTokenRejected(): Boolean {
|
||||
|
||||
@@ -335,7 +335,7 @@ public abstract class BaseEnterSmsCodeFragment<ViewModel extends BaseRegistratio
|
||||
.subscribe(processor -> {
|
||||
if (processor.hasResult()) {
|
||||
Toast.makeText(requireContext(), getCodeRequestedToastText(mode), Toast.LENGTH_LONG).show();
|
||||
} else if (processor.captchaRequired()) {
|
||||
} else if (processor.captchaRequired(viewModel.getExcludedChallenges())) {
|
||||
navigateToCaptcha();
|
||||
} else if (processor.rateLimit()) {
|
||||
handleRateLimited();
|
||||
|
||||
@@ -283,7 +283,7 @@ public final class EnterPhoneNumberFragment extends LoggingFragment implements R
|
||||
if (processor.verificationCodeRequestSuccess()) {
|
||||
disposables.add(updateFcmTokenValue());
|
||||
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionEnterVerificationCode());
|
||||
} else if (processor.captchaRequired()) {
|
||||
} else if (processor.captchaRequired(viewModel.getExcludedChallenges())) {
|
||||
Log.i(TAG, "Unable to request sms code due to captcha required");
|
||||
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionRequestCaptcha());
|
||||
} else if (processor.exhaustedVerificationCodeAttempts()) {
|
||||
|
||||
@@ -303,7 +303,7 @@ public abstract class BaseRegistrationViewModel extends ViewModel {
|
||||
return Single.just(processor);
|
||||
}
|
||||
|
||||
if (hasCaptchaToken() && processor.captchaRequired()) {
|
||||
if (hasCaptchaToken() && processor.captchaRequired(getExcludedChallenges())) {
|
||||
Log.d(TAG, "Submitting completed captcha challenge");
|
||||
final String captcha = Objects.requireNonNull(getCaptchaToken());
|
||||
clearCaptchaResponse();
|
||||
|
||||
@@ -67,10 +67,6 @@ public abstract class ServiceResponseProcessor<T> {
|
||||
return response.getStatus() == 401 || response.getStatus() == 403;
|
||||
}
|
||||
|
||||
protected boolean captchaRequired() {
|
||||
return response.getStatus() == 402;
|
||||
}
|
||||
|
||||
protected boolean notFound() {
|
||||
return response.getStatus() == 404;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user