]> nmode's Git Repositories - signal-cli/commitdiff
Prevent crash when receiving already migrated group v1 from storage
authorAsamK <asamk@gmx.de>
Sun, 25 Feb 2024 18:41:10 +0000 (19:41 +0100)
committerAsamK <asamk@gmx.de>
Sun, 25 Feb 2024 18:41:10 +0000 (19:41 +0100)
Fixes #1471

lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java
lib/src/main/java/org/asamk/signal/manager/syncStorage/GroupV1RecordProcessor.java

index e24816bc38c0d0e6df00efc0456eb6a055126c68..3dac4876288befe196bcf51e02d8f52a21a62a4e 100644 (file)
@@ -229,20 +229,24 @@ public class GroupStore {
 
     public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) {
         try (final var connection = database.getConnection()) {
 
     public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) {
         try (final var connection = database.getConnection()) {
-            var group = getGroup(connection, groupId);
+            return getOrCreateGroupV1(connection, groupId);
+        } catch (SQLException e) {
+            throw new RuntimeException("Failed read from group store", e);
+        }
+    }
 
 
-            if (group != null) {
-                return group;
-            }
+    public GroupInfoV1 getOrCreateGroupV1(final Connection connection, final GroupIdV1 groupId) throws SQLException {
+        var group = getGroup(connection, groupId);
 
 
-            if (getGroupV2ByV1Id(connection, groupId) == null) {
-                return new GroupInfoV1(groupId);
-            }
+        if (group != null) {
+            return group;
+        }
 
 
-            return null;
-        } catch (SQLException e) {
-            throw new RuntimeException("Failed read from group store", e);
+        if (getGroupV2ByV1Id(connection, groupId) == null) {
+            return new GroupInfoV1(groupId);
         }
         }
+
+        return null;
     }
 
     public GroupInfoV2 getGroupOrPartialMigrate(
     }
 
     public GroupInfoV2 getGroupOrPartialMigrate(
index be95591bda9d86004c04969c30a333404dae4ded..14d3c882e9fd4316c303c18bdf146000ba709279 100644 (file)
@@ -112,14 +112,16 @@ public final class GroupV1RecordProcessor extends DefaultStorageRecordProcessor<
         final var groupV1Record = update.newRecord();
         final var groupIdV1 = GroupId.v1(groupV1Record.getGroupId());
 
         final var groupV1Record = update.newRecord();
         final var groupIdV1 = GroupId.v1(groupV1Record.getGroupId());
 
-        final var group = account.getGroupStore().getGroup(connection, groupIdV1);
-        group.setBlocked(groupV1Record.isBlocked());
-        account.getGroupStore().updateGroup(connection, group);
-        account.getGroupStore()
-                .storeStorageRecord(connection,
-                        group.getGroupId(),
-                        groupV1Record.getId(),
-                        groupV1Record.toProto().encode());
+        final var group = account.getGroupStore().getOrCreateGroupV1(connection, groupIdV1);
+        if (group != null) {
+            group.setBlocked(groupV1Record.isBlocked());
+            account.getGroupStore().updateGroup(connection, group);
+            account.getGroupStore()
+                    .storeStorageRecord(connection,
+                            group.getGroupId(),
+                            groupV1Record.getId(),
+                            groupV1Record.toProto().encode());
+        }
     }
 
     @Override
     }
 
     @Override