Ensure numbers are properly formatted before giving them to contact discovery service.

We were sending "Unknown" addresses, which would cause the service to
choke.
This commit is contained in:
Greyson Parrelli 2018-09-27 19:59:57 -07:00
parent 946f76a442
commit 6359961a82

View File

@ -348,7 +348,8 @@ public class DirectoryHelper {
@NonNull SignalServiceAccountManager accountManager,
@NonNull Set<String> eligibleContactNumbers)
{
List<Set<String>> batches = splitIntoBatches(eligibleContactNumbers, CONTACT_DISCOVERY_BATCH_SIZE);
Set<String> sanitizedNumbers = sanitizeNumbers(eligibleContactNumbers);
List<Set<String>> batches = splitIntoBatches(sanitizedNumbers, CONTACT_DISCOVERY_BATCH_SIZE);
List<Future<Set<String>>> futures = new ArrayList<>(batches.size());
for (Set<String> batch : batches) {
@ -360,6 +361,10 @@ public class DirectoryHelper {
return futures;
}
private static Set<String> sanitizeNumbers(@NonNull Set<String> numbers) {
return Stream.of(numbers).filter(number -> number.startsWith("+")).collect(Collectors.toSet());
}
private static List<Set<String>> splitIntoBatches(@NonNull Set<String> numbers, int batchSize) {
List<String> numberList = new ArrayList<>(numbers);
List<Set<String>> batches = new LinkedList<>();