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
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
8 import org
.asamk
.signal
.manager
.Manager
;
9 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
10 import org
.asamk
.signal
.output
.OutputWriter
;
11 import org
.asamk
.signal
.util
.CommandUtil
;
13 import static org
.asamk
.signal
.util
.SendMessageResultUtils
.outputResult
;
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")
30 .help("Specify the timestamp of the messages for which a receipt should be sent.");
31 subparser
.addArgument("--type")
32 .help("Specify the receipt type (default is read receipt).")
33 .choices("read", "viewed");
37 public void handleCommand(
38 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
39 ) throws CommandException
{
40 final var recipientString
= ns
.getString("recipient");
41 final var recipient
= CommandUtil
.getSingleRecipientIdentifier(recipientString
, m
.getSelfNumber());
43 final var targetTimestamps
= ns
.<Long
>getList("target-timestamp");
44 final var type
= ns
.getString("type");
46 final SendMessageResults results
;
47 if (type
== null || "read".equals(type
)) {
48 results
= m
.sendReadReceipt(recipient
, targetTimestamps
);
49 } else if ("viewed".equals(type
)) {
50 results
= m
.sendViewedReceipt(recipient
, targetTimestamps
);
52 throw new UserErrorException("Unknown receipt type: " + type
);
54 outputResult(outputWriter
, results
);