]>
nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/api/RecipientAddress.java
1 package org
.asamk
.signal
.manager
.api
;
3 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
5 import java
.util
.Optional
;
8 public record RecipientAddress(
9 Optional
<String
> aci
, Optional
<String
> pni
, Optional
<String
> number
, Optional
<String
> username
12 public static final UUID UNKNOWN_UUID
= UuidUtil
.UNKNOWN_UUID
;
15 * Construct a RecipientAddress.
17 * @param aci The ACI of the user, if available.
18 * @param pni The PNI of the user, if available.
19 * @param number The phone number of the user, if available.
21 public RecipientAddress
{
22 if (aci
.isEmpty() && pni
.isEmpty() && number
.isEmpty() && username
.isEmpty()) {
23 throw new AssertionError("Must have either a ACI, PNI, username or E164 number!");
27 public RecipientAddress(String e164
) {
28 this(null, null, e164
, null);
31 public RecipientAddress(UUID uuid
) {
32 this(uuid
.toString(), null, null, null);
35 public RecipientAddress(String aci
, String pni
, String e164
, String username
) {
36 this(Optional
.ofNullable(aci
),
37 Optional
.ofNullable(pni
),
38 Optional
.ofNullable(e164
),
39 Optional
.ofNullable(username
));
42 public Optional
<UUID
> uuid() {
43 return aci
.map(UUID
::fromString
);
46 public String
getIdentifier() {
47 if (aci
.isPresent()) {
49 } else if (number
.isPresent()) {
51 } else if (pni
.isPresent()) {
53 } else if (username
.isPresent()) {
54 return username
.get();
56 throw new AssertionError("Given the checks in the constructor, this should not be possible.");
60 public String
getLegacyIdentifier() {
61 if (number
.isPresent()) {
64 return getIdentifier();
68 public boolean matches(RecipientAddress other
) {
69 return (aci
.isPresent() && other
.aci
.isPresent() && aci
.get().equals(other
.aci
.get()))
71 pni
.isPresent() && other
.pni
.isPresent() && pni
.get().equals(other
.pni
.get())
73 || (number
.isPresent() && other
.number
.isPresent() && number
.get().equals(other
.number
.get()))
74 || (username
.isPresent() && other
.username
.isPresent() && username
.get().equals(other
.username
.get()));