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
.GroupIdFormatException
;
8 import org
.asamk
.signal
.GroupNotFoundException
;
9 import org
.asamk
.signal
.NotAGroupMemberException
;
10 import org
.asamk
.signal
.manager
.Manager
;
11 import org
.asamk
.signal
.util
.Util
;
12 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
13 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.EncapsulatedExceptions
;
14 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
16 import java
.io
.IOException
;
18 import static org
.asamk
.signal
.util
.ErrorUtils
.handleAssertionError
;
19 import static org
.asamk
.signal
.util
.ErrorUtils
.handleEncapsulatedExceptions
;
20 import static org
.asamk
.signal
.util
.ErrorUtils
.handleGroupIdFormatException
;
21 import static org
.asamk
.signal
.util
.ErrorUtils
.handleGroupNotFoundException
;
22 import static org
.asamk
.signal
.util
.ErrorUtils
.handleIOException
;
23 import static org
.asamk
.signal
.util
.ErrorUtils
.handleInvalidNumberException
;
24 import static org
.asamk
.signal
.util
.ErrorUtils
.handleNotAGroupMemberException
;
26 public class SendReactionCommand
implements LocalCommand
{
29 public void attachToSubparser(final Subparser subparser
) {
30 subparser
.help("Send reaction to a previously received or sent message.");
31 subparser
.addArgument("-g", "--group")
32 .help("Specify the recipient group ID.");
33 subparser
.addArgument("recipient")
34 .help("Specify the recipients' phone number.")
36 subparser
.addArgument("-e", "--emoji")
38 .help("Specify the emoji, should be a single unicode grapheme cluster.");
39 subparser
.addArgument("-a", "--target-author")
41 .help("Specify the number of the author of the message to which to react.");
42 subparser
.addArgument("-t", "--target-timestamp")
45 .help("Specify the timestamp of the message to which to react.");
46 subparser
.addArgument("-r", "--remove")
47 .help("Remove a reaction.")
48 .action(Arguments
.storeTrue());
52 public int handleCommand(final Namespace ns
, final Manager m
) {
53 if (!m
.isRegistered()) {
54 System
.err
.println("User is not registered.");
58 if ((ns
.getList("recipient") == null || ns
.getList("recipient").size() == 0) && ns
.getString("group") == null) {
59 System
.err
.println("No recipients given");
60 System
.err
.println("Aborting sending.");
64 String emoji
= ns
.getString("emoji");
65 boolean isRemove
= ns
.getBoolean("remove");
66 SignalServiceAddress targetAuthor
= new SignalServiceAddress(null, ns
.getString("target_author"));
67 long targetTimestamp
= ns
.getLong("target_timestamp");
70 if (ns
.getString("group") != null) {
71 byte[] groupId
= Util
.decodeGroupId(ns
.getString("group"));
72 m
.sendGroupMessageReaction(emoji
, isRemove
, targetAuthor
, targetTimestamp
, groupId
);
74 m
.sendMessageReaction(emoji
, isRemove
, targetAuthor
, targetTimestamp
, ns
.getList("recipient"));
77 } catch (IOException e
) {
80 } catch (EncapsulatedExceptions e
) {
81 handleEncapsulatedExceptions(e
);
83 } catch (AssertionError e
) {
84 handleAssertionError(e
);
86 } catch (GroupNotFoundException e
) {
87 handleGroupNotFoundException(e
);
89 } catch (NotAGroupMemberException e
) {
90 handleNotAGroupMemberException(e
);
92 } catch (GroupIdFormatException e
) {
93 handleGroupIdFormatException(e
);
95 } catch (InvalidNumberException e
) {
96 handleInvalidNumberException(e
);