try {
return Optional.of(resolveRecipient(recipient));
} catch (UnregisteredRecipientException e) {
- return Optional.empty();
+ if (recipient instanceof RecipientIdentifier.Number r) {
+ return account.getRecipientStore().resolveRecipientByNumberOptional(r.number());
+ } else {
+ return Optional.empty();
+ }
}
}
return byNumber.get().id();
}
+ public Optional<RecipientId> resolveRecipientByNumberOptional(final String number) {
+ final Optional<RecipientWithAddress> byNumber;
+ try (final var connection = database.getConnection()) {
+ byNumber = findByNumber(connection, number);
+ } catch (SQLException e) {
+ throw new RuntimeException("Failed read from recipient store", e);
+ }
+ return byNumber.map(RecipientWithAddress::id);
+ }
+
public RecipientId resolveRecipientByUsername(
final String username, Supplier<ServiceId> serviceIdSupplier
) throws UnregisteredRecipientException {