]> nmode's Git Repositories - signal-cli/commitdiff
Fix deleting old unregistered recipient
authorAsamK <asamk@gmx.de>
Tue, 16 May 2023 21:09:07 +0000 (23:09 +0200)
committerAsamK <asamk@gmx.de>
Tue, 16 May 2023 21:09:07 +0000 (23:09 +0200)
Fixes #1242

lib/src/main/java/org/asamk/signal/manager/helper/RecipientHelper.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java

index 2a3866a5b00bd83f39c90cea3bc896f0138b778f..f614d7ec9ab10e2ef9ab3f4dc7f77f4e930594ea 100644 (file)
@@ -107,7 +107,11 @@ public class RecipientHelper {
         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();
+            }
         }
     }
 
index d3b949f8d0850184819f12b38963157130f00758..b8a4b39bef30e125fe392408f4cfd113d4c31ad7 100644 (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 {