]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/SendReceiptCommand.java
Exposing Signal CLI as HTTP Server (#1078)
[signal-cli] / src / main / java / org / asamk / signal / commands / SendReceiptCommand.java
index afdbd4f8137a60477b00328afc69bdac80b7bba6..1eec6c9947b8ac49ba4ac920161b11ab74910cb1 100644 (file)
@@ -3,15 +3,17 @@ 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.api.SendMessageResults;
+import org.asamk.signal.output.OutputWriter;
 import org.asamk.signal.util.CommandUtil;
-import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
 
 import java.io.IOException;
 
+import static org.asamk.signal.util.SendMessageResultUtils.outputResult;
+
 public class SendReceiptCommand implements JsonRpcLocalCommand {
 
     @Override
@@ -26,8 +28,11 @@ 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
@@ -35,21 +40,24 @@ public class SendReceiptCommand implements JsonRpcLocalCommand {
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
         final var recipientString = ns.getString("recipient");
-        final var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getUsername());
+        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);
+            final SendMessageResults results;
+            if (type == null || "read".equals(type)) {
+                results = m.sendReadReceipt(recipient, targetTimestamps);
             } else if ("viewed".equals(type)) {
-                m.sendViewedReceipt(recipient, targetTimestamps);
+                results = 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());
+            outputResult(outputWriter, results);
+        } catch (IOException e) {
+            throw new UserErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
+                    .getSimpleName() + ")");
         }
     }
 }