Skip to content

Commit

Permalink
Handle all possible identifiers of a RecipientAddress
Browse files Browse the repository at this point in the history
Fixes #1516
  • Loading branch information
AsamK committed May 17, 2024
1 parent 8f756cd commit 53d7e0f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static Single fromAddress(RecipientAddress address) {
return new Number(address.number().get());
} else if (address.aci().isPresent()) {
return new Uuid(UUID.fromString(address.aci().get()));
} else if (address.pni().isPresent()) {
return new Pni(address.pni().get());
} else if (address.username().isPresent()) {
return new Username(address.username().get());
}
Expand All @@ -71,6 +73,19 @@ public RecipientAddress toPartialRecipientAddress() {
}
}

record Pni(String pni) implements Single {

@Override
public String getIdentifier() {
return pni;
}

@Override
public RecipientAddress toPartialRecipientAddress() {
return new RecipientAddress(null, pni, null, null);
}
}

record Number(String number) implements Single {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single>
public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredRecipientException {
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()));
} else if (recipient instanceof RecipientIdentifier.Number numberRecipient) {
final var number = numberRecipient.number();
return account.getRecipientStore().resolveRecipientByNumber(number, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.push.ServiceId.PNI;
import org.whispersystems.signalservice.api.push.ServiceIdType;
import org.whispersystems.signalservice.api.push.exceptions.CdsiResourceExhaustedException;
import org.whispersystems.signalservice.api.util.DeviceNameUtil;
Expand Down Expand Up @@ -836,6 +837,9 @@ public SendMessageResults sendRemoteDeleteMessage(
if (recipient instanceof RecipientIdentifier.Uuid u) {
account.getMessageSendLogStore()
.deleteEntryForRecipientNonGroup(targetSentTimestamp, ACI.from(u.uuid()));
} else if (recipient instanceof RecipientIdentifier.Pni pni) {
account.getMessageSendLogStore()
.deleteEntryForRecipientNonGroup(targetSentTimestamp, PNI.parseOrThrow(pni.pni()));
} else if (recipient instanceof RecipientIdentifier.Single r) {
try {
final var recipientId = context.getRecipientHelper().resolveRecipient(r);
Expand Down

0 comments on commit 53d7e0f

Please sign in to comment.