]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java
Refactor signed pre key store
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / RegistrationManager.java
index 6ded4d0bb550ae0e8abdabe91270135df6634193..a16ead37c3a26b5680cb1add71d50d43c054fe09 100644 (file)
@@ -128,7 +128,7 @@ public class RegistrationManager implements Closeable {
         account.save();
     }
 
-    public void verifyAccount(
+    public Manager verifyAccount(
             String verificationCode, String pin
     ) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
         verificationCode = verificationCode.replace("-", "");
@@ -163,20 +163,30 @@ public class RegistrationManager implements Closeable {
         account.setRegistered(true);
         account.setUuid(UuidUtil.parseOrNull(response.getUuid()));
         account.setRegistrationLockPin(pin);
-        account.getSignalProtocolStore().archiveAllSessions();
+        account.getSessionStore().archiveAllSessions();
         account.getSignalProtocolStore()
                 .saveIdentity(account.getSelfAddress(),
-                        account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey(),
+                        account.getIdentityKeyPair().getPublicKey(),
                         TrustLevel.TRUSTED_VERIFIED);
 
-        try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
+        Manager m = null;
+        try {
+            m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
 
             m.refreshPreKeys();
 
-            m.close(false);
-        }
+            account.save();
 
-        account.save();
+            final var result = m;
+            account = null;
+            m = null;
+
+            return result;
+        } finally {
+            if (m != null) {
+                m.close();
+            }
+        }
     }
 
     private VerifyAccountResponse verifyAccountWithCode(
@@ -184,7 +194,7 @@ public class RegistrationManager implements Closeable {
     ) throws IOException {
         return accountManager.verifyAccountWithCode(verificationCode,
                 null,
-                account.getSignalProtocolStore().getLocalRegistrationId(),
+                account.getLocalRegistrationId(),
                 true,
                 legacyPin,
                 registrationLock,