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
.OutputWriter
;
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
.UntrustedIdentityException
;
11 import org
.asamk
.signal
.util
.CommandUtil
;
13 import java
.io
.IOException
;
15 public class SendReceiptCommand
implements JsonRpcLocalCommand
{
18 public String
getName() {
23 public void attachToSubparser(final Subparser subparser
) {
24 subparser
.help("Send a read or viewed receipt to a previously received message.");
25 subparser
.addArgument("recipient").help("Specify the sender's phone number.").required(true);
26 subparser
.addArgument("-t", "--target-timestamp")
29 .help("Specify the timestamp of the messages for which a receipt should be sent.");
30 subparser
.addArgument("--type")
31 .help("Specify the receipt type (default is read receipt).")
32 .choices("read", "viewed");
36 public void handleCommand(
37 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
38 ) throws CommandException
{
39 final var recipientString
= ns
.getString("recipient");
40 final var recipient
= CommandUtil
.getSingleRecipientIdentifier(recipientString
, m
.getUsername());
42 final var targetTimestamps
= ns
.<Long
>getList("target-timestamp");
43 final var type
= ns
.getString("type");
46 if (type
== null || "read".equals(type
)) {
47 m
.sendReadReceipt(recipient
, targetTimestamps
);
48 } else if ("viewed".equals(type
)) {
49 m
.sendViewedReceipt(recipient
, targetTimestamps
);
51 throw new UserErrorException("Unknown receipt type: " + type
);
53 } catch (IOException
| UntrustedIdentityException e
) {
54 throw new UserErrorException("Failed to send message: " + e
.getMessage() + " (" + e
.getClass()
55 .getSimpleName() + ")");