X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/f60a10eb6e40921c32045c1e38843d6b87f3d274..f51f0cbbcf0c7aab9bf725b4f3831544f50c4e14:/src/main/java/org/asamk/signal/JsonDbusReceiveMessageHandler.java diff --git a/src/main/java/org/asamk/signal/JsonDbusReceiveMessageHandler.java b/src/main/java/org/asamk/signal/JsonDbusReceiveMessageHandler.java index c0977c0f..3ba65f7d 100644 --- a/src/main/java/org/asamk/signal/JsonDbusReceiveMessageHandler.java +++ b/src/main/java/org/asamk/signal/JsonDbusReceiveMessageHandler.java @@ -4,7 +4,14 @@ import org.asamk.Signal; import org.asamk.signal.manager.Manager; import org.freedesktop.dbus.DBusConnection; import org.freedesktop.dbus.exceptions.DBusException; -import org.whispersystems.signalservice.api.messages.*; +import org.whispersystems.signalservice.api.messages.SignalServiceAttachment; +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; @@ -27,39 +34,71 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler { conn.sendSignal(new Signal.ReceiptReceived( objectPath, envelope.getTimestamp(), - envelope.getSource() + !envelope.isUnidentifiedSender() && envelope.hasSource() ? envelope.getSourceE164().get() : content.getSender().getNumber().get() )); } 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.getGroupInfo().isPresent() && - message.getGroupInfo().get().getType() != SignalServiceGroup.Type.DELIVER)) { - List 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.getSource(), - message.getGroupInfo().isPresent() ? message.getGroupInfo().get().getGroupId() : new byte[0], - message.getBody().isPresent() ? message.getBody().get() : "", - attachments)); - } catch (DBusException e) { - e.printStackTrace(); + static private List getAttachments(SignalServiceDataMessage message, Manager m) { + List 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