1 package org
.asamk
.signal
.manager
.storage
.recipients
;
3 import org
.whispersystems
.signalservice
.api
.push
.ACI
;
4 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
6 import java
.util
.Optional
;
9 public record RecipientAddress(Optional
<UUID
> uuid
, Optional
<String
> number
) {
11 public static final UUID UNKNOWN_UUID
= ACI
.UNKNOWN
.uuid();
14 * Construct a RecipientAddress.
16 * @param uuid The UUID of the user, if available.
17 * @param number The phone number of the user, if available.
19 public RecipientAddress
{
20 uuid
= uuid
.isPresent() && uuid
.get().equals(UNKNOWN_UUID
) ? Optional
.empty() : uuid
;
21 if (uuid
.isEmpty() && number
.isEmpty()) {
22 throw new AssertionError("Must have either a UUID or E164 number!");
26 public RecipientAddress(UUID uuid
, String e164
) {
27 this(Optional
.ofNullable(uuid
), Optional
.ofNullable(e164
));
30 public RecipientAddress(SignalServiceAddress address
) {
31 this(Optional
.of(address
.getServiceId().uuid()), Optional
.ofNullable(address
.getNumber().orNull()));
34 public RecipientAddress(UUID uuid
) {
35 this(Optional
.of(uuid
), Optional
.empty());
38 public String
getIdentifier() {
39 if (uuid
.isPresent()) {
40 return uuid
.get().toString();
41 } else if (number
.isPresent()) {
44 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
48 public String
getLegacyIdentifier() {
49 if (number
.isPresent()) {
51 } else if (uuid
.isPresent()) {
52 return uuid
.get().toString();
54 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
58 public boolean matches(RecipientAddress other
) {
59 return (uuid
.isPresent() && other
.uuid
.isPresent() && uuid
.get().equals(other
.uuid
.get())) || (
60 number
.isPresent() && other
.number
.isPresent() && number
.get().equals(other
.number
.get())
64 public SignalServiceAddress
toSignalServiceAddress() {
65 return new SignalServiceAddress(ACI
.from(uuid
.orElse(UNKNOWN_UUID
)),
66 org
.whispersystems
.libsignal
.util
.guava
.Optional
.fromNullable(number
.orElse(null)));