diff --git a/lib/src/main/java/org/asamk/signal/manager/api/InvalidNumberException.java b/lib/src/main/java/org/asamk/signal/manager/api/InvalidNumberException.java index ba71ef2e9..8e6a80647 100644 --- a/lib/src/main/java/org/asamk/signal/manager/api/InvalidNumberException.java +++ b/lib/src/main/java/org/asamk/signal/manager/api/InvalidNumberException.java @@ -2,6 +2,10 @@ public class InvalidNumberException extends Exception { + InvalidNumberException(String message) { + super(message); + } + InvalidNumberException(String message, Throwable e) { super(message, e); } diff --git a/lib/src/main/java/org/asamk/signal/manager/api/RecipientIdentifier.java b/lib/src/main/java/org/asamk/signal/manager/api/RecipientIdentifier.java index 794672a4b..53da2aade 100644 --- a/lib/src/main/java/org/asamk/signal/manager/api/RecipientIdentifier.java +++ b/lib/src/main/java/org/asamk/signal/manager/api/RecipientIdentifier.java @@ -29,6 +29,14 @@ static Single fromString(String identifier, String localNumber) throws InvalidNu return new Uuid(UUID.fromString(identifier)); } + if (identifier.startsWith("PNI:")) { + final var pni = identifier.substring(4); + if (!UuidUtil.isUuid(pni)) { + throw new InvalidNumberException("Invalid PNI"); + } + return new Pni(UUID.fromString(pni)); + } + if (identifier.startsWith("u:")) { return new Username(identifier.substring(2)); } @@ -50,7 +58,7 @@ static Single fromAddress(RecipientAddress address) { } else if (address.aci().isPresent()) { return new Uuid(UUID.fromString(address.aci().get())); } else if (address.pni().isPresent()) { - return new Pni(address.pni().get()); + return new Pni(UUID.fromString(address.pni().get().substring(4))); } else if (address.username().isPresent()) { return new Username(address.username().get()); } @@ -73,16 +81,16 @@ public RecipientAddress toPartialRecipientAddress() { } } - record Pni(String pni) implements Single { + record Pni(UUID pni) implements Single { @Override public String getIdentifier() { - return pni; + return "PNI:" + pni.toString(); } @Override public RecipientAddress toPartialRecipientAddress() { - return new RecipientAddress(null, pni, null, null); + return new RecipientAddress(null, getIdentifier(), null, null); } } diff --git a/lib/src/main/java/org/asamk/signal/manager/helper/RecipientHelper.java b/lib/src/main/java/org/asamk/signal/manager/helper/RecipientHelper.java index 5da66b7e4..125fa0d83 100644 --- a/lib/src/main/java/org/asamk/signal/manager/helper/RecipientHelper.java +++ b/lib/src/main/java/org/asamk/signal/manager/helper/RecipientHelper.java @@ -79,7 +79,7 @@ public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) if (recipient instanceof RecipientIdentifier.Uuid uuidRecipient) { return account.getRecipientResolver().resolveRecipient(ACI.from(uuidRecipient.uuid())); } else if (recipient instanceof RecipientIdentifier.Pni pniRecipient) { - return account.getRecipientResolver().resolveRecipient(PNI.parseOrThrow(pniRecipient.pni())); + return account.getRecipientResolver().resolveRecipient(PNI.from(pniRecipient.pni())); } else if (recipient instanceof RecipientIdentifier.Number numberRecipient) { final var number = numberRecipient.number(); return account.getRecipientStore().resolveRecipientByNumber(number, () -> { diff --git a/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java b/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java index 2f2ba3dbf..dcdead735 100644 --- a/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java +++ b/lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java @@ -888,7 +888,7 @@ public SendMessageResults sendRemoteDeleteMessage( .deleteEntryForRecipientNonGroup(targetSentTimestamp, ACI.from(u.uuid())); } else if (recipient instanceof RecipientIdentifier.Pni pni) { account.getMessageSendLogStore() - .deleteEntryForRecipientNonGroup(targetSentTimestamp, PNI.parseOrThrow(pni.pni())); + .deleteEntryForRecipientNonGroup(targetSentTimestamp, PNI.from(pni.pni())); } else if (recipient instanceof RecipientIdentifier.Single r) { try { final var recipientId = context.getRecipientHelper().resolveRecipient(r); diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientAddress.java b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientAddress.java index b80f81da5..ba2b9f266 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientAddress.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientAddress.java @@ -69,8 +69,8 @@ public RecipientAddress(SignalServiceAddress address) { } public RecipientAddress(org.asamk.signal.manager.api.RecipientAddress address) { - this(address.aci().map(ACI::parseOrNull), - address.pni().map(PNI::parseOrNull), + this(address.aci().map(ACI::parseOrThrow), + address.pni().map(PNI::parseOrThrow), address.number(), address.username()); }