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
.whispersystems
.signalservice
.api
.crypto
.UntrustedIdentityException
;
11 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
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").help("Specify the receipt type.").choices("read", "viewed").setDefault("read");
34 public void handleCommand(
35 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
36 ) throws CommandException
{
37 final var recipient
= ns
.getString("recipient");
39 final var targetTimestamps
= ns
.<Long
>getList("target-timestamp");
40 final var type
= ns
.getString("type");
43 if ("read".equals(type
)) {
44 m
.sendReadReceipt(recipient
, targetTimestamps
);
45 } else if ("viewed".equals(type
)) {
46 m
.sendViewedReceipt(recipient
, targetTimestamps
);
48 throw new UserErrorException("Unknown receipt type: " + type
);
50 } catch (IOException
| UntrustedIdentityException e
) {
51 throw new UserErrorException("Failed to send message: " + e
.getMessage());
52 } catch (InvalidNumberException e
) {
53 throw new UserErrorException("Invalid number: " + e
.getMessage());