X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/2044a7d7a58ada7ca1e67a80012e3ffdaf86c88c..9b102c49d06bd6dcd59f032ddd17663f47991118:/src/main/java/org/asamk/signal/commands/ReceiveCommand.java diff --git a/src/main/java/org/asamk/signal/commands/ReceiveCommand.java b/src/main/java/org/asamk/signal/commands/ReceiveCommand.java index 62b3164b..6b2e497e 100644 --- a/src/main/java/org/asamk/signal/commands/ReceiveCommand.java +++ b/src/main/java/org/asamk/signal/commands/ReceiveCommand.java @@ -128,11 +128,18 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand { logger.error("Dbus client failed", e); throw new UnexpectedErrorException("Dbus client failed", e); } + + double timeout = ns.getDouble("timeout"); + long timeoutMilliseconds = timeout < 0 ? 10000 : (long) (timeout * 1000); + while (true) { try { - Thread.sleep(10000); + Thread.sleep(timeoutMilliseconds); } catch (InterruptedException ignored) { - return; + break; + } + if (timeout >= 0) { + break; } } } @@ -142,20 +149,16 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand { final Namespace ns, final Manager m, final OutputWriter outputWriter ) throws CommandException { double timeout = ns.getDouble("timeout"); - var returnOnTimeout = true; - if (timeout < 0) { - returnOnTimeout = false; - timeout = 3600; - } - boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); + boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments")); + m.setIgnoreAttachments(ignoreAttachments); try { final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m, (JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter); - m.receiveMessages((long) (timeout * 1000), - TimeUnit.MILLISECONDS, - returnOnTimeout, - ignoreAttachments, - handler); + if (timeout < 0) { + m.receiveMessages(handler); + } else { + m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, handler); + } } catch (IOException e) { throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e); }