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
.NotMasterDeviceException
;
11 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
12 import org
.asamk
.signal
.output
.OutputWriter
;
13 import org
.asamk
.signal
.util
.CommandUtil
;
14 import org
.slf4j
.Logger
;
15 import org
.slf4j
.LoggerFactory
;
17 import java
.io
.IOException
;
19 public class UnblockCommand
implements JsonRpcLocalCommand
{
21 private final static Logger logger
= LoggerFactory
.getLogger(UnblockCommand
.class);
24 public String
getName() {
29 public void attachToSubparser(final Subparser subparser
) {
30 subparser
.help("Unblock the given contacts or groups (messages will be received again)");
31 subparser
.addArgument("recipient").help("Contact number").nargs("*");
32 subparser
.addArgument("-g", "--group-id", "--group").help("Group ID").nargs("*");
36 public void handleCommand(
37 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
38 ) throws CommandException
{
39 for (var contactNumber
: CommandUtil
.getSingleRecipientIdentifiers(ns
.getList("recipient"),
42 m
.setContactBlocked(contactNumber
, false);
43 } catch (NotMasterDeviceException e
) {
44 throw new UserErrorException("This command doesn't work on linked devices.");
45 } catch (IOException e
) {
46 throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e
.getMessage(), e
);
50 final var groupIdStrings
= ns
.<String
>getList("group-id");
51 for (var groupId
: CommandUtil
.getGroupIds(groupIdStrings
)) {
53 m
.setGroupBlocked(groupId
, false);
54 } catch (NotMasterDeviceException e
) {
55 throw new UserErrorException("This command doesn't work on linked devices.");
56 } catch (GroupNotFoundException e
) {
57 logger
.warn("Unknown group id: {}", groupId
);
58 } catch (IOException e
) {
59 throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e
.getMessage(), e
);