]> nmode's Git Repositories - signal-cli/commitdiff
Only store recipient if there were changes
authorAsamK <asamk@gmx.de>
Fri, 19 Nov 2021 16:17:13 +0000 (17:17 +0100)
committerAsamK <asamk@gmx.de>
Fri, 19 Nov 2021 16:17:13 +0000 (17:17 +0100)
graalvm-config-dir/resource-config.json
lib/src/main/java/org/asamk/signal/manager/helper/AttachmentHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/StorageHelper.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/Contact.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/Profile.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/Recipient.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java
src/main/java/org/asamk/signal/commands/ListIdentitiesCommand.java

index 54fbfb2a4c0a745a5a586dc3b326ad506f1c9ce4..f14c84918e0d88ac1f68080abcb67b2c1febc122 100644 (file)
@@ -37,6 +37,9 @@
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BM\\E"
     }, 
+    {
+      "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR\\E"
+    }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BS\\E"
     }, 
@@ -46,6 +49,9 @@
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CH\\E"
     }, 
+    {
+      "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN\\E"
+    }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ\\E"
     }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GR\\E"
     }, 
+    {
+      "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HK\\E"
+    }, 
+    {
+      "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU\\E"
+    }, 
+    {
+      "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ID\\E"
+    }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL\\E"
     }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO\\E"
     }, 
+    {
+      "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MY\\E"
+    }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NL\\E"
     }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UA\\E"
     }, 
+    {
+      "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UG\\E"
+    }, 
     {
       "pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US\\E"
     }, 
index 449a575ef69ece32f1ec6de2a1e4575531923c4c..4944c7b328a297d4b933536d808ef6347becdf88 100644 (file)
@@ -94,8 +94,10 @@ public class AttachmentHelper {
             return;
         }
 
+        final var pointer = attachment.asPointer();
+        logger.debug("Retrieving attachment {} with size {}", pointer.getRemoteId(), pointer.getSize());
         var tmpFile = IOUtils.createTempFile();
-        try (var input = retrieveAttachmentAsStream(attachment.asPointer(), tmpFile)) {
+        try (var input = retrieveAttachmentAsStream(pointer, tmpFile)) {
             consumer.handle(input);
         } finally {
             try {
index 25ffe1fdcbb148385d12936c6e73be99f9891a1c..4548b420556989093f25e85a234a401311e7aa47 100644 (file)
@@ -83,6 +83,7 @@ public class StorageHelper {
                 readContactRecord(record);
             }
         }
+        logger.debug("Done reading data from remote storage");
     }
 
     private void readContactRecord(final SignalStorageRecord record) {
index f2867c9f9a942257438dbea103094459c2df54b7..c03f5c7f2d4338b8b1f2b81c1cd4c3629121646a 100644 (file)
@@ -1,5 +1,7 @@
 package org.asamk.signal.manager.storage.recipients;
 
+import java.util.Objects;
+
 public class Contact {
 
     private final String name;
@@ -68,6 +70,23 @@ public class Contact {
         return archived;
     }
 
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        final Contact contact = (Contact) o;
+        return messageExpirationTime == contact.messageExpirationTime
+                && blocked == contact.blocked
+                && archived == contact.archived
+                && Objects.equals(name, contact.name)
+                && Objects.equals(color, contact.color);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(name, color, messageExpirationTime, blocked, archived);
+    }
+
     public static final class Builder {
 
         private String name;
index c6ba5c922bb63a38ddb28422676c428a64ab9a8d..44ee5f6d05ec0210cc282fd15f457ffeaffe5e8e 100644 (file)
@@ -3,6 +3,7 @@ package org.asamk.signal.manager.storage.recipients;
 import org.whispersystems.signalservice.internal.util.Util;
 
 import java.util.Collections;
+import java.util.Objects;
 import java.util.Set;
 
 public class Profile {
@@ -156,6 +157,33 @@ public class Profile {
         }
     }
 
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        final Profile profile = (Profile) o;
+        return lastUpdateTimestamp == profile.lastUpdateTimestamp
+                && Objects.equals(givenName, profile.givenName)
+                && Objects.equals(familyName, profile.familyName)
+                && Objects.equals(about, profile.about)
+                && Objects.equals(aboutEmoji, profile.aboutEmoji)
+                && Objects.equals(avatarUrlPath, profile.avatarUrlPath)
+                && unidentifiedAccessMode == profile.unidentifiedAccessMode
+                && Objects.equals(capabilities, profile.capabilities);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(lastUpdateTimestamp,
+                givenName,
+                familyName,
+                about,
+                aboutEmoji,
+                avatarUrlPath,
+                unidentifiedAccessMode,
+                capabilities);
+    }
+
     public static final class Builder {
 
         private String givenName;
index 2d2950dc0539f52e4ddd103ddb1e21e8ba116d87..df7d10aa87bd19062c9c979e2c1589d00fc13606 100644 (file)
@@ -3,6 +3,8 @@ package org.asamk.signal.manager.storage.recipients;
 import org.signal.zkgroup.profiles.ProfileKey;
 import org.signal.zkgroup.profiles.ProfileKeyCredential;
 
+import java.util.Objects;
+
 public class Recipient {
 
     private final RecipientId recipientId;
@@ -81,6 +83,24 @@ public class Recipient {
         return profile;
     }
 
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        final Recipient recipient = (Recipient) o;
+        return Objects.equals(recipientId, recipient.recipientId)
+                && Objects.equals(address, recipient.address)
+                && Objects.equals(contact, recipient.contact)
+                && Objects.equals(profileKey, recipient.profileKey)
+                && Objects.equals(profileKeyCredential, recipient.profileKeyCredential)
+                && Objects.equals(profile, recipient.profile);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(recipientId, address, contact, profileKey, profileKeyCredential, profile);
+    }
+
     public static final class Builder {
 
         private RecipientId recipientId;
index 2f07bd2e6197886d1d70f3e3196a98e2bb3e692a..82db8946cb5362e4d2496c7550f37fc38ed8b199 100644 (file)
@@ -130,10 +130,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
 
     public Recipient getRecipient(RecipientId recipientId) {
         synchronized (recipients) {
-            while (recipientsMerged.containsKey(recipientId)) {
-                recipientId = recipientsMerged.get(recipientId);
-            }
-            return recipients.get(recipientId);
+            return getRecipientLocked(recipientId);
         }
     }
 
@@ -378,11 +375,21 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
         storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withAddress(address).build());
     }
 
+    private Recipient getRecipientLocked(RecipientId recipientId) {
+        while (recipientsMerged.containsKey(recipientId)) {
+            recipientId = recipientsMerged.get(recipientId);
+        }
+        return recipients.get(recipientId);
+    }
+
     private void storeRecipientLocked(
             final RecipientId recipientId, final Recipient recipient
     ) {
-        recipients.put(recipientId, recipient);
-        saveLocked();
+        final var existingRecipient = getRecipientLocked(recipientId);
+        if (existingRecipient == null || !existingRecipient.equals(recipient)) {
+            recipients.put(recipientId, recipient);
+            saveLocked();
+        }
     }
 
     private void mergeRecipientsLocked(RecipientId recipientId, RecipientId toBeMergedRecipientId) {
index 04cc00a010e50b412fd9fca8f59ddd9d77629461..c3cfbce8085892d0e2c6f0e83b512ecbd9ed3731 100644 (file)
@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
 
 import java.util.Base64;
 import java.util.List;
+import java.util.UUID;
 import java.util.stream.Collectors;
 
 public class ListIdentitiesCommand implements JsonRpcLocalCommand {
@@ -67,7 +68,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
                 var safetyNumber = Util.formatSafetyNumber(id.safetyNumber());
                 var scannableSafetyNumber = id.scannableSafetyNumber();
                 return new JsonIdentity(address.getNumber().orElse(null),
-                        address.getUuid().toString(),
+                        address.getUuid().map(UUID::toString).orElse(null),
                         Hex.toString(id.getFingerprint()),
                         safetyNumber,
                         scannableSafetyNumber == null