]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/helper/AccountHelper.java
Update self identifiers after whoAmI request
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / helper / AccountHelper.java
index 3e60ce74281ba8e5b9d91aaf1743ddf446340dae..6b7f68f40ea6dd8b94506bd4cd5e74d0a2d770be 100644 (file)
@@ -52,9 +52,7 @@ public class AccountHelper {
         try {
             context.getPreKeyHelper().refreshPreKeysIfNecessary();
             if (account.getAci() == null) {
-                final var aci = ACI.parseOrNull(dependencies.getAccountManager().getWhoAmI().getAci());
-                account.setAci(aci);
-                context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), aci);
+                checkWhoAmiI();
             }
             updateAccountAttributes();
         } catch (AuthorizationFailedException e) {
@@ -63,6 +61,27 @@ public class AccountHelper {
         }
     }
 
+    public void checkWhoAmiI() throws IOException {
+        final var whoAmI = dependencies.getAccountManager().getWhoAmI();
+        final var number = whoAmI.getNumber();
+        final var aci = ACI.parseOrNull(whoAmI.getAci());
+        if (number.equals(account.getNumber()) && aci.equals(account.getAci())) {
+            return;
+        }
+
+        updateSelfIdentifiers(number, aci);
+    }
+
+    private void updateSelfIdentifiers(final String number, final ACI aci) {
+        account.setNumber(number);
+        account.setAci(aci);
+        account.getRecipientStore().resolveRecipientTrusted(account.getSelfRecipientAddress());
+        context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), account.getAci());
+        // TODO check and update remote storage
+        context.getUnidentifiedAccessHelper().rotateSenderCertificates();
+        dependencies.getSignalWebSocket().forceNewWebSockets();
+    }
+
     public void setDeviceName(String deviceName) {
         final var privateKey = account.getIdentityKeyPair().getPrivateKey();
         final var encryptedDeviceName = DeviceNameUtil.encryptDeviceName(deviceName, privateKey);