]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/util/NumberVerificationUtils.java
Show information when requesting voice verification without SMS verification
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / util / NumberVerificationUtils.java
index f8a14c0544ed2effb96f1623aa829212965afce0..9eb01cdbdbdcf3d859a37639d11c05aff8d4325f 100644 (file)
@@ -6,7 +6,10 @@ import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
 import org.asamk.signal.manager.api.Pair;
 import org.asamk.signal.manager.api.PinLockedException;
 import org.asamk.signal.manager.api.RateLimitException;
+import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
 import org.asamk.signal.manager.helper.PinHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.whispersystems.signalservice.api.SignalServiceAccountManager;
 import org.whispersystems.signalservice.api.kbs.MasterKey;
 import org.whispersystems.signalservice.api.push.exceptions.NoSuchSessionException;
@@ -24,13 +27,15 @@ import java.util.function.Consumer;
 
 public class NumberVerificationUtils {
 
+    private static final Logger logger = LoggerFactory.getLogger(NumberVerificationUtils.class);
+
     public static String handleVerificationSession(
             SignalServiceAccountManager accountManager,
             String sessionId,
             Consumer<String> sessionIdSaver,
             boolean voiceVerification,
             String captcha
-    ) throws CaptchaRequiredException, IOException, RateLimitException {
+    ) throws CaptchaRequiredException, IOException, RateLimitException, VerificationMethoNotAvailableException {
         RegistrationSessionMetadataResponse sessionResponse;
         try {
             sessionResponse = getValidSession(accountManager, sessionId);
@@ -57,7 +62,9 @@ public class NumberVerificationUtils {
         final var nextAttempt = voiceVerification
                 ? sessionResponse.getBody().getNextCall()
                 : sessionResponse.getBody().getNextSms();
-        if (nextAttempt != null && nextAttempt > 0) {
+        if (nextAttempt == null) {
+            throw new VerificationMethoNotAvailableException();
+        } else if (nextAttempt > 0) {
             final var timestamp = sessionResponse.getHeaders().getTimestamp() + nextAttempt * 1000;
             throw new RateLimitException(timestamp);
         }
@@ -143,7 +150,7 @@ public class NumberVerificationUtils {
 
     private static RegistrationSessionMetadataResponse requestValidSession(
             final SignalServiceAccountManager accountManager
-    ) throws NoSuchSessionException, IOException {
+    ) throws IOException {
         return Utils.handleResponseException(accountManager.createRegistrationSession(null, "", ""));
     }
 
@@ -153,6 +160,7 @@ public class NumberVerificationUtils {
         try {
             return validateSession(accountManager, sessionId);
         } catch (NoSuchSessionException e) {
+            logger.debug("No registration session, creating new one.");
             return requestValidSession(accountManager);
         }
     }