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")
32 .help("Specify the timestamp of the messages for which a receipt should be sent.");
33 subparser
.addArgument("--type")
34 .help("Specify the receipt type (default is read receipt).")
35 .choices("read", "viewed");
39 public void handleCommand(
40 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
41 ) throws CommandException
{
42 final var recipientString
= ns
.getString("recipient");
43 final var recipient
= CommandUtil
.getSingleRecipientIdentifier(recipientString
, m
.getSelfNumber());
45 final var targetTimestamps
= ns
.<Long
>getList("target-timestamp");
46 final var type
= ns
.getString("type");
49 final SendMessageResults results
;
50 if (type
== null || "read".equals(type
)) {
51 results
= m
.sendReadReceipt(recipient
, targetTimestamps
);
52 } else if ("viewed".equals(type
)) {
53 results
= m
.sendViewedReceipt(recipient
, targetTimestamps
);
55 throw new UserErrorException("Unknown receipt type: " + type
);
57 outputResult(outputWriter
, results
);
58 } catch (IOException e
) {
59 throw new UserErrorException("Failed to send message: " + e
.getMessage() + " (" + e
.getClass()
60 .getSimpleName() + ")");