]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/json/JsonGroupInfo.java
Update libsignal-service-java
[signal-cli] / src / main / java / org / asamk / signal / json / JsonGroupInfo.java
index 970cde52d7011434c2a932985447fc1c38874d08..de78186aa426eff16fcc167974c67f98ce9f6c27 100644 (file)
@@ -1,41 +1,59 @@
 package org.asamk.signal.json;
 
-import org.asamk.signal.manager.GroupUtils;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.asamk.signal.manager.groups.GroupUtils;
+import org.asamk.signal.util.Util;
 import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
 import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
-import org.whispersystems.signalservice.api.push.SignalServiceAddress;
-import org.whispersystems.util.Base64;
 
-import java.util.ArrayList;
+import java.util.Base64;
 import java.util.List;
+import java.util.stream.Collectors;
 
 class JsonGroupInfo {
 
-    String groupId;
-    List<String> members;
-    String name;
-    String type;
+    @JsonProperty
+    final String groupId;
+
+    @JsonProperty
+    final String type;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final String name;
+
+    @JsonProperty
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    final List<String> members;
 
     JsonGroupInfo(SignalServiceGroup groupInfo) {
-        this.groupId = Base64.encodeBytes(groupInfo.getGroupId());
+        this.groupId = Base64.getEncoder().encodeToString(groupInfo.getGroupId());
+        this.type = groupInfo.getType().toString();
+        this.name = groupInfo.getName().orNull();
         if (groupInfo.getMembers().isPresent()) {
-            this.members = new ArrayList<>(groupInfo.getMembers().get().size());
-            for (SignalServiceAddress address : groupInfo.getMembers().get()) {
-                this.members.add(address.getLegacyIdentifier());
-            }
-        }
-        if (groupInfo.getName().isPresent()) {
-            this.name = groupInfo.getName().get();
+            this.members = groupInfo.getMembers()
+                    .get()
+                    .stream()
+                    .map(Util::getLegacyIdentifier)
+                    .collect(Collectors.toList());
+        } else {
+            this.members = null;
         }
-        this.type = groupInfo.getType().toString();
     }
 
     JsonGroupInfo(SignalServiceGroupV2 groupInfo) {
-        this.groupId = Base64.encodeBytes(GroupUtils.getGroupId(groupInfo.getMasterKey()));
+        this.groupId = GroupUtils.getGroupIdV2(groupInfo.getMasterKey()).toBase64();
         this.type = groupInfo.hasSignedGroupChange() ? "UPDATE" : "DELIVER";
+        this.members = null;
+        this.name = null;
     }
 
     JsonGroupInfo(byte[] groupId) {
-        this.groupId = Base64.encodeBytes(groupId);
+        this.groupId = Base64.getEncoder().encodeToString(groupId);
+        this.type = "DELIVER";
+        this.members = null;
+        this.name = null;
     }
 }