X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/fc8b6d0fcbedd6a4c9ae394a0640e79690e28337..276ecef3009baecb740f23d53ddaa81f487d57a2:/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 bc2ef379..1eec6c99 100644 --- a/src/main/java/org/asamk/signal/commands/SendReceiptCommand.java +++ b/src/main/java/org/asamk/signal/commands/SendReceiptCommand.java @@ -7,14 +7,12 @@ 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.JsonWriter; import org.asamk.signal.output.OutputWriter; -import org.asamk.signal.output.PlainTextWriter; 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 { @@ -30,6 +28,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).") @@ -55,20 +54,10 @@ public class SendReceiptCommand implements JsonRpcLocalCommand { } else { throw new UserErrorException("Unknown receipt type: " + type); } - outputResult(outputWriter, results.timestamp()); - ErrorUtils.handleSendMessageResults(results.results()); + outputResult(outputWriter, 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); - } else { - final var writer = (JsonWriter) outputWriter; - writer.write(Map.of("timestamp", timestamp)); - } - } }