]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/RegistrationManagerImpl.java
Better logging for registration failure
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / RegistrationManagerImpl.java
index f5bff4d278e406fb1381028044045c29acb3f21a..0e3c9af003178730fbe2d8f96340117f374fe431 100644 (file)
@@ -29,6 +29,7 @@ import org.asamk.signal.manager.helper.PinHelper;
 import org.asamk.signal.manager.storage.SignalAccount;
 import org.asamk.signal.manager.util.NumberVerificationUtils;
 import org.asamk.signal.manager.util.Utils;
+import org.signal.libsignal.usernames.BaseUsernameException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.whispersystems.signalservice.api.SignalServiceAccountManager;
@@ -38,6 +39,7 @@ import org.whispersystems.signalservice.api.push.ACI;
 import org.whispersystems.signalservice.api.push.PNI;
 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
 import org.whispersystems.signalservice.api.push.exceptions.AlreadyVerifiedException;
+import org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException;
 import org.whispersystems.signalservice.internal.push.VerifyAccountResponse;
 import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider;
 
@@ -113,16 +115,21 @@ class RegistrationManagerImpl implements RegistrationManager {
             throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment());
         }
 
-        if (account.getAci() != null && attemptReactivateAccount()) {
-            return;
-        }
+        try {
+            if (account.getAci() != null && attemptReactivateAccount()) {
+                return;
+            }
 
-        String sessionId = NumberVerificationUtils.handleVerificationSession(accountManager,
-                account.getSessionId(account.getNumber()),
-                id -> account.setSessionId(account.getNumber(), id),
-                voiceVerification,
-                captcha);
-        NumberVerificationUtils.requestVerificationCode(accountManager, sessionId, voiceVerification);
+            String sessionId = NumberVerificationUtils.handleVerificationSession(accountManager,
+                    account.getSessionId(account.getNumber()),
+                    id -> account.setSessionId(account.getNumber(), id),
+                    voiceVerification,
+                    captcha);
+            NumberVerificationUtils.requestVerificationCode(accountManager, sessionId, voiceVerification);
+        } catch (DeprecatedVersionException e) {
+            logger.debug("Signal-Server returned deprecated version exception", e);
+            throw e;
+        }
     }
 
     @Override
@@ -163,6 +170,12 @@ class RegistrationManagerImpl implements RegistrationManager {
                 logger.warn("Failed to set default profile: {}", e.getMessage());
             }
 
+            try {
+                m.refreshCurrentUsername();
+            } catch (IOException | BaseUsernameException e) {
+                logger.warn("Failed to refresh current username", e);
+            }
+
             if (newManagerListener != null) {
                 newManagerListener.accept(m);
                 m = null;