1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
4 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
5 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
7 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.manager
.api
.TypingAction
;
11 import org
.asamk
.signal
.manager
.groups
.GroupId
;
12 import org
.asamk
.signal
.manager
.groups
.GroupIdFormatException
;
13 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
14 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
15 import org
.asamk
.signal
.util
.Util
;
16 import org
.whispersystems
.signalservice
.api
.crypto
.UntrustedIdentityException
;
17 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
19 import java
.io
.IOException
;
20 import java
.util
.HashSet
;
22 public class SendTypingCommand
implements LocalCommand
{
25 public void attachToSubparser(final Subparser subparser
) {
27 "Send typing message to trigger a typing indicator for the recipient. Indicator will be shown for 15seconds unless a typing STOP message is sent first.");
28 subparser
.addArgument("-g", "--group").help("Specify the recipient group ID.");
29 subparser
.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
30 subparser
.addArgument("-s", "--stop").help("Send a typing STOP message.").action(Arguments
.storeTrue());
34 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
35 final var recipients
= ns
.<String
>getList("recipient");
36 final var groupIdString
= ns
.getString("group");
38 final var noRecipients
= recipients
== null || recipients
.isEmpty();
39 if (noRecipients
&& groupIdString
== null) {
40 throw new UserErrorException("No recipients given");
42 if (!noRecipients
&& groupIdString
!= null) {
43 throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
46 final var action
= ns
.getBoolean("stop") ? TypingAction
.STOP
: TypingAction
.START
;
48 GroupId groupId
= null;
49 if (groupIdString
!= null) {
51 groupId
= Util
.decodeGroupId(groupIdString
);
52 } catch (GroupIdFormatException e
) {
53 throw new UserErrorException("Invalid group id: " + e
.getMessage());
58 if (groupId
!= null) {
59 m
.sendGroupTypingMessage(action
, groupId
);
61 m
.sendTypingMessage(action
, new HashSet
<>(recipients
));
63 } catch (IOException
| UntrustedIdentityException e
) {
64 throw new UserErrorException("Failed to send message: " + e
.getMessage());
65 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
66 throw new UserErrorException("Failed to send to group: " + e
.getMessage());
67 } catch (InvalidNumberException e
) {
68 throw new UserErrorException("Invalid number: " + e
.getMessage());