]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java
Update libsignal-service-java
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / SignalAccountFiles.java
index f1d37e81acbd9f2fd640d11fdca5047e74ff8ada..0ca9b0abbdebf4588b0d19f3e210572ab92d1efd 100644 (file)
@@ -9,9 +9,9 @@ import org.asamk.signal.manager.storage.SignalAccount;
 import org.asamk.signal.manager.storage.accounts.AccountsStore;
 import org.asamk.signal.manager.storage.identities.TrustNewIdentity;
 import org.asamk.signal.manager.util.KeyUtils;
+import org.signal.libsignal.protocol.util.KeyHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.whispersystems.libsignal.util.KeyHelper;
 
 import java.io.File;
 import java.io.IOException;
@@ -34,7 +34,7 @@ public class SignalAccountFiles {
             final ServiceEnvironment serviceEnvironment,
             final String userAgent,
             final TrustNewIdentity trustNewIdentity
-    ) {
+    ) throws IOException {
         this.pathConfig = PathConfig.createDefault(settingsPath);
         this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(serviceEnvironment, userAgent);
         this.userAgent = userAgent;
@@ -47,11 +47,11 @@ public class SignalAccountFiles {
     }
 
     public MultiAccountManager initMultiAccountManager() {
-        final var managers = getAllLocalAccountNumbers().stream().map(a -> {
+        final var managers = accountsStore.getAllAccounts().parallelStream().map(a -> {
             try {
-                return initManager(a);
+                return initManager(a.number(), a.path());
             } catch (NotRegisteredException | IOException | AccountCheckException e) {
-                logger.warn("Ignoring {}: {} ({})", a, e.getMessage(), e.getClass().getSimpleName());
+                logger.warn("Ignoring {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
                 return null;
             }
         }).filter(Objects::nonNull).toList();
@@ -61,7 +61,16 @@ public class SignalAccountFiles {
 
     public Manager initManager(String number) throws IOException, NotRegisteredException, AccountCheckException {
         final var accountPath = accountsStore.getPathByNumber(number);
-        if (accountPath == null || !SignalAccount.accountFileExists(pathConfig.dataPath(), accountPath)) {
+        return this.initManager(number, accountPath);
+    }
+
+    private Manager initManager(
+            String number, String accountPath
+    ) throws IOException, NotRegisteredException, AccountCheckException {
+        if (accountPath == null) {
+            throw new NotRegisteredException();
+        }
+        if (!SignalAccount.accountFileExists(pathConfig.dataPath(), accountPath)) {
             throw new NotRegisteredException();
         }
 
@@ -116,14 +125,16 @@ public class SignalAccountFiles {
         final var accountPath = accountsStore.getPathByNumber(number);
         if (accountPath == null || !SignalAccount.accountFileExists(pathConfig.dataPath(), accountPath)) {
             final var newAccountPath = accountPath == null ? accountsStore.addAccount(number, null) : accountPath;
-            var identityKey = KeyUtils.generateIdentityKeyPair();
+            var aciIdentityKey = KeyUtils.generateIdentityKeyPair();
+            var pniIdentityKey = KeyUtils.generateIdentityKeyPair();
             var registrationId = KeyHelper.generateRegistrationId(false);
 
             var profileKey = KeyUtils.createProfileKey();
             var account = SignalAccount.create(pathConfig.dataPath(),
                     newAccountPath,
                     number,
-                    identityKey,
+                    aciIdentityKey,
+                    pniIdentityKey,
                     registrationId,
                     profileKey,
                     trustNewIdentity);