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 java
.io
.IOException
;
15 import static org
.asamk
.signal
.util
.SendMessageResultUtils
.outputResult
;
17 public class SendReceiptCommand
implements JsonRpcLocalCommand
{
20 public String
getName() {
25 public void attachToSubparser(final Subparser subparser
) {
26 subparser
.help("Send a read or viewed receipt to a previously received message.");
27 subparser
.addArgument("recipient").help("Specify the sender's phone number.").required(true);
28 subparser
.addArgument("-t", "--target-timestamp")
31 .help("Specify the timestamp of the messages for which a receipt should be sent.");
32 subparser
.addArgument("--type")
33 .help("Specify the receipt type (default is read receipt).")
34 .choices("read", "viewed");
38 public void handleCommand(
39 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
40 ) throws CommandException
{
41 final var recipientString
= ns
.getString("recipient");
42 final var recipient
= CommandUtil
.getSingleRecipientIdentifier(recipientString
, m
.getSelfNumber());
44 final var targetTimestamps
= ns
.<Long
>getList("target-timestamp");
45 final var type
= ns
.getString("type");
48 final SendMessageResults results
;
49 if (type
== null || "read".equals(type
)) {
50 results
= m
.sendReadReceipt(recipient
, targetTimestamps
);
51 } else if ("viewed".equals(type
)) {
52 results
= m
.sendViewedReceipt(recipient
, targetTimestamps
);
54 throw new UserErrorException("Unknown receipt type: " + type
);
56 outputResult(outputWriter
, results
);
57 } catch (IOException e
) {
58 throw new UserErrorException("Failed to send message: " + e
.getMessage() + " (" + e
.getClass()
59 .getSimpleName() + ")");