]> nmode's Git Repositories - signal-cli/commitdiff
Split load function
authorAsamK <asamk@gmx.de>
Thu, 27 Oct 2016 14:03:20 +0000 (16:03 +0200)
committerAsamK <asamk@gmx.de>
Thu, 27 Oct 2016 14:03:20 +0000 (16:03 +0200)
src/main/java/org/asamk/signal/Main.java
src/main/java/org/asamk/signal/Manager.java

index fbdc0ce120410d0857f2d86d4fe4b3948c0cb21a..5dd471f94f4fa1d25dc0cc66b2c29d4894f74aea 100644 (file)
@@ -110,7 +110,7 @@ public class Main {
                 ts = m;
                 if (m.userExists()) {
                     try {
-                        m.load();
+                        m.init();
                     } catch (Exception e) {
                         System.err.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage());
                         return 2;
index e02258f19918967c9e9f3afeec3454c8c1a8cf63..34bb5068ba5c03ad726c5489c70d0fcba7a74c3a 100644 (file)
@@ -211,7 +211,23 @@ class Manager implements Signal {
         }
     }
 
-    public void load() throws IOException, InvalidKeyException {
+    public void init() throws IOException {
+        load();
+
+        migrateLegacyConfigs();
+
+        accountManager = new SignalServiceAccountManager(URL, TRUST_STORE, username, password, deviceId, USER_AGENT);
+        try {
+            if (registered && accountManager.getPreKeysCount() < PREKEY_MINIMUM_COUNT) {
+                refreshPreKeys();
+                save();
+            }
+        } catch (AuthorizationFailedException e) {
+            System.err.println("Authorization failed, was the number registered elsewhere?");
+        }
+    }
+
+    private void load() throws IOException {
         openFileChannel();
         JsonNode rootNode = jsonProcessot.readTree(Channels.newInputStream(fileChannel));
 
@@ -243,10 +259,21 @@ class Manager implements Signal {
         if (groupStore == null) {
             groupStore = new JsonGroupStore();
         }
+
+        JsonNode contactStoreNode = rootNode.get("contactStore");
+        if (contactStoreNode != null) {
+            contactStore = jsonProcessot.convertValue(contactStoreNode, JsonContactsStore.class);
+        }
+        if (contactStore == null) {
+            contactStore = new JsonContactsStore();
+        }
+    }
+
+    private void migrateLegacyConfigs() {
         // Copy group avatars that were previously stored in the attachments folder
         // to the new avatar folder
-        if (groupStore.groupsWithLegacyAvatarId.size() > 0) {
-            for (GroupInfo g : groupStore.groupsWithLegacyAvatarId) {
+        if (JsonGroupStore.groupsWithLegacyAvatarId.size() > 0) {
+            for (GroupInfo g : JsonGroupStore.groupsWithLegacyAvatarId) {
                 File avatarFile = getGroupAvatarFile(g.groupId);
                 File attachmentFile = getAttachmentFile(g.getAvatarId());
                 if (!avatarFile.exists() && attachmentFile.exists()) {
@@ -258,27 +285,9 @@ class Manager implements Signal {
                     }
                 }
             }
-            groupStore.groupsWithLegacyAvatarId.clear();
+            JsonGroupStore.groupsWithLegacyAvatarId.clear();
             save();
         }
-
-        JsonNode contactStoreNode = rootNode.get("contactStore");
-        if (contactStoreNode != null) {
-            contactStore = jsonProcessot.convertValue(contactStoreNode, JsonContactsStore.class);
-        }
-        if (contactStore == null) {
-            contactStore = new JsonContactsStore();
-        }
-
-        accountManager = new SignalServiceAccountManager(URL, TRUST_STORE, username, password, deviceId, USER_AGENT);
-        try {
-            if (registered && accountManager.getPreKeysCount() < PREKEY_MINIMUM_COUNT) {
-                refreshPreKeys();
-                save();
-            }
-        } catch (AuthorizationFailedException e) {
-            System.err.println("Authorization failed, was the number registered elsewhere?");
-        }
     }
 
     private void save() {