]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/SendReceiptCommand.java
Align cli param names for recipient
[signal-cli] / src / main / java / org / asamk / signal / commands / SendReceiptCommand.java
index 74f48112e72d7774db7c0eac4a2c5647643fb0aa..70e2f015adc5f4fa8dd798815ada7081c8be5782 100644 (file)
@@ -7,8 +7,8 @@ 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.util.CommandUtil;
 import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
-import org.whispersystems.signalservice.api.util.InvalidNumberException;
 
 import java.io.IOException;
 
@@ -27,20 +27,23 @@ public class SendReceiptCommand implements JsonRpcLocalCommand {
                 .type(long.class)
                 .nargs("+")
                 .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
     ) throws CommandException {
-        final var recipient = ns.getString("recipient");
+        final var recipientString = ns.getString("recipient");
+        final var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getUsername());
 
         final var targetTimestamps = ns.<Long>getList("target-timestamp");
         final var type = ns.getString("type");
 
         try {
-            if ("read".equals(type)) {
+            if (type == null || "read".equals(type)) {
                 m.sendReadReceipt(recipient, targetTimestamps);
             } else if ("viewed".equals(type)) {
                 m.sendViewedReceipt(recipient, targetTimestamps);
@@ -49,8 +52,6 @@ public class SendReceiptCommand implements JsonRpcLocalCommand {
             }
         } catch (IOException | UntrustedIdentityException e) {
             throw new UserErrorException("Failed to send message: " + e.getMessage());
-        } catch (InvalidNumberException e) {
-            throw new UserErrorException("Invalid number: " + e.getMessage());
         }
     }
 }