]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java
Extend updateProfile command to set family name
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / RegistrationManager.java
index a16ead37c3a26b5680cb1add71d50d43c054fe09..612984edbdd78f50e047eb44b931bb922277b3fb 100644 (file)
@@ -29,6 +29,7 @@ import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
 import org.whispersystems.signalservice.api.SignalServiceAccountManager;
 import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
 import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
+import org.whispersystems.signalservice.api.kbs.MasterKey;
 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
 import org.whispersystems.signalservice.api.util.SleepTimer;
 import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
@@ -102,7 +103,6 @@ public class RegistrationManager implements Closeable {
                     identityKey,
                     registrationId,
                     profileKey);
-            account.save();
 
             return new RegistrationManager(account, pathConfig, serviceConfiguration, userAgent);
         }
@@ -113,10 +113,6 @@ public class RegistrationManager implements Closeable {
     }
 
     public void register(boolean voiceVerification, String captcha) throws IOException {
-        if (account.getPassword() == null) {
-            account.setPassword(KeyUtils.createPassword());
-        }
-
         if (voiceVerification) {
             accountManager.requestVoiceVerificationCode(Locale.getDefault(),
                     Optional.fromNullable(captcha),
@@ -124,18 +120,18 @@ public class RegistrationManager implements Closeable {
         } else {
             accountManager.requestSmsVerificationCode(false, Optional.fromNullable(captcha), Optional.absent());
         }
-
-        account.save();
     }
 
     public Manager verifyAccount(
             String verificationCode, String pin
-    ) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
+    ) throws IOException, LockedException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
         verificationCode = verificationCode.replace("-", "");
         VerifyAccountResponse response;
+        MasterKey masterKey;
         try {
             response = verifyAccountWithCode(verificationCode, pin, null);
-            account.setPinMasterKey(null);
+
+            masterKey = null;
         } catch (LockedException e) {
             if (pin == null) {
                 throw e;
@@ -152,33 +148,23 @@ public class RegistrationManager implements Closeable {
             } catch (LockedException _e) {
                 throw new AssertionError("KBS Pin appeared to matched but reg lock still failed!");
             }
-            account.setPinMasterKey(registrationLockData.getMasterKey());
+            masterKey = registrationLockData.getMasterKey();
         }
 
         // TODO response.isStorageCapable()
         //accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
-
-        account.setDeviceId(SignalServiceAddress.DEFAULT_DEVICE_ID);
-        account.setMultiDevice(false);
-        account.setRegistered(true);
-        account.setUuid(UuidUtil.parseOrNull(response.getUuid()));
-        account.setRegistrationLockPin(pin);
-        account.getSessionStore().archiveAllSessions();
-        account.getSignalProtocolStore()
-                .saveIdentity(account.getSelfAddress(),
-                        account.getIdentityKeyPair().getPublicKey(),
-                        TrustLevel.TRUSTED_VERIFIED);
+        account.finishRegistration(UuidUtil.parseOrNull(response.getUuid()), masterKey, pin);
 
         Manager m = null;
         try {
             m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
+            account = null;
 
             m.refreshPreKeys();
-
-            account.save();
+            // Set an initial empty profile so user can be added to groups
+            m.setProfile(null, null, null, null, null);
 
             final var result = m;
-            account = null;
             m = null;
 
             return result;