X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/d72b838560b1a4186ac121c7d605773b49fcdf46..fe752e0c7998bc8ca66c46d981624e6fbce7abf9:/src/main/java/org/asamk/signal/commands/SendReceiptCommand.java diff --git a/src/main/java/org/asamk/signal/commands/SendReceiptCommand.java b/src/main/java/org/asamk/signal/commands/SendReceiptCommand.java index 5dd29682..93c8a564 100644 --- a/src/main/java/org/asamk/signal/commands/SendReceiptCommand.java +++ b/src/main/java/org/asamk/signal/commands/SendReceiptCommand.java @@ -3,14 +3,14 @@ package org.asamk.signal.commands; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; -import org.asamk.signal.OutputWriter; import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.manager.Manager; -import org.asamk.signal.manager.UntrustedIdentityException; +import org.asamk.signal.manager.api.SendMessageResults; +import org.asamk.signal.output.OutputWriter; import org.asamk.signal.util.CommandUtil; -import java.io.IOException; +import static org.asamk.signal.util.SendMessageResultUtils.outputResult; public class SendReceiptCommand implements JsonRpcLocalCommand { @@ -26,6 +26,7 @@ public class SendReceiptCommand implements JsonRpcLocalCommand { subparser.addArgument("-t", "--target-timestamp") .type(long.class) .nargs("+") + .required(true) .help("Specify the timestamp of the messages for which a receipt should be sent."); subparser.addArgument("--type") .help("Specify the receipt type (default is read receipt).") @@ -34,7 +35,9 @@ public class SendReceiptCommand implements JsonRpcLocalCommand { @Override public void handleCommand( - final Namespace ns, final Manager m, final OutputWriter outputWriter + final Namespace ns, + final Manager m, + final OutputWriter outputWriter ) throws CommandException { final var recipientString = ns.getString("recipient"); final var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getSelfNumber()); @@ -42,17 +45,14 @@ public class SendReceiptCommand implements JsonRpcLocalCommand { final var targetTimestamps = ns.getList("target-timestamp"); final var type = ns.getString("type"); - try { - if (type == null || "read".equals(type)) { - m.sendReadReceipt(recipient, targetTimestamps); - } else if ("viewed".equals(type)) { - m.sendViewedReceipt(recipient, targetTimestamps); - } else { - throw new UserErrorException("Unknown receipt type: " + type); - } - } catch (IOException | UntrustedIdentityException e) { - throw new UserErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass() - .getSimpleName() + ")"); + final SendMessageResults results; + if (type == null || "read".equals(type)) { + results = m.sendReadReceipt(recipient, targetTimestamps); + } else if ("viewed".equals(type)) { + results = m.sendViewedReceipt(recipient, targetTimestamps); + } else { + throw new UserErrorException("Unknown receipt type: " + type); } + outputResult(outputWriter, results); } }