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,9 +107,13 @@ public class RecipientHelper {
try {
return Optional.of(resolveRecipient(recipient));
} catch (UnregisteredRecipientException e) {
if (recipient instanceof RecipientIdentifier.Number r) {
return account.getRecipientStore().resolveRecipientByNumberOptional(r.number());
} else {
return Optional.empty();
}
}
}
public RecipientId refreshRegisteredUser(RecipientId recipientId) throws IOException, UnregisteredRecipientException {
final var address = resolveSignalServiceAddress(recipientId);

View file

@ -215,6 +215,16 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
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 {