X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/4ebacd0e1ff089ab961cbc557324801df46f33df..a91e3f762e0e5d6a9cf9e208fe85207d7829e22d:/lib/src/main/java/org/asamk/signal/manager/Manager.java diff --git a/lib/src/main/java/org/asamk/signal/manager/Manager.java b/lib/src/main/java/org/asamk/signal/manager/Manager.java index 45404154..9d73ac81 100644 --- a/lib/src/main/java/org/asamk/signal/manager/Manager.java +++ b/lib/src/main/java/org/asamk/signal/manager/Manager.java @@ -826,22 +826,33 @@ public class Manager implements Closeable { } public Pair> updateGroup( - GroupId groupId, String name, String description, List members, File avatarFile + GroupId groupId, + String name, + String description, + List members, + List removeMembers, + File avatarFile ) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException { return updateGroup(groupId, name, description, members == null ? null : getSignalServiceAddresses(members), + removeMembers == null ? null : getSignalServiceAddresses(removeMembers), avatarFile); } private Pair> updateGroup( - GroupId groupId, String name, String description, Set members, File avatarFile + GroupId groupId, + String name, + String description, + Set members, + final Set removeMembers, + File avatarFile ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException { var group = getGroupForUpdating(groupId); if (group instanceof GroupInfoV2) { - return updateGroupV2((GroupInfoV2) group, name, description, members, avatarFile); + return updateGroupV2((GroupInfoV2) group, name, description, members, removeMembers, avatarFile); } return updateGroupV1((GroupInfoV1) group, name, members, avatarFile); @@ -901,6 +912,7 @@ public class Manager implements Closeable { final String name, final String description, final Set members, + final Set removeMembers, final File avatarFile ) throws IOException { Pair> result = null; @@ -917,6 +929,24 @@ public class Manager implements Closeable { result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); } } + + if (removeMembers != null) { + var existingRemoveMembers = new HashSet<>(removeMembers); + existingRemoveMembers.retainAll(group.getMembers()); + existingRemoveMembers.remove(getSelfRecipientId());// self can be removed with sendQuitGroupMessage + if (existingRemoveMembers.size() > 0) { + var groupGroupChangePair = groupHelper.removeMembers(group, existingRemoveMembers); + result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); + } + + var pendingRemoveMembers = new HashSet<>(removeMembers); + pendingRemoveMembers.retainAll(group.getPendingMembers()); + if (pendingRemoveMembers.size() > 0) { + var groupGroupChangePair = groupHelper.revokeInvitedMembers(group, pendingRemoveMembers); + result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); + } + } + if (result == null || name != null || description != null || avatarFile != null) { var groupGroupChangePair = groupHelper.updateGroupV2(group, name, description, avatarFile); if (avatarFile != null) { @@ -954,10 +984,14 @@ public class Manager implements Closeable { private Pair> sendUpdateGroupV2Message( GroupInfoV2 group, DecryptedGroup newDecryptedGroup, GroupChange groupChange ) throws IOException { + final var selfRecipientId = account.getSelfRecipientId(); + final var members = group.getMembersIncludingPendingWithout(selfRecipientId); group.setGroup(newDecryptedGroup, this::resolveRecipient); + members.addAll(group.getMembersIncludingPendingWithout(selfRecipientId)); + final var messageBuilder = getGroupUpdateMessageBuilder(group, groupChange.toByteArray()); account.getGroupStore().updateGroup(group); - return sendMessage(messageBuilder, group.getMembersIncludingPendingWithout(account.getSelfRecipientId())); + return sendMessage(messageBuilder, members); } private static int currentTimeDays() {