mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Split load function
This commit is contained in:
parent
f97b0c0faa
commit
6c9f26f49b
2 changed files with 32 additions and 23 deletions
|
@ -110,7 +110,7 @@ public class Main {
|
||||||
ts = m;
|
ts = m;
|
||||||
if (m.userExists()) {
|
if (m.userExists()) {
|
||||||
try {
|
try {
|
||||||
m.load();
|
m.init();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage());
|
System.err.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage());
|
||||||
return 2;
|
return 2;
|
||||||
|
|
|
@ -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();
|
openFileChannel();
|
||||||
JsonNode rootNode = jsonProcessot.readTree(Channels.newInputStream(fileChannel));
|
JsonNode rootNode = jsonProcessot.readTree(Channels.newInputStream(fileChannel));
|
||||||
|
|
||||||
|
@ -243,10 +259,21 @@ class Manager implements Signal {
|
||||||
if (groupStore == null) {
|
if (groupStore == null) {
|
||||||
groupStore = new JsonGroupStore();
|
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
|
// Copy group avatars that were previously stored in the attachments folder
|
||||||
// to the new avatar folder
|
// to the new avatar folder
|
||||||
if (groupStore.groupsWithLegacyAvatarId.size() > 0) {
|
if (JsonGroupStore.groupsWithLegacyAvatarId.size() > 0) {
|
||||||
for (GroupInfo g : groupStore.groupsWithLegacyAvatarId) {
|
for (GroupInfo g : JsonGroupStore.groupsWithLegacyAvatarId) {
|
||||||
File avatarFile = getGroupAvatarFile(g.groupId);
|
File avatarFile = getGroupAvatarFile(g.groupId);
|
||||||
File attachmentFile = getAttachmentFile(g.getAvatarId());
|
File attachmentFile = getAttachmentFile(g.getAvatarId());
|
||||||
if (!avatarFile.exists() && attachmentFile.exists()) {
|
if (!avatarFile.exists() && attachmentFile.exists()) {
|
||||||
|
@ -258,27 +285,9 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groupStore.groupsWithLegacyAvatarId.clear();
|
JsonGroupStore.groupsWithLegacyAvatarId.clear();
|
||||||
save();
|
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() {
|
private void save() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue