]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/SendReceiptCommand.java
Implement dbus support for listIdentities
[signal-cli] / src / main / java / org / asamk / signal / commands / SendReceiptCommand.java
index bc2ef37943be68ceeac8dfacc3bb200742025ab1..adae7c4d97f036ac22ee1c57ca2b969390b8906a 100644 (file)
@@ -7,14 +7,10 @@ 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.commands.exceptions.UserErrorException;
 import org.asamk.signal.manager.Manager;
 import org.asamk.signal.manager.api.SendMessageResults;
-import org.asamk.signal.output.JsonWriter;
 import org.asamk.signal.output.OutputWriter;
 import org.asamk.signal.output.OutputWriter;
-import org.asamk.signal.output.PlainTextWriter;
 import org.asamk.signal.util.CommandUtil;
 import org.asamk.signal.util.CommandUtil;
-import org.asamk.signal.util.ErrorUtils;
 
 
-import java.io.IOException;
-import java.util.Map;
+import static org.asamk.signal.util.SendMessageResultUtils.outputResult;
 
 public class SendReceiptCommand implements JsonRpcLocalCommand {
 
 
 public class SendReceiptCommand implements JsonRpcLocalCommand {
 
@@ -30,6 +26,7 @@ public class SendReceiptCommand implements JsonRpcLocalCommand {
         subparser.addArgument("-t", "--target-timestamp")
                 .type(long.class)
                 .nargs("+")
         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).")
                 .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).")
@@ -46,29 +43,14 @@ public class SendReceiptCommand implements JsonRpcLocalCommand {
         final var targetTimestamps = ns.<Long>getList("target-timestamp");
         final var type = ns.getString("type");
 
         final var targetTimestamps = ns.<Long>getList("target-timestamp");
         final var type = ns.getString("type");
 
-        try {
-            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.timestamp());
-            ErrorUtils.handleSendMessageResults(results.results());
-        } catch (IOException e) {
-            throw new UserErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
-                    .getSimpleName() + ")");
-        }
-    }
-
-    private void outputResult(final OutputWriter outputWriter, final long timestamp) {
-        if (outputWriter instanceof PlainTextWriter writer) {
-            writer.println("{}", timestamp);
+        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 {
         } else {
-            final var writer = (JsonWriter) outputWriter;
-            writer.write(Map.of("timestamp", timestamp));
+            throw new UserErrorException("Unknown receipt type: " + type);
         }
         }
+        outputResult(outputWriter, results);
     }
 }
     }
 }