]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java
Fix sending messages to groups
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / SignalAccountFiles.java
index 3821a30639feed52e031e92f8b78a85ad719f058..305b061d53be124d0d288aac0b8cd7dbf4aa1413 100644 (file)
@@ -41,20 +41,33 @@ public class SignalAccountFiles {
         this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(this.serviceEnvironment, userAgent);
         this.userAgent = userAgent;
         this.trustNewIdentity = trustNewIdentity;
-        this.accountsStore = new AccountsStore(pathConfig.dataPath());
+        this.accountsStore = new AccountsStore(pathConfig.dataPath(), serviceEnvironment, accountPath -> {
+            if (accountPath == null || !SignalAccount.accountFileExists(pathConfig.dataPath(), accountPath)) {
+                return null;
+            }
+
+            try {
+                return SignalAccount.load(pathConfig.dataPath(), accountPath, false, trustNewIdentity);
+            } catch (Exception e) {
+                return null;
+            }
+        });
     }
 
-    public Set<String> getAllLocalAccountNumbers() {
+    public Set<String> getAllLocalAccountNumbers() throws IOException {
         return accountsStore.getAllNumbers();
     }
 
-    public MultiAccountManager initMultiAccountManager() {
+    public MultiAccountManager initMultiAccountManager() throws IOException {
         final var managers = accountsStore.getAllAccounts().parallelStream().map(a -> {
             try {
                 return initManager(a.number(), a.path());
             } catch (NotRegisteredException | IOException | AccountCheckException e) {
                 logger.warn("Ignoring {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
                 return null;
+            } catch (Throwable e) {
+                logger.error("Failed to load {}: {} ({})", a.number(), e.getMessage(), e.getClass().getSimpleName());
+                throw e;
             }
         }).filter(Objects::nonNull).toList();
 
@@ -108,6 +121,7 @@ public class SignalAccountFiles {
 
         if (account.getServiceEnvironment() == null) {
             account.setServiceEnvironment(serviceEnvironment);
+            accountsStore.updateAccount(accountPath, account.getNumber(), account.getAci());
         }
 
         return manager;
@@ -138,6 +152,7 @@ public class SignalAccountFiles {
             var aciIdentityKey = KeyUtils.generateIdentityKeyPair();
             var pniIdentityKey = KeyUtils.generateIdentityKeyPair();
             var registrationId = KeyHelper.generateRegistrationId(false);
+            var pniRegistrationId = KeyHelper.generateRegistrationId(false);
 
             var profileKey = KeyUtils.createProfileKey();
             var account = SignalAccount.create(pathConfig.dataPath(),
@@ -147,6 +162,7 @@ public class SignalAccountFiles {
                     aciIdentityKey,
                     pniIdentityKey,
                     registrationId,
+                    pniRegistrationId,
                     profileKey,
                     trustNewIdentity);