From d2e592beef5b6078f7e5601e8114f2f5f4f417e9 Mon Sep 17 00:00:00 2001 From: Karan Bedi Date: Wed, 7 Aug 2019 23:14:20 +0530 Subject: [PATCH] Add default fallbacks for country code determination --- .../android/contacts/worker/ContactsSyncWorker.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/chat/rocket/android/contacts/worker/ContactsSyncWorker.kt b/app/src/main/java/chat/rocket/android/contacts/worker/ContactsSyncWorker.kt index ec8b2e72c9..ca267bf58b 100644 --- a/app/src/main/java/chat/rocket/android/contacts/worker/ContactsSyncWorker.kt +++ b/app/src/main/java/chat/rocket/android/contacts/worker/ContactsSyncWorker.kt @@ -171,7 +171,19 @@ class ContactsSyncWorker(context : Context, params : WorkerParameters) } private fun formatPhoneNumber(phone: String, country:String): String? { - return PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), country) + var number = PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), country) + + // Default fallback: Mexico + if (number==null) { + number = PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), "MX") + } + + // Default fallback, second priority: US + if (number==null) { + number = PhoneNumberUtils.formatNumberToE164(phone.replace("-|\\s|\\(|\\)".toRegex(), ""), "US") + } + + return number } }