Prevent creation of RecipientAddress with UNKNOWN_UUID

This commit is contained in:
AsamK 2021-09-05 16:06:13 +02:00
parent 2e01a05e71
commit 656ca6b5e4
2 changed files with 4 additions and 5 deletions

View 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) {
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!");
}
@ -31,13 +32,11 @@ public class RecipientAddress {
}
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) {
this.uuid = Optional.of(uuid);
this.e164 = Optional.empty();
this(Optional.of(uuid), Optional.empty());
}
public Optional<String> getNumber() {

View 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 byUuid = address.getUuid().isEmpty() || address.getUuid().get().equals(UuidUtil.UNKNOWN_UUID)
final var byUuid = address.getUuid().isEmpty()
? Optional.<Recipient>empty()
: findByUuidLocked(address.getUuid().get());