diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java index e24816bc..3dac4876 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java @@ -229,22 +229,26 @@ public class GroupStore { public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) { try (final var connection = database.getConnection()) { - var group = getGroup(connection, groupId); - - if (group != null) { - return group; - } - - if (getGroupV2ByV1Id(connection, groupId) == null) { - return new GroupInfoV1(groupId); - } - - return null; + return getOrCreateGroupV1(connection, groupId); } catch (SQLException e) { throw new RuntimeException("Failed read from group store", e); } } + public GroupInfoV1 getOrCreateGroupV1(final Connection connection, final GroupIdV1 groupId) throws SQLException { + var group = getGroup(connection, groupId); + + if (group != null) { + return group; + } + + if (getGroupV2ByV1Id(connection, groupId) == null) { + return new GroupInfoV1(groupId); + } + + return null; + } + public GroupInfoV2 getGroupOrPartialMigrate( Connection connection, final GroupMasterKey groupMasterKey ) throws SQLException { diff --git a/lib/src/main/java/org/asamk/signal/manager/syncStorage/GroupV1RecordProcessor.java b/lib/src/main/java/org/asamk/signal/manager/syncStorage/GroupV1RecordProcessor.java index be95591b..14d3c882 100644 --- a/lib/src/main/java/org/asamk/signal/manager/syncStorage/GroupV1RecordProcessor.java +++ b/lib/src/main/java/org/asamk/signal/manager/syncStorage/GroupV1RecordProcessor.java @@ -112,14 +112,16 @@ public final class GroupV1RecordProcessor extends DefaultStorageRecordProcessor< 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