]> nmode's Git Repositories - signal-cli/commitdiff
Update groups when using listGroups command
authorAsamK <asamk@gmx.de>
Thu, 6 Jun 2024 08:03:27 +0000 (10:03 +0200)
committerAsamK <asamk@gmx.de>
Thu, 6 Jun 2024 08:07:20 +0000 (10:07 +0200)
Fixes #1517

lib/src/main/java/org/asamk/signal/manager/helper/GroupHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/SendHelper.java
lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java

index 0c15ceff3751d9dd800edbf5cfb5f5b2fffd6e5f..7cc9fef8f47465c6ddffdc4934d21673d9e96d50 100644 (file)
@@ -79,6 +79,12 @@ public class GroupHelper {
         return getGroup(groupId, false);
     }
 
         return getGroup(groupId, false);
     }
 
+    public List<GroupInfo> getGroups() {
+        final var groups = account.getGroupStore().getGroups();
+        groups.forEach(group -> fillOrUpdateGroup(group, false));
+        return groups;
+    }
+
     public boolean isGroupBlocked(final GroupId groupId) {
         var group = getGroup(groupId);
         return group != null && group.isBlocked();
     public boolean isGroupBlocked(final GroupId groupId) {
         var group = getGroup(groupId);
         return group != null && group.isBlocked();
@@ -382,34 +388,46 @@ public class GroupHelper {
 
     private GroupInfo getGroup(GroupId groupId, boolean forceUpdate) {
         final var group = account.getGroupStore().getGroup(groupId);
 
     private GroupInfo getGroup(GroupId groupId, boolean forceUpdate) {
         final var group = account.getGroupStore().getGroup(groupId);
-        if (group instanceof GroupInfoV2 groupInfoV2) {
-            if (forceUpdate || (!groupInfoV2.isPermissionDenied() && groupInfoV2.getGroup() == null)) {
-                final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
-                DecryptedGroup decryptedGroup;
-                try {
-                    decryptedGroup = context.getGroupV2Helper().getDecryptedGroup(groupSecretParams);
-                } catch (NotAGroupMemberException e) {
-                    groupInfoV2.setPermissionDenied(true);
-                    decryptedGroup = null;
-                }
-                if (decryptedGroup != null) {
-                    try {
-                        storeProfileKeysFromHistory(groupSecretParams, groupInfoV2, decryptedGroup);
-                    } catch (NotAGroupMemberException ignored) {
-                    }
-                    storeProfileKeysFromMembers(decryptedGroup);
-                    final var avatar = decryptedGroup.avatar;
-                    if (!avatar.isEmpty()) {
-                        downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar);
-                    }
-                }
-                groupInfoV2.setGroup(decryptedGroup);
-                account.getGroupStore().updateGroup(group);
-            }
-        }
+        fillOrUpdateGroup(group, forceUpdate);
         return group;
     }
 
         return group;
     }
 
+    private void fillOrUpdateGroup(final GroupInfo group, final boolean forceUpdate) {
+        if (!(group instanceof GroupInfoV2 groupInfoV2)) {
+            return;
+        }
+
+        if (!forceUpdate && (groupInfoV2.isPermissionDenied() || groupInfoV2.getGroup() != null)) {
+            return;
+        }
+
+        final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
+        DecryptedGroup decryptedGroup;
+        try {
+            decryptedGroup = context.getGroupV2Helper().getDecryptedGroup(groupSecretParams);
+        } catch (NotAGroupMemberException e) {
+            groupInfoV2.setPermissionDenied(true);
+            account.getGroupStore().updateGroup(group);
+            return;
+        }
+
+        if (decryptedGroup == null) {
+            return;
+        }
+
+        try {
+            storeProfileKeysFromHistory(groupSecretParams, groupInfoV2, decryptedGroup);
+        } catch (NotAGroupMemberException ignored) {
+        }
+        storeProfileKeysFromMembers(decryptedGroup);
+        final var avatar = decryptedGroup.avatar;
+        if (!avatar.isEmpty()) {
+            downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar);
+        }
+        groupInfoV2.setGroup(decryptedGroup);
+        account.getGroupStore().updateGroup(group);
+    }
+
     private void downloadGroupAvatar(GroupIdV2 groupId, GroupSecretParams groupSecretParams, String cdnKey) {
         try {
             context.getAvatarStore()
     private void downloadGroupAvatar(GroupIdV2 groupId, GroupSecretParams groupSecretParams, String cdnKey) {
         try {
             context.getAvatarStore()
index a066c85107adb76ea4672ed463ba4eeef11d1ea9..0ff7fd89c6de48e791c0d4f539a6220b43121402 100644 (file)
@@ -261,7 +261,7 @@ public class SendHelper {
         }
 
         final var groupId = messageSendLogEntry.groupId().get();
         }
 
         final var groupId = messageSendLogEntry.groupId().get();
-        final var group = account.getGroupStore().getGroup(groupId);
+        final var group = context.getGroupHelper().getGroup(groupId);
 
         if (group == null) {
             logger.debug("Could not find a matching group for the groupId {}! Skipping message send.",
 
         if (group == null) {
             logger.debug("Could not find a matching group for the groupId {}! Skipping message send.",
index c21a150e4d26dfb77a9a9322c4b7bedab1fc2f27..13785a949904f6a5661d193b8fbc391d6fea08f5 100644 (file)
@@ -511,7 +511,7 @@ public class ManagerImpl implements Manager {
 
     @Override
     public List<Group> getGroups() {
 
     @Override
     public List<Group> getGroups() {
-        return account.getGroupStore().getGroups().stream().map(this::toGroup).toList();
+        return context.getGroupHelper().getGroups().stream().map(this::toGroup).toList();
     }
 
     private Group toGroup(final GroupInfo groupInfo) {
     }
 
     private Group toGroup(final GroupInfo groupInfo) {