]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/SignalAccountFiles.java
Store information if account is registerd on LIVE or STAGING env in account file
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / SignalAccountFiles.java
index 0ca9b0abbdebf4588b0d19f3e210572ab92d1efd..5f0f551c5dfc800afa3df596ff9d9480fd89cebb 100644 (file)
@@ -24,6 +24,7 @@ public class SignalAccountFiles {
     private static final Logger logger = LoggerFactory.getLogger(MultiAccountManager.class);
 
     private final PathConfig pathConfig;
+    private final ServiceEnvironment serviceEnvironment;
     private final ServiceEnvironmentConfig serviceEnvironmentConfig;
     private final String userAgent;
     private final TrustNewIdentity trustNewIdentity;
@@ -36,7 +37,8 @@ public class SignalAccountFiles {
             final TrustNewIdentity trustNewIdentity
     ) throws IOException {
         this.pathConfig = PathConfig.createDefault(settingsPath);
-        this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(serviceEnvironment, userAgent);
+        this.serviceEnvironment = serviceEnvironment;
+        this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(this.serviceEnvironment, userAgent);
         this.userAgent = userAgent;
         this.trustNewIdentity = trustNewIdentity;
         this.accountsStore = new AccountsStore(pathConfig.dataPath());
@@ -85,6 +87,10 @@ public class SignalAccountFiles {
             throw new NotRegisteredException();
         }
 
+        if (account.getServiceEnvironment() != null && account.getServiceEnvironment() != serviceEnvironment) {
+            throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment());
+        }
+
         account.initDatabase();
 
         final var manager = new ManagerImpl(account,
@@ -100,6 +106,10 @@ public class SignalAccountFiles {
             throw new AccountCheckException("Error while checking account " + number + ": " + e.getMessage(), e);
         }
 
+        if (account.getServiceEnvironment() == null) {
+            account.setServiceEnvironment(serviceEnvironment);
+        }
+
         return manager;
     }
 
@@ -133,6 +143,7 @@ public class SignalAccountFiles {
             var account = SignalAccount.create(pathConfig.dataPath(),
                     newAccountPath,
                     number,
+                    serviceEnvironment,
                     aciIdentityKey,
                     pniIdentityKey,
                     registrationId,