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
.OutputWriter
;
8 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
10 import org
.asamk
.signal
.manager
.Manager
;
11 import org
.asamk
.signal
.manager
.api
.TypingAction
;
12 import org
.asamk
.signal
.manager
.groups
.GroupId
;
13 import org
.asamk
.signal
.manager
.groups
.GroupIdFormatException
;
14 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
15 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
16 import org
.asamk
.signal
.util
.Util
;
17 import org
.whispersystems
.signalservice
.api
.crypto
.UntrustedIdentityException
;
18 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
20 import java
.io
.IOException
;
21 import java
.util
.HashSet
;
23 public class SendTypingCommand
implements JsonRpcLocalCommand
{
26 public String
getName() {
31 public void attachToSubparser(final Subparser subparser
) {
33 "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.");
34 subparser
.addArgument("-g", "--group-id", "--group").help("Specify the recipient group ID.");
35 subparser
.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
36 subparser
.addArgument("-s", "--stop").help("Send a typing STOP message.").action(Arguments
.storeTrue());
40 public void handleCommand(
41 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
42 ) throws CommandException
{
43 final var recipients
= ns
.<String
>getList("recipient");
44 final var groupIdString
= ns
.getString("group-id");
46 final var noRecipients
= recipients
== null || recipients
.isEmpty();
47 if (noRecipients
&& groupIdString
== null) {
48 throw new UserErrorException("No recipients given");
50 if (!noRecipients
&& groupIdString
!= null) {
51 throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
54 final var action
= ns
.getBoolean("stop") ? TypingAction
.STOP
: TypingAction
.START
;
56 GroupId groupId
= null;
57 if (groupIdString
!= null) {
59 groupId
= Util
.decodeGroupId(groupIdString
);
60 } catch (GroupIdFormatException e
) {
61 throw new UserErrorException("Invalid group id: " + e
.getMessage());
66 if (groupId
!= null) {
67 m
.sendGroupTypingMessage(action
, groupId
);
69 m
.sendTypingMessage(action
, new HashSet
<>(recipients
));
71 } catch (IOException
| UntrustedIdentityException e
) {
72 throw new UserErrorException("Failed to send message: " + e
.getMessage());
73 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
74 throw new UserErrorException("Failed to send to group: " + e
.getMessage());
75 } catch (InvalidNumberException e
) {
76 throw new UserErrorException("Invalid number: " + e
.getMessage());