From e47db0d5327f37af7442db9e560cab32c84678d6 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 28 Jun 2021 11:12:48 -0400 Subject: [PATCH] Ensure recipients added to the cache have an identifier. --- .../securesms/recipients/LiveRecipientCache.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java index c531b6a9a0..63069886fe 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java @@ -100,7 +100,7 @@ public final class LiveRecipientCache { */ @AnyThread public void addToCache(@NonNull Collection newRecipients) { - for (Recipient recipient : newRecipients) { + newRecipients.stream().filter(this::isValidForCache).forEach(recipient -> { LiveRecipient live; boolean needsResolve; @@ -131,7 +131,7 @@ public final class LiveRecipientCache { } }); } - } + }); } @NonNull Recipient getSelf() { @@ -205,4 +205,8 @@ public final class LiveRecipientCache { recipients.clear(); } } + + private boolean isValidForCache(@NonNull Recipient recipient) { + return !recipient.getId().isUnknown() && (recipient.hasServiceIdentifier() || recipient.getGroupId().isPresent() || recipient.hasSmsAddress()); + } }