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