mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Add support for using PNI as recipient
This commit is contained in:
parent
68c9d84d19
commit
2c68b5a9e1
5 changed files with 20 additions and 8 deletions
|
@ -2,6 +2,10 @@ package org.asamk.signal.manager.api;
|
|||
|
||||
public class InvalidNumberException extends Exception {
|
||||
|
||||
InvalidNumberException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
InvalidNumberException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,14 @@ public sealed interface RecipientIdentifier {
|
|||
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 @@ public sealed interface RecipientIdentifier {
|
|||
} 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 sealed interface RecipientIdentifier {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public class RecipientHelper {
|
|||
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, () -> {
|
||||
|
|
|
@ -888,7 +888,7 @@ public class ManagerImpl implements Manager {
|
|||
.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);
|
||||
|
|
|
@ -69,8 +69,8 @@ public record RecipientAddress(
|
|||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue