- for (var contact : CommandUtil.getSingleRecipientIdentifiers(contacts, m.getSelfNumber())) {
- try {
- m.setContactBlocked(contact, true);
- } catch (NotMasterDeviceException e) {
- throw new UserErrorException("This command doesn't work on linked devices.");
- } catch (IOException e) {
- throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage(), e);
- }
+ final var recipients = CommandUtil.getSingleRecipientIdentifiers(contacts, m.getSelfNumber());
+ try {
+ m.setContactsBlocked(recipients, true);
+ } catch (NotPrimaryDeviceException e) {
+ throw new UserErrorException("This command doesn't work on linked devices.");
+ } catch (IOException e) {
+ throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage(), e);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");