]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/UnblockCommand.java
Refactor set blocked methods to accept multiple recipientIds/groupIds
[signal-cli] / src / main / java / org / asamk / signal / commands / UnblockCommand.java
index af49236cdbd7fae84142165f4ed13e16e565572b..4cfe46478000861cb2ba32f7d6eed88d3ebaad4b 100644 (file)
@@ -37,30 +37,28 @@ public class UnblockCommand implements JsonRpcLocalCommand {
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
-        for (var contactNumber : CommandUtil.getSingleRecipientIdentifiers(ns.getList("recipient"),
-                m.getSelfNumber())) {
-            try {
-                m.setContactBlocked(contactNumber, false);
-            } catch (NotMasterDeviceException e) {
-                throw new UserErrorException("This command doesn't work on linked devices.");
-            } catch (IOException e) {
-                throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage(), e);
-            } catch (UnregisteredRecipientException e) {
-                throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
-            }
+        final var contacts = ns.<String>getList("recipient");
+        final var recipients = CommandUtil.getSingleRecipientIdentifiers(contacts, m.getSelfNumber());
+        try {
+            m.setContactsBlocked(recipients, false);
+        } catch (NotMasterDeviceException e) {
+            throw new UserErrorException("This command doesn't work on linked devices.");
+        } catch (IOException e) {
+            throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage(), e);
+        } catch (UnregisteredRecipientException e) {
+            throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
         }
 
         final var groupIdStrings = ns.<String>getList("group-id");
-        for (var groupId : CommandUtil.getGroupIds(groupIdStrings)) {
-            try {
-                m.setGroupBlocked(groupId, false);
-            } catch (NotMasterDeviceException e) {
-                throw new UserErrorException("This command doesn't work on linked devices.");
-            } catch (GroupNotFoundException e) {
-                logger.warn("Unknown group id: {}", groupId);
-            } catch (IOException e) {
-                throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage(), e);
-            }
+        final var groupIds = CommandUtil.getGroupIds(groupIdStrings);
+        try {
+            m.setGroupsBlocked(groupIds, false);
+        } catch (NotMasterDeviceException e) {
+            throw new UserErrorException("This command doesn't work on linked devices.");
+        } catch (GroupNotFoundException e) {
+            logger.warn("Unknown group id: {}", e.getMessage());
+        } catch (IOException e) {
+            throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage(), e);
         }
     }
 }