]> nmode's Git Repositories - signal-cli/commitdiff
Add a new sync dbus message which shows messages you sent. Necessary for having synch...
authornarodnik <policeterror@dyne.org>
Fri, 3 Apr 2020 11:16:57 +0000 (13:16 +0200)
committerGitHub <noreply@github.com>
Fri, 3 Apr 2020 11:16:57 +0000 (13:16 +0200)
src/main/java/org/asamk/Signal.java
src/main/java/org/asamk/signal/JsonDbusReceiveMessageHandler.java
src/main/java/org/asamk/signal/commands/ReceiveCommand.java

index 528116b11f108d159ddd289e6c200169b9294990..f8b353c7bcac24d4f774c2a769e19d260909132b 100644 (file)
@@ -96,4 +96,47 @@ public interface Signal extends DBusInterface {
             return sender;
         }
     }
+
+    class SyncMessageReceived extends DBusSignal {
+        private long timestamp;
+        private String source;
+        private String destination;
+        private byte[] groupId;
+        private String message;
+        private List<String> attachments;
+
+        public SyncMessageReceived(String objectpath, long timestamp, String source, String destination, byte[] groupId, String message, List<String> attachments) throws DBusException {
+            super(objectpath, timestamp, source, destination, groupId, message, attachments);
+            this.timestamp = timestamp;
+            this.source = source;
+            this.destination = destination;
+            this.groupId = groupId;
+            this.message = message;
+            this.attachments = attachments;
+        }
+
+        public long getTimestamp() {
+            return timestamp;
+        }
+
+        public String getSource() {
+            return source;
+        }
+
+        public String getDestination() {
+            return destination;
+        }
+
+        public byte[] getGroupId() {
+            return groupId;
+        }
+
+        public String getMessage() {
+            return message;
+        }
+
+        public List<String> getAttachments() {
+            return attachments;
+        }
+    }
 }
index 14aa1fbd7126a7242608f32f5b3ab02d1bdb39c6..3ba65f7dcbf62f4e1865847abdb8365d12ca49ea 100644 (file)
@@ -9,6 +9,9 @@ import org.whispersystems.signalservice.api.messages.SignalServiceContent;
 import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
 import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
 import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
+import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
+import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
+import org.whispersystems.signalservice.api.push.SignalServiceAddress;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -36,35 +39,66 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
             } catch (DBusException e) {
                 e.printStackTrace();
             }
-        } else if (content != null && content.getDataMessage().isPresent()) {
-            SignalServiceDataMessage message = content.getDataMessage().get();
+        } else if (content != null) {
+            if (content.getDataMessage().isPresent()) {
+                SignalServiceDataMessage message = content.getDataMessage().get();
 
-            if (!message.isEndSession() &&
-                    !(message.getGroupContext().isPresent() &&
-                            message.getGroupContext().get().getGroupV1Type() != SignalServiceGroup.Type.DELIVER)) {
-                List<String> attachments = new ArrayList<>();
-                if (message.getAttachments().isPresent()) {
-                    for (SignalServiceAttachment attachment : message.getAttachments().get()) {
-                        if (attachment.isPointer()) {
-                            attachments.add(m.getAttachmentFile(attachment.asPointer().getId()).getAbsolutePath());
+                if (message.getBody().isPresent())
+                    System.out.println(message.getBody().get());
+
+                if (!message.isEndSession() &&
+                        !(message.getGroupContext().isPresent() &&
+                                message.getGroupContext().get().getGroupV1Type() != SignalServiceGroup.Type.DELIVER)) {
+                    try {
+                        conn.sendSignal(new Signal.MessageReceived(
+                                objectPath,
+                                message.getTimestamp(),
+                                envelope.isUnidentifiedSender() || !envelope.hasSource() ? content.getSender().getNumber().get() : envelope.getSourceE164().get(),
+                                message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
+                                        ? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
+                                message.getBody().isPresent() ? message.getBody().get() : "",
+                                JsonDbusReceiveMessageHandler.getAttachments(message, m)));
+                    } catch (DBusException e) {
+                        e.printStackTrace();
+                    }
+                }
+            } else if (content.getSyncMessage().isPresent()) {
+                SignalServiceSyncMessage sync_message = content.getSyncMessage().get();
+                if (sync_message.getSent().isPresent()) {
+                    SentTranscriptMessage transcript = sync_message.getSent().get();
+
+                    if (!envelope.isUnidentifiedSender() && envelope.hasSource() && (transcript.getDestination().isPresent() || transcript.getMessage().getGroupContext().isPresent())) {
+                        SignalServiceDataMessage message = transcript.getMessage();
+
+                        try {
+                            conn.sendSignal(new Signal.SyncMessageReceived(
+                                    objectPath,
+                                    transcript.getTimestamp(),
+                                    envelope.getSourceAddress().getNumber().get(),
+                                    transcript.getDestination().isPresent() ? transcript.getDestination().get().getNumber().get() : "",
+                                    message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
+                                            ? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
+                                    message.getBody().isPresent() ? message.getBody().get() : "",
+                                    JsonDbusReceiveMessageHandler.getAttachments(message, m)));
+                        } catch (DBusException e) {
+                            e.printStackTrace();
                         }
                     }
                 }
+            }
+        }
+    }
 
-                try {
-                    conn.sendSignal(new Signal.MessageReceived(
-                            objectPath,
-                            message.getTimestamp(),
-                            envelope.isUnidentifiedSender() || !envelope.hasSource() ? content.getSender().getNumber().get() : envelope.getSourceE164().get(),
-                            message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
-                                    ? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
-                            message.getBody().isPresent() ? message.getBody().get() : "",
-                            attachments));
-                } catch (DBusException e) {
-                    e.printStackTrace();
+    static private List<String> getAttachments(SignalServiceDataMessage message, Manager m) {
+        List<String> attachments = new ArrayList<>();
+        if (message.getAttachments().isPresent()) {
+            for (SignalServiceAttachment attachment : message.getAttachments().get()) {
+                if (attachment.isPointer()) {
+                    attachments.add(m.getAttachmentFile(attachment.asPointer().getId()).getAbsolutePath());
                 }
             }
         }
+        return attachments;
     }
 
     @Override
index ffc5953007cb5c3bc2f94de7af9cc7dc8fb94a58..42ab732704b92c81c015b0bade1bd40731d48ce4 100644 (file)
@@ -53,7 +53,22 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
                 });
                 dbusconnection.addSigHandler(Signal.ReceiptReceived.class,
                         receiptReceived -> System.out.print(String.format("Receipt from: %s\nTimestamp: %s\n",
-                                receiptReceived.getSender(), DateUtils.formatTimestamp(receiptReceived.getTimestamp()))));
+                            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());
                 return 1;