- var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
-
- // TODO delete later when "json" variable is removed
- if (ns.getBoolean("json")) {
- logger.warn("\"--json\" option has been deprecated, please use the global \"--output=json\" instead.");
- }
-
- try {
- if (inJson) {
- final var jsonWriter = new JsonWriter(System.out);
-
- dbusconnection.addSigHandler(Signal.MessageReceived.class, messageReceived -> {
- var envelope = new JsonMessageEnvelope(messageReceived);
- final var object = Map.of("envelope", envelope);
- jsonWriter.write(object);
- });
-
- dbusconnection.addSigHandler(Signal.ReceiptReceived.class, receiptReceived -> {
- var envelope = new JsonMessageEnvelope(receiptReceived);
- final var object = Map.of("envelope", envelope);
- jsonWriter.write(object);
- });
-
- dbusconnection.addSigHandler(Signal.SyncMessageReceived.class, syncReceived -> {
- var envelope = new JsonMessageEnvelope(syncReceived);
- final var object = Map.of("envelope", envelope);
- jsonWriter.write(object);
- });
- } else {
- final var writer = new PlainTextWriterImpl(System.out);
-
- dbusconnection.addSigHandler(Signal.MessageReceived.class, messageReceived -> {
- writer.println("Envelope from: {}", messageReceived.getSender());
- writer.println("Timestamp: {}", DateUtils.formatTimestamp(messageReceived.getTimestamp()));
- writer.println("Body: {}", messageReceived.getMessage());
- if (messageReceived.getGroupId().length > 0) {
- writer.println("Group info:");
- writer.indentedWriter()
- .println("Id: {}", Base64.getEncoder().encodeToString(messageReceived.getGroupId()));
- }
- if (messageReceived.getAttachments().size() > 0) {
- writer.println("Attachments:");
- for (var attachment : messageReceived.getAttachments()) {
- writer.println("- Stored plaintext in: {}", attachment);
- }
- }
- writer.println();
- });
-
- dbusconnection.addSigHandler(Signal.ReceiptReceived.class, receiptReceived -> {
- writer.println("Receipt from: {}", receiptReceived.getSender());
- writer.println("Timestamp: {}", DateUtils.formatTimestamp(receiptReceived.getTimestamp()));
- });
-
- dbusconnection.addSigHandler(Signal.SyncMessageReceived.class, syncReceived -> {
- writer.println("Sync Envelope from: {} to: {}",
- syncReceived.getSource(),
- syncReceived.getDestination());
- writer.println("Timestamp: {}", DateUtils.formatTimestamp(syncReceived.getTimestamp()));
- writer.println("Body: {}", syncReceived.getMessage());
- if (syncReceived.getGroupId().length > 0) {
- writer.println("Group info:");
- writer.indentedWriter()
- .println("Id: {}", Base64.getEncoder().encodeToString(syncReceived.getGroupId()));
- }
- if (syncReceived.getAttachments().size() > 0) {
- writer.println("Attachments:");
- for (var attachment : syncReceived.getAttachments()) {
- writer.println("- Stored plaintext in: {}", attachment);
- }
- }
- writer.println();
- });
- }
- } catch (DBusException e) {
- logger.error("Dbus client failed", e);
- throw new UnexpectedErrorException("Dbus client failed");
- }
- while (true) {
- try {
- Thread.sleep(10000);
- } catch (InterruptedException ignored) {
- return;
- }
- }
- }
-
- @Override
- public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
- var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
-
- // TODO delete later when "json" variable is removed
- if (ns.getBoolean("json")) {
- logger.warn("\"--json\" option has been deprecated, please use the global \"--output=json\" instead.");
- }
-
- double timeout = ns.getDouble("timeout");
- var returnOnTimeout = true;
- if (timeout < 0) {
- returnOnTimeout = false;
- timeout = 3600;
- }
- boolean ignoreAttachments = ns.getBoolean("ignore_attachments");