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 String
getIdentifier() {
43 if (uuid
.isPresent()) {
44 return uuid
.get().toString();
45 } else if (number
.isPresent()) {
47 } else if (username
.isPresent()) {
48 return username
.get();
50 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
54 public String
getLegacyIdentifier() {
55 if (number
.isPresent()) {
57 } else if (uuid
.isPresent()) {
58 return uuid
.get().toString();
59 } else if (username
.isPresent()) {
60 return username
.get();
62 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
66 public boolean matches(RecipientAddress other
) {
67 return (uuid
.isPresent() && other
.uuid
.isPresent() && uuid
.get().equals(other
.uuid
.get()))
68 || (number
.isPresent() && other
.number
.isPresent() && number
.get().equals(other
.number
.get()))
69 || (username
.isPresent() && other
.username
.isPresent() && username
.get().equals(other
.username
.get()));