From 6359961a821239bc5316ea7a4764eb083cf2ef5c Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 27 Sep 2018 19:59:57 -0700 Subject: [PATCH] Ensure numbers are properly formatted before giving them to contact discovery service. We were sending "Unknown" addresses, which would cause the service to choke. --- src/org/thoughtcrime/securesms/util/DirectoryHelper.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java index fed2f4e49c..145ec5428f 100644 --- a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java +++ b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java @@ -348,8 +348,9 @@ public class DirectoryHelper { @NonNull SignalServiceAccountManager accountManager, @NonNull Set eligibleContactNumbers) { - List> batches = splitIntoBatches(eligibleContactNumbers, CONTACT_DISCOVERY_BATCH_SIZE); - List>> futures = new ArrayList<>(batches.size()); + Set sanitizedNumbers = sanitizeNumbers(eligibleContactNumbers); + List> batches = splitIntoBatches(sanitizedNumbers, CONTACT_DISCOVERY_BATCH_SIZE); + List>> futures = new ArrayList<>(batches.size()); for (Set batch : batches) { Future> future = SignalExecutors.IO.submit(() -> { @@ -360,6 +361,10 @@ public class DirectoryHelper { return futures; } + private static Set sanitizeNumbers(@NonNull Set numbers) { + return Stream.of(numbers).filter(number -> number.startsWith("+")).collect(Collectors.toSet()); + } + private static List> splitIntoBatches(@NonNull Set numbers, int batchSize) { List numberList = new ArrayList<>(numbers); List> batches = new LinkedList<>();