From: AsamK Date: Fri, 25 Dec 2020 12:46:35 +0000 (+0100) Subject: Use base64 group id for protobuf group file to match avatar files X-Git-Tag: v0.7.2~9 X-Git-Url: https://git.nmode.ca/signal-cli/commitdiff_plain/6a82029ab481eb657847651b4f5200acf57b2553?ds=sidebyside Use base64 group id for protobuf group file to match avatar files base64 with '/' replaced by '_' --- diff --git a/src/main/java/org/asamk/signal/storage/groups/JsonGroupStore.java b/src/main/java/org/asamk/signal/storage/groups/JsonGroupStore.java index d6a99f1c..6f0f3c04 100644 --- a/src/main/java/org/asamk/signal/storage/groups/JsonGroupStore.java +++ b/src/main/java/org/asamk/signal/storage/groups/JsonGroupStore.java @@ -58,6 +58,10 @@ public class JsonGroupStore { try (FileOutputStream stream = new FileOutputStream(getGroupFile(group.getGroupId()))) { ((GroupInfoV2) group).getGroup().writeTo(stream); } + final File groupFileLegacy = getGroupFileLegacy(group.getGroupId()); + if (groupFileLegacy.exists()) { + groupFileLegacy.delete(); + } } catch (IOException e) { System.err.println("Failed to cache group, ignoring ..."); } @@ -95,17 +99,28 @@ public class JsonGroupStore { private void loadDecryptedGroup(final GroupInfo group) { if (group instanceof GroupInfoV2 && ((GroupInfoV2) group).getGroup() == null) { - try (FileInputStream stream = new FileInputStream(getGroupFile(group.getGroupId()))) { + File groupFile = getGroupFile(group.getGroupId()); + if (!groupFile.exists()) { + groupFile = getGroupFileLegacy(group.getGroupId()); + } + if (!groupFile.exists()) { + return; + } + try (FileInputStream stream = new FileInputStream(groupFile)) { ((GroupInfoV2) group).setGroup(DecryptedGroup.parseFrom(stream)); } catch (IOException ignored) { } } } - private File getGroupFile(final GroupId groupId) { + private File getGroupFileLegacy(final GroupId groupId) { return new File(groupCachePath, Hex.toStringCondensed(groupId.serialize())); } + private File getGroupFile(final GroupId groupId) { + return new File(groupCachePath, groupId.toBase64().replace("/", "_")); + } + public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) { GroupInfo group = getGroup(groupId); if (group instanceof GroupInfoV1) {