import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.CdsiInvalidArgumentException;
import org.whispersystems.signalservice.api.push.exceptions.CdsiInvalidTokenException;
+import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.UUID;
import static org.asamk.signal.manager.config.ServiceConfig.MAXIMUM_ONE_OFF_REQUEST_SIZE;
import static org.asamk.signal.manager.util.Utils.handleResponseException;
.toSignalServiceAddress();
}
- public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws UnregisteredRecipientException {
+ public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws UnregisteredRecipientException, IOException {
final var recipientIds = new HashSet<RecipientId>(recipients.size());
for (var number : recipients) {
final var recipientId = resolveRecipient(number);
}
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.from(pniRecipient.pni()));
- } else if (recipient instanceof RecipientIdentifier.Number numberRecipient) {
- final var number = numberRecipient.number();
+ if (recipient instanceof RecipientIdentifier.Uuid(UUID uuid)) {
+ return account.getRecipientResolver().resolveRecipient(ACI.from(uuid));
+ } else if (recipient instanceof RecipientIdentifier.Pni(UUID pni)) {
+ return account.getRecipientResolver().resolveRecipient(PNI.from(pni));
+ } else if (recipient instanceof RecipientIdentifier.Number(String number)) {
return account.getRecipientStore().resolveRecipientByNumber(number, () -> {
try {
return getRegisteredUserByNumber(number);
return null;
}
});
- } else if (recipient instanceof RecipientIdentifier.Username usernameRecipient) {
- var username = usernameRecipient.username();
- return resolveRecipientByUsernameOrLink(username, false);
+ } else if (recipient instanceof RecipientIdentifier.Username(String username)) {
+ try {
+ return resolveRecipientByUsernameOrLink(username, false);
+ } catch (Exception e) {
+ return null;
+ }
}
throw new AssertionError("Unexpected RecipientIdentifier: " + recipient);
}
public RecipientId resolveRecipientByUsernameOrLink(
String username,
boolean forceRefresh
- ) throws UnregisteredRecipientException {
+ ) throws UnregisteredRecipientException, IOException {
final Username finalUsername;
try {
finalUsername = getUsernameFromUsernameOrLink(username);
try {
final var aci = handleResponseException(dependencies.getUsernameApi().getAciByUsername(finalUsername));
return account.getRecipientStore().resolveRecipientTrusted(aci, finalUsername.getUsername());
- } catch (IOException e) {
- throw new UnregisteredRecipientException(new org.asamk.signal.manager.api.RecipientAddress(null,
- null,
- null,
- username));
+ } catch (NonSuccessfulResponseCodeException e) {
+ if (e.code == 404) {
+ throw new UnregisteredRecipientException(new org.asamk.signal.manager.api.RecipientAddress(null,
+ null,
+ null,
+ username));
+ }
+ logger.debug("Failed to get uuid for username: {}", username, e);
+ throw e;
}
}
return account.getRecipientStore().resolveRecipientByUsername(finalUsername.getUsername(), () -> {
try {
return Optional.of(resolveRecipient(recipient));
} catch (UnregisteredRecipientException e) {
- if (recipient instanceof RecipientIdentifier.Number r) {
- return account.getRecipientStore().resolveRecipientByNumberOptional(r.number());
+ if (recipient instanceof RecipientIdentifier.Number(String number)) {
+ return account.getRecipientStore().resolveRecipientByNumberOptional(number);
} else {
return Optional.empty();
}
token,
null,
dependencies.getLibSignalNetwork(),
- false,
newToken -> {
if (isPartialRefresh) {
account.getCdsiStore().updateAfterPartialCdsQuery(newNumbers);