]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/json/JsonDataMessage.java
Strip url scheme from captcha string
[signal-cli] / src / main / java / org / asamk / signal / json / JsonDataMessage.java
index fd3f1efc1939400a94d42075e76dc18dc212d247..6dbda9783e5b081eac7533e94b6c2b8cc7b5beb2 100644 (file)
@@ -1,48 +1,85 @@
 package org.asamk.signal.json;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
 import org.asamk.Signal;
 import org.asamk.signal.manager.Manager;
 import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
-import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
-import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
 
 import java.util.List;
 import java.util.stream.Collectors;
 
 class JsonDataMessage {
 
-    long timestamp;
-    String message;
-    int expiresInSeconds;
+    @JsonProperty
+    final long timestamp;
+
+    @JsonProperty
+    final String message;
+
+    @JsonProperty
+    final Integer expiresInSeconds;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final Boolean viewOnce;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final JsonReaction reaction;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final JsonQuote quote;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final List<JsonMention> mentions;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final List<JsonAttachment> attachments;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final JsonSticker sticker;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final JsonRemoteDelete remoteDelete;
 
-    JsonReaction reaction;
-    JsonQuote quote;
-    List<JsonMention> mentions;
-    List<JsonAttachment> attachments;
-    JsonSticker sticker;
-    JsonGroupInfo groupInfo;
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final List<JsonSharedContact> contacts;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final JsonGroupInfo groupInfo;
 
     JsonDataMessage(SignalServiceDataMessage dataMessage, Manager m) {
         this.timestamp = dataMessage.getTimestamp();
         if (dataMessage.getGroupContext().isPresent()) {
-            if (dataMessage.getGroupContext().get().getGroupV1().isPresent()) {
-                SignalServiceGroup groupInfo = dataMessage.getGroupContext().get().getGroupV1().get();
+            final var groupContext = dataMessage.getGroupContext().get();
+            if (groupContext.getGroupV1().isPresent()) {
+                var groupInfo = groupContext.getGroupV1().get();
                 this.groupInfo = new JsonGroupInfo(groupInfo);
-            } else if (dataMessage.getGroupContext().get().getGroupV2().isPresent()) {
-                SignalServiceGroupV2 groupInfo = dataMessage.getGroupContext().get().getGroupV2().get();
+            } else if (groupContext.getGroupV2().isPresent()) {
+                var groupInfo = groupContext.getGroupV2().get();
                 this.groupInfo = new JsonGroupInfo(groupInfo);
+            } else {
+                this.groupInfo = null;
             }
+        } else {
+            this.groupInfo = null;
         }
-        if (dataMessage.getBody().isPresent()) {
-            this.message = dataMessage.getBody().get();
-        }
+        this.message = dataMessage.getBody().orNull();
         this.expiresInSeconds = dataMessage.getExpiresInSeconds();
-        if (dataMessage.getReaction().isPresent()) {
-            this.reaction = new JsonReaction(dataMessage.getReaction().get(), m);
-        }
-        if (dataMessage.getQuote().isPresent()) {
-            this.quote = new JsonQuote(dataMessage.getQuote().get(), m);
-        }
+        this.viewOnce = dataMessage.isViewOnce();
+        this.reaction = dataMessage.getReaction().isPresent()
+                ? new JsonReaction(dataMessage.getReaction().get(), m)
+                : null;
+        this.quote = dataMessage.getQuote().isPresent() ? new JsonQuote(dataMessage.getQuote().get(), m) : null;
         if (dataMessage.getMentions().isPresent()) {
             this.mentions = dataMessage.getMentions()
                     .get()
@@ -52,6 +89,8 @@ class JsonDataMessage {
         } else {
             this.mentions = List.of();
         }
+        remoteDelete = dataMessage.getRemoteDelete().isPresent() ? new JsonRemoteDelete(dataMessage.getRemoteDelete()
+                .get()) : null;
         if (dataMessage.getAttachments().isPresent()) {
             this.attachments = dataMessage.getAttachments()
                     .get()
@@ -61,8 +100,16 @@ class JsonDataMessage {
         } else {
             this.attachments = List.of();
         }
-        if (dataMessage.getSticker().isPresent()) {
-            this.sticker = new JsonSticker(dataMessage.getSticker().get());
+        this.sticker = dataMessage.getSticker().isPresent() ? new JsonSticker(dataMessage.getSticker().get()) : null;
+
+        if (dataMessage.getSharedContacts().isPresent()) {
+            this.contacts = dataMessage.getSharedContacts()
+                    .get()
+                    .stream()
+                    .map(JsonSharedContact::new)
+                    .collect(Collectors.toList());
+        } else {
+            this.contacts = List.of();
         }
     }
 
@@ -70,10 +117,14 @@ class JsonDataMessage {
         timestamp = messageReceived.getTimestamp();
         message = messageReceived.getMessage();
         groupInfo = messageReceived.getGroupId().length > 0 ? new JsonGroupInfo(messageReceived.getGroupId()) : null;
-        reaction = null;    // TODO Replace these 4 with the proper commands
+        expiresInSeconds = null;
+        viewOnce = null;
+        remoteDelete = null;
+        reaction = null;    // TODO Replace these 5 with the proper commands
         quote = null;
         mentions = null;
         sticker = null;
+        contacts = null;
         attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
     }
 
@@ -81,10 +132,14 @@ class JsonDataMessage {
         timestamp = messageReceived.getTimestamp();
         message = messageReceived.getMessage();
         groupInfo = messageReceived.getGroupId().length > 0 ? new JsonGroupInfo(messageReceived.getGroupId()) : null;
-        reaction = null;    // TODO Replace these 4 with the proper commands
+        expiresInSeconds = null;
+        viewOnce = null;
+        remoteDelete = null;
+        reaction = null;    // TODO Replace these 5 with the proper commands
         quote = null;
         mentions = null;
         sticker = null;
+        contacts = null;
         attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
     }
 }