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
.UserErrorException
;
8 import org
.asamk
.signal
.manager
.Manager
;
9 import org
.asamk
.signal
.manager
.NotMasterDeviceException
;
10 import org
.asamk
.signal
.manager
.groups
.GroupIdFormatException
;
11 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
12 import org
.asamk
.signal
.util
.Util
;
13 import org
.slf4j
.Logger
;
14 import org
.slf4j
.LoggerFactory
;
15 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
17 public class BlockCommand
implements LocalCommand
{
19 private final static Logger logger
= LoggerFactory
.getLogger(BlockCommand
.class);
22 public void attachToSubparser(final Subparser subparser
) {
23 subparser
.help("Block the given contacts or groups (no messages will be received)");
24 subparser
.addArgument("contact").help("Contact number").nargs("*");
25 subparser
.addArgument("-g", "--group").help("Group ID").nargs("*");
29 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
30 for (var contact_number
: ns
.<String
>getList("contact")) {
32 m
.setContactBlocked(contact_number
, true);
33 } catch (InvalidNumberException e
) {
34 logger
.warn("Invalid number {}: {}", contact_number
, e
.getMessage());
35 } catch (NotMasterDeviceException e
) {
36 throw new UserErrorException("This command doesn't work on linked devices.");
40 if (ns
.<String
>getList("group") != null) {
41 for (var groupIdString
: ns
.<String
>getList("group")) {
43 var groupId
= Util
.decodeGroupId(groupIdString
);
44 m
.setGroupBlocked(groupId
, true);
45 } catch (GroupIdFormatException
| GroupNotFoundException e
) {
46 logger
.warn("Invalid group id {}: {}", groupIdString
, e
.getMessage());