1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.UnexpectedErrorException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
11 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
12 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
13 import org
.asamk
.signal
.output
.OutputWriter
;
14 import org
.asamk
.signal
.util
.CommandUtil
;
15 import org
.slf4j
.Logger
;
16 import org
.slf4j
.LoggerFactory
;
18 import java
.io
.IOException
;
20 public class UnblockCommand
implements JsonRpcLocalCommand
{
22 private static final Logger logger
= LoggerFactory
.getLogger(UnblockCommand
.class);
25 public String
getName() {
30 public void attachToSubparser(final Subparser subparser
) {
31 subparser
.help("Unblock the given contacts or groups (messages will be received again)");
32 subparser
.addArgument("recipient").help("Contact number").nargs("*");
33 subparser
.addArgument("-g", "--group-id", "--group").help("Group ID").nargs("*");
37 public void handleCommand(
38 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
39 ) throws CommandException
{
40 final var contacts
= ns
.<String
>getList("recipient");
41 final var recipients
= CommandUtil
.getSingleRecipientIdentifiers(contacts
, m
.getSelfNumber());
43 m
.setContactsBlocked(recipients
, false);
44 } catch (NotPrimaryDeviceException e
) {
45 throw new UserErrorException("This command doesn't work on linked devices.");
46 } catch (IOException e
) {
47 throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e
.getMessage(), e
);
48 } catch (UnregisteredRecipientException e
) {
49 throw new UserErrorException("The user " + e
.getSender().getIdentifier() + " is not registered.");
52 final var groupIdStrings
= ns
.<String
>getList("group-id");
53 final var groupIds
= CommandUtil
.getGroupIds(groupIdStrings
);
55 m
.setGroupsBlocked(groupIds
, false);
56 } catch (NotPrimaryDeviceException e
) {
57 throw new UserErrorException("This command doesn't work on linked devices.");
58 } catch (GroupNotFoundException e
) {
59 logger
.warn("Unknown group id: {}", e
.getMessage());
60 } catch (IOException e
) {
61 throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e
.getMessage(), e
);