]>
nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/api/RecipientIdentifier.java
70a60d47d0d7f6f55ec0f741b11e68d297960361
1 package org
.asamk
.signal
.manager
.api
;
3 import org
.asamk
.signal
.manager
.groups
.GroupId
;
4 import org
.slf4j
.Logger
;
5 import org
.slf4j
.LoggerFactory
;
6 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
7 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
11 public sealed interface RecipientIdentifier
{
13 String
getIdentifier();
15 record NoteToSelf() implements RecipientIdentifier
{
17 public static final NoteToSelf INSTANCE
= new NoteToSelf();
20 public String
getIdentifier() {
21 return "Note-To-Self";
25 sealed interface Single
extends RecipientIdentifier
{
27 static Single
fromString(String identifier
, String localNumber
) throws InvalidNumberException
{
29 if (UuidUtil
.isUuid(identifier
)) {
30 return new Uuid(UUID
.fromString(identifier
));
33 final var normalizedNumber
= PhoneNumberFormatter
.formatNumber(identifier
, localNumber
);
34 if (!normalizedNumber
.equals(identifier
)) {
35 final Logger logger
= LoggerFactory
.getLogger(RecipientIdentifier
.class);
36 logger
.debug("Normalized number {} to {}.", identifier
, normalizedNumber
);
38 return new Number(normalizedNumber
);
39 } catch (org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException e
) {
40 throw new InvalidNumberException(e
.getMessage(), e
);
44 static Single
fromAddress(RecipientAddress address
) {
45 if (address
.number().isPresent()) {
46 return new Number(address
.number().get());
47 } else if (address
.uuid().isPresent()) {
48 return new Uuid(address
.uuid().get());
50 throw new AssertionError("RecipientAddress without identifier");
53 RecipientAddress
toPartialRecipientAddress();
56 record Uuid(UUID uuid
) implements Single
{
59 public String
getIdentifier() {
60 return uuid
.toString();
64 public RecipientAddress
toPartialRecipientAddress() {
65 return new RecipientAddress(uuid
);
69 record Number(String number
) implements Single
{
72 public String
getIdentifier() {
77 public RecipientAddress
toPartialRecipientAddress() {
78 return new RecipientAddress(null, number
);
82 record Group(GroupId groupId
) implements RecipientIdentifier
{
85 public String
getIdentifier() {
86 return groupId
.toBase64();