Fix deleting old unregistered recipient

Fixes #1242
This commit is contained in:
AsamK 2023-05-16 23:09:07 +02:00
parent a3bc754e80
commit 760934d5a5
2 changed files with 15 additions and 1 deletions

View file

@ -107,7 +107,11 @@ public class RecipientHelper {
try { try {
return Optional.of(resolveRecipient(recipient)); return Optional.of(resolveRecipient(recipient));
} catch (UnregisteredRecipientException e) { } catch (UnregisteredRecipientException e) {
return Optional.empty(); if (recipient instanceof RecipientIdentifier.Number r) {
return account.getRecipientStore().resolveRecipientByNumberOptional(r.number());
} else {
return Optional.empty();
}
} }
} }

View file

@ -215,6 +215,16 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
return byNumber.get().id(); 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( public RecipientId resolveRecipientByUsername(
final String username, Supplier<ServiceId> serviceIdSupplier final String username, Supplier<ServiceId> serviceIdSupplier
) throws UnregisteredRecipientException { ) throws UnregisteredRecipientException {