Show registration rate limit error messaging.

This commit is contained in:
Cody Henthorne 2020-06-16 17:38:52 -04:00 committed by Greyson Parrelli
parent b687b1a4c5
commit 2915e4698c
4 changed files with 29 additions and 6 deletions

View File

@ -1,8 +1,5 @@
package org.thoughtcrime.securesms.registration.fragments;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -20,7 +17,6 @@ import androidx.navigation.Navigation;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.registration.CallMeCountDownView;
import org.thoughtcrime.securesms.components.registration.VerificationCodeView;
@ -39,7 +35,6 @@ import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public final class EnterCodeFragment extends BaseRegistrationFragment {
@ -278,6 +273,11 @@ public final class EnterCodeFragment extends BaseRegistrationFragment {
model.markASuccessfulAttempt();
}
@Override
public void onRateLimited() {
Toast.makeText(requireContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show();
}
@Override
public void onError() {
Toast.makeText(requireContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show();

View File

@ -245,6 +245,15 @@ public final class EnterPhoneNumberFragment extends BaseRegistrationFragment {
model.updateLimiter();
}
@Override
public void onRateLimited() {
Toast.makeText(register.getContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show();
cancelSpinning(register);
enableAllEntries();
model.getRequestLimiter().onUnsuccessfulRequest();
model.updateLimiter();
}
@Override
public void onError() {
Toast.makeText(register.getContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show();

View File

@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException;
import org.whispersystems.signalservice.api.push.exceptions.RateLimitException;
import java.io.IOException;
import java.util.Locale;
@ -62,8 +63,10 @@ public final class RegistrationCodeRequest {
}
protected void onPostExecute(@NonNull VerificationRequestResult result) {
if (result.exception.isPresent() && result.exception.get() instanceof CaptchaRequiredException) {
if (isCaptchaRequired(result)) {
callback.onNeedCaptcha();
} else if (isRateLimited(result)) {
callback.onRateLimited();
} else if (result.exception.isPresent()) {
callback.onError();
} else {
@ -79,6 +82,14 @@ public final class RegistrationCodeRequest {
TextSecurePreferences.setPushRegistered(context, false);
}
private static boolean isCaptchaRequired(@NonNull VerificationRequestResult result) {
return result.exception.isPresent() && result.exception.get() instanceof CaptchaRequiredException;
}
private static boolean isRateLimited(@NonNull VerificationRequestResult result) {
return result.exception.isPresent() && result.exception.get() instanceof RateLimitException;
}
private static class VerificationRequestResult {
private final @Nullable String fcmToken;
private final Optional<IOException> exception;
@ -130,6 +141,8 @@ public final class RegistrationCodeRequest {
void requestSent(@Nullable String fcmToken);
void onRateLimited();
void onError();
}
}

View File

@ -1025,6 +1025,7 @@
<string name="RegistrationActivity_more_information">More information</string>
<string name="RegistrationActivity_less_information">Less information</string>
<string name="RegistrationActivity_signal_needs_access_to_your_contacts_and_media_in_order_to_connect_with_friends">Signal needs access to your contacts and media in order to connect with friends, exchange messages, and make secure calls</string>
<string name="RegistrationActivity_rate_limited_to_service">You\'ve made too many attempts to register this number. Please try again later.</string>
<string name="RegistrationActivity_unable_to_connect_to_service">Unable to connect to service. Please check network connection and try again.</string>
<string name="RegistrationActivity_to_easily_verify_your_phone_number_signal_can_automatically_detect_your_verification_code">To easily verify your phone number, Signal can automatically detect your verification code if you allow Signal to view SMS messages.</string>
<plurals name="RegistrationActivity_debug_log_hint">