X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/85025d2e25a9993162d5c859858e7ecb6149fea6..d49d536c32f5d44eaf50f3ac20dfd8e72e94c985:/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 876b6832..42ab7327 100644 --- a/src/main/java/org/asamk/signal/commands/ReceiveCommand.java +++ b/src/main/java/org/asamk/signal/commands/ReceiveCommand.java @@ -10,7 +10,6 @@ import org.asamk.signal.ReceiveMessageHandler; import org.asamk.signal.manager.Manager; import org.asamk.signal.util.DateUtils; import org.freedesktop.dbus.DBusConnection; -import org.freedesktop.dbus.DBusSigHandler; import org.freedesktop.dbus.exceptions.DBusException; import org.whispersystems.util.Base64; @@ -37,30 +36,38 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand { public int handleCommand(final Namespace ns, final Signal signal, DBusConnection dbusconnection) { if (dbusconnection != null) { try { - dbusconnection.addSigHandler(Signal.MessageReceived.class, new DBusSigHandler() { - @Override - public void handle(Signal.MessageReceived s) { - System.out.print(String.format("Envelope from: %s\nTimestamp: %s\nBody: %s\n", - s.getSender(), DateUtils.formatTimestamp(s.getTimestamp()), s.getMessage())); - if (s.getGroupId().length > 0) { - System.out.println("Group info:"); - System.out.println(" Id: " + Base64.encodeBytes(s.getGroupId())); - } - if (s.getAttachments().size() > 0) { - System.out.println("Attachments: "); - for (String attachment : s.getAttachments()) { - System.out.println("- Stored plaintext in: " + attachment); - } + dbusconnection.addSigHandler(Signal.MessageReceived.class, messageReceived -> { + System.out.print(String.format("Envelope from: %s\nTimestamp: %s\nBody: %s\n", + messageReceived.getSender(), DateUtils.formatTimestamp(messageReceived.getTimestamp()), messageReceived.getMessage())); + if (messageReceived.getGroupId().length > 0) { + System.out.println("Group info:"); + System.out.println(" Id: " + Base64.encodeBytes(messageReceived.getGroupId())); + } + if (messageReceived.getAttachments().size() > 0) { + System.out.println("Attachments: "); + for (String attachment : messageReceived.getAttachments()) { + System.out.println("- Stored plaintext in: " + attachment); } - System.out.println(); } + System.out.println(); }); - dbusconnection.addSigHandler(Signal.ReceiptReceived.class, new DBusSigHandler() { - @Override - public void handle(Signal.ReceiptReceived s) { - System.out.print(String.format("Receipt from: %s\nTimestamp: %s\n", - s.getSender(), DateUtils.formatTimestamp(s.getTimestamp()))); + dbusconnection.addSigHandler(Signal.ReceiptReceived.class, + receiptReceived -> System.out.print(String.format("Receipt from: %s\nTimestamp: %s\n", + receiptReceived.getSender(), DateUtils.formatTimestamp(receiptReceived.getTimestamp())))); + dbusconnection.addSigHandler(Signal.SyncMessageReceived.class, syncReceived -> { + System.out.print(String.format("Sync Envelope from: %s to: %s\nTimestamp: %s\nBody: %s\n", + syncReceived.getSource(), syncReceived.getDestination(), DateUtils.formatTimestamp(syncReceived.getTimestamp()), syncReceived.getMessage())); + if (syncReceived.getGroupId().length > 0) { + System.out.println("Group info:"); + System.out.println(" Id: " + Base64.encodeBytes(syncReceived.getGroupId())); + } + if (syncReceived.getAttachments().size() > 0) { + System.out.println("Attachments: "); + for (String attachment : syncReceived.getAttachments()) { + System.out.println("- Stored plaintext in: " + attachment); + } } + System.out.println(); }); } catch (UnsatisfiedLinkError e) { System.err.println("Missing native library dependency for dbus service: " + e.getMessage());