]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/SendReceiptCommand.java
Check if required quote-author parameter is missing
[signal-cli] / src / main / java / org / asamk / signal / commands / SendReceiptCommand.java
index 74f48112e72d7774db7c0eac4a2c5647643fb0aa..93c8a56401ddc018e5f76107d6863a13bc462e25 100644 (file)
@@ -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.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
-import org.whispersystems.signalservice.api.util.InvalidNumberException;
+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,31 +26,33 @@ 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.").choices("read", "viewed").setDefault("read");
+        subparser.addArgument("--type")
+                .help("Specify the receipt type (default is read receipt).")
+                .choices("read", "viewed");
     }
 
     @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 recipient = ns.getString("recipient");
+        final var recipientString = ns.getString("recipient");
+        final var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getSelfNumber());
 
         final var targetTimestamps = ns.<Long>getList("target-timestamp");
         final var type = ns.getString("type");
 
-        try {
-            if ("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());
-        } catch (InvalidNumberException e) {
-            throw new UserErrorException("Invalid number: " + e.getMessage());
+        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);
     }
 }