]>
nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/api/RecipientIdentifier.java
1bd2f38dd66eaf4690fbf81d5ad7fa323e2949bd
1 package org
.asamk
.signal
.manager
.api
;
3 import org
.asamk
.signal
.manager
.groups
.GroupId
;
4 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
5 import org
.slf4j
.Logger
;
6 import org
.slf4j
.LoggerFactory
;
7 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
8 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
10 import java
.util
.UUID
;
12 public sealed interface RecipientIdentifier
{
14 String
getIdentifier();
16 record NoteToSelf() implements RecipientIdentifier
{
18 public static NoteToSelf INSTANCE
= new NoteToSelf();
21 public String
getIdentifier() {
22 return "Note-To-Self";
26 sealed interface Single
extends RecipientIdentifier
{
28 static Single
fromString(String identifier
, String localNumber
) throws InvalidNumberException
{
30 if (UuidUtil
.isUuid(identifier
)) {
31 return new Uuid(UUID
.fromString(identifier
));
34 final var normalizedNumber
= PhoneNumberFormatter
.formatNumber(identifier
, localNumber
);
35 if (!normalizedNumber
.equals(identifier
)) {
36 final Logger logger
= LoggerFactory
.getLogger(RecipientIdentifier
.class);
37 logger
.debug("Normalized number {} to {}.", identifier
, normalizedNumber
);
39 return new Number(normalizedNumber
);
40 } catch (org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException e
) {
41 throw new InvalidNumberException(e
.getMessage(), e
);
45 static Single
fromAddress(RecipientAddress address
) {
46 if (address
.number().isPresent()) {
47 return new Number(address
.number().get());
48 } else if (address
.uuid().isPresent()) {
49 return new Uuid(address
.uuid().get());
51 throw new AssertionError("RecipientAddress without identifier");
54 RecipientAddress
toPartialRecipientAddress();
57 record Uuid(UUID uuid
) implements Single
{
60 public String
getIdentifier() {
61 return uuid
.toString();
65 public RecipientAddress
toPartialRecipientAddress() {
66 return new RecipientAddress(uuid
);
70 record Number(String number
) implements Single
{
73 public String
getIdentifier() {
78 public RecipientAddress
toPartialRecipientAddress() {
79 return new RecipientAddress(null, number
);
83 record Group(GroupId groupId
) implements RecipientIdentifier
{
86 public String
getIdentifier() {
87 return groupId
.toBase64();