]> nmode's Git Repositories - signal-cli/commitdiff
Prevent creation of RecipientAddress with UNKNOWN_UUID
authorAsamK <asamk@gmx.de>
Sun, 5 Sep 2021 14:06:13 +0000 (16:06 +0200)
committerAsamK <asamk@gmx.de>
Sun, 5 Sep 2021 14:06:13 +0000 (16:06 +0200)
lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientAddress.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java

index 29e964b0d411d871eb4b2172753691d6e9c0f4b9..88877d8380ac560cb1799da72ec2960e8cc78012 100644 (file)
@@ -18,6 +18,7 @@ public class RecipientAddress {
      * @param e164 The phone number of the user, if available.
      */
     public RecipientAddress(Optional<UUID> uuid, Optional<String> e164) {
      * @param e164 The phone number of the user, if available.
      */
     public RecipientAddress(Optional<UUID> uuid, Optional<String> e164) {
+        uuid = uuid.isPresent() && uuid.get().equals(UuidUtil.UNKNOWN_UUID) ? Optional.empty() : uuid;
         if (!uuid.isPresent() && !e164.isPresent()) {
             throw new AssertionError("Must have either a UUID or E164 number!");
         }
         if (!uuid.isPresent() && !e164.isPresent()) {
             throw new AssertionError("Must have either a UUID or E164 number!");
         }
@@ -31,13 +32,11 @@ public class RecipientAddress {
     }
 
     public RecipientAddress(SignalServiceAddress address) {
     }
 
     public RecipientAddress(SignalServiceAddress address) {
-        this.uuid = Optional.of(address.getUuid());
-        this.e164 = Optional.ofNullable(address.getNumber().orNull());
+        this(Optional.of(address.getUuid()), Optional.ofNullable(address.getNumber().orNull()));
     }
 
     public RecipientAddress(UUID uuid) {
     }
 
     public RecipientAddress(UUID uuid) {
-        this.uuid = Optional.of(uuid);
-        this.e164 = Optional.empty();
+        this(Optional.of(uuid), Optional.empty());
     }
 
     public Optional<String> getNumber() {
     }
 
     public Optional<String> getNumber() {
index 86164d5878cf3aa90425cfe842b2b6c804dcb90d..bace6a6b5952763bd0077e19842a6f9a7bdc820e 100644 (file)
@@ -308,7 +308,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
         final var byNumber = address.getNumber().isEmpty()
                 ? Optional.<Recipient>empty()
                 : findByNumberLocked(address.getNumber().get());
         final var byNumber = address.getNumber().isEmpty()
                 ? Optional.<Recipient>empty()
                 : findByNumberLocked(address.getNumber().get());
-        final var byUuid = address.getUuid().isEmpty() || address.getUuid().get().equals(UuidUtil.UNKNOWN_UUID)
+        final var byUuid = address.getUuid().isEmpty()
                 ? Optional.<Recipient>empty()
                 : findByUuidLocked(address.getUuid().get());
 
                 ? Optional.<Recipient>empty()
                 : findByUuidLocked(address.getUuid().get());