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 LocalCommand
{
25 public SendTypingCommand(final OutputWriter outputWriter
) {
28 public static void attachToSubparser(final Subparser subparser
) {
30 "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.");
31 subparser
.addArgument("-g", "--group").help("Specify the recipient group ID.");
32 subparser
.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
33 subparser
.addArgument("-s", "--stop").help("Send a typing STOP message.").action(Arguments
.storeTrue());
37 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
38 final var recipients
= ns
.<String
>getList("recipient");
39 final var groupIdString
= ns
.getString("group");
41 final var noRecipients
= recipients
== null || recipients
.isEmpty();
42 if (noRecipients
&& groupIdString
== null) {
43 throw new UserErrorException("No recipients given");
45 if (!noRecipients
&& groupIdString
!= null) {
46 throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
49 final var action
= ns
.getBoolean("stop") ? TypingAction
.STOP
: TypingAction
.START
;
51 GroupId groupId
= null;
52 if (groupIdString
!= null) {
54 groupId
= Util
.decodeGroupId(groupIdString
);
55 } catch (GroupIdFormatException e
) {
56 throw new UserErrorException("Invalid group id: " + e
.getMessage());
61 if (groupId
!= null) {
62 m
.sendGroupTypingMessage(action
, groupId
);
64 m
.sendTypingMessage(action
, new HashSet
<>(recipients
));
66 } catch (IOException
| UntrustedIdentityException e
) {
67 throw new UserErrorException("Failed to send message: " + e
.getMessage());
68 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
69 throw new UserErrorException("Failed to send to group: " + e
.getMessage());
70 } catch (InvalidNumberException e
) {
71 throw new UserErrorException("Invalid number: " + e
.getMessage());