1 package org
.asamk
.signal
.manager
.api
;
3 import org
.whispersystems
.signalservice
.api
.push
.ServiceId
;
4 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
6 import java
.util
.Optional
;
9 public record RecipientAddress(Optional
<UUID
> uuid
, Optional
<String
> number
, Optional
<String
> username
) {
11 public static final UUID UNKNOWN_UUID
= ServiceId
.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() && username
.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
), Optional
.empty());
30 public RecipientAddress(UUID uuid
, String e164
, String username
) {
31 this(Optional
.ofNullable(uuid
), Optional
.ofNullable(e164
), Optional
.ofNullable(username
));
34 public RecipientAddress(SignalServiceAddress address
) {
35 this(Optional
.of(address
.getServiceId().uuid()), address
.getNumber(), Optional
.empty());
38 public RecipientAddress(UUID uuid
) {
39 this(Optional
.of(uuid
), Optional
.empty(), Optional
.empty());
42 public ServiceId
getServiceId() {
43 return ServiceId
.from(uuid
.orElse(UNKNOWN_UUID
));
46 public String
getIdentifier() {
47 if (uuid
.isPresent()) {
48 return uuid
.get().toString();
49 } else if (number
.isPresent()) {
51 } else if (username
.isPresent()) {
52 return username
.get();
54 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
58 public String
getLegacyIdentifier() {
59 if (number
.isPresent()) {
61 } else if (uuid
.isPresent()) {
62 return uuid
.get().toString();
63 } else if (username
.isPresent()) {
64 return username
.get();
66 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
70 public boolean matches(RecipientAddress other
) {
71 return (uuid
.isPresent() && other
.uuid
.isPresent() && uuid
.get().equals(other
.uuid
.get()))
72 || (number
.isPresent() && other
.number
.isPresent() && number
.get().equals(other
.number
.get()))
73 || (username
.isPresent() && other
.username
.isPresent() && username
.get().equals(other
.username
.get()));