]> nmode's Git Repositories - signal-cli/commitdiff
Use base64 group id for protobuf group file to match avatar files
authorAsamK <asamk@gmx.de>
Fri, 25 Dec 2020 12:46:35 +0000 (13:46 +0100)
committerAsamK <asamk@gmx.de>
Fri, 25 Dec 2020 12:46:35 +0000 (13:46 +0100)
base64 with '/' replaced by '_'

src/main/java/org/asamk/signal/storage/groups/JsonGroupStore.java

index d6a99f1c278752e9972437ce97720baea240f74b..6f0f3c04a5cfbf8a47cbfa97b46da5c1ee8f5c29 100644 (file)
@@ -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) {