- final var reader = new BufferedReader(new InputStreamReader(System.in));
- final Supplier<String> lineSupplier = () -> {
- try {
- return reader.readLine();
- } catch (IOException e) {
- throw new AssertionError(e);
- }
- };
-
- final var handler = new SignalJsonRpcDispatcherHandler(m, jsonOutputWriter, lineSupplier);
- handler.handleConnection();
+ final var lineSupplier = getLineSupplier();
+
+ final var handler = new SignalJsonRpcDispatcherHandler(jsonOutputWriter,
+ lineSupplier,
+ receiveMode == ReceiveMode.MANUAL);
+ handler.handleConnection(m);
+ }
+
+ @Override
+ public void handleCommand(
+ final Namespace ns, final MultiAccountManager c, final OutputWriter outputWriter
+ ) throws CommandException {
+ final var receiveMode = ns.<ReceiveMode>get("receive-mode");
+ final var receiveConfig = getReceiveConfig(ns);
+ c.getManagers().forEach(m -> m.setReceiveConfig(receiveConfig));
+ c.addOnManagerAddedHandler(m -> m.setReceiveConfig(receiveConfig));
+
+ final var jsonOutputWriter = (JsonWriter) outputWriter;
+ final var lineSupplier = getLineSupplier();
+
+ final var handler = new SignalJsonRpcDispatcherHandler(jsonOutputWriter,
+ lineSupplier,
+ receiveMode == ReceiveMode.MANUAL);
+ handler.handleConnection(c);
+ }
+
+ private static ReceiveConfig getReceiveConfig(final Namespace ns) {
+ final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
+ final var ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
+ final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
+ return new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts);
+ }
+
+ private static Supplier<String> getLineSupplier() {
+ return IOUtils.getLineSupplier(new InputStreamReader(System.in, IOUtils.getConsoleCharset()));