mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Add support for the new Benin phone format.
This commit is contained in:
@@ -4,8 +4,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -22,7 +20,7 @@ import java.util.Set;
|
||||
*/
|
||||
class FuzzyPhoneNumberHelper {
|
||||
|
||||
private final static List<FuzzyMatcher> FUZZY_MATCHERS = Arrays.asList(new MexicoFuzzyMatcher(), new ArgentinaFuzzyMatcher());
|
||||
private final static List<FuzzyMatcher> FUZZY_MATCHERS = Arrays.asList(new MexicoFuzzyMatcher(), new ArgentinaFuzzyMatcher(), new BeninFuzzyMatcher());
|
||||
|
||||
/**
|
||||
* This should be run on the list of eligible numbers for contact intersection so that we can
|
||||
@@ -151,6 +149,41 @@ class FuzzyPhoneNumberHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Benin has added an 01 after their +229 country code, e.g. both of these numbers are valid and map to the same logical number:
|
||||
*
|
||||
* +22912345678
|
||||
* +2290112345678
|
||||
*
|
||||
* The format with the added 01 should be preferred.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static class BeninFuzzyMatcher implements FuzzyMatcher {
|
||||
|
||||
@Override
|
||||
public boolean matches(@NonNull String number) {
|
||||
return (number.startsWith("+229") && number.length() == 12) || (number.startsWith("+22901") && number.length() == 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getVariant(String number) {
|
||||
if(number.startsWith("+229") && number.length() == 12) {
|
||||
return "+22901" + number.substring("+229".length());
|
||||
}
|
||||
|
||||
if(number.startsWith("+22901") && number.length() == 14) {
|
||||
return "+229" + number.substring("+22901".length());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreferredVariant(@NonNull String number) {
|
||||
return number.startsWith("+22901") && number.length() == 14;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InputResult {
|
||||
private final Set<String> numbers;
|
||||
private final Map<String, String> originalToVariant;
|
||||
|
||||
@@ -23,7 +23,6 @@ class MiscellaneousValues internal constructor(store: KeyValueStore) : SignalSto
|
||||
private const val LAST_FOREGROUND_TIME = "misc.last_foreground_time"
|
||||
private const val PNI_INITIALIZED_DEVICES = "misc.pni_initialized_devices"
|
||||
private const val LINKED_DEVICES_REMINDER = "misc.linked_devices_reminder"
|
||||
private const val HAS_LINKED_DEVICES = "misc.linked_devices_present"
|
||||
private const val USERNAME_QR_CODE_COLOR = "mis.username_qr_color_scheme"
|
||||
private const val KEYBOARD_LANDSCAPE_HEIGHT = "misc.keyboard.landscape_height"
|
||||
private const val KEYBOARD_PORTRAIT_HEIGHT = "misc.keyboard.protrait_height"
|
||||
@@ -161,12 +160,6 @@ class MiscellaneousValues internal constructor(store: KeyValueStore) : SignalSto
|
||||
*/
|
||||
var hasPniInitializedDevices by booleanValue(PNI_INITIALIZED_DEVICES, true)
|
||||
|
||||
/**
|
||||
* Whether or not the user has linked devices.
|
||||
*/
|
||||
@get:JvmName("hasLinkedDevices")
|
||||
var hasLinkedDevices by booleanValue(HAS_LINKED_DEVICES, false)
|
||||
|
||||
/**
|
||||
* Whether or not we should show a reminder for the user to relink their devices after re-registering.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.thoughtcrime.securesms.contacts.sync
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.thoughtcrime.securesms.contacts.sync.FuzzyPhoneNumberHelper.BeninFuzzyMatcher
|
||||
|
||||
class BeninFuzzyMatcherTest {
|
||||
|
||||
@Test
|
||||
fun matches() {
|
||||
val subject = BeninFuzzyMatcher()
|
||||
|
||||
Assert.assertTrue(subject.matches("+22912345678"))
|
||||
Assert.assertTrue(subject.matches("+2290112345678"))
|
||||
|
||||
Assert.assertFalse(subject.matches("+2290212345678"))
|
||||
Assert.assertFalse(subject.matches("+229999999999"))
|
||||
Assert.assertFalse(subject.matches("+11235550101"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getVariant() {
|
||||
val subject = BeninFuzzyMatcher()
|
||||
|
||||
Assert.assertEquals("+22912345678", subject.getVariant("+2290112345678"))
|
||||
Assert.assertEquals("+2290112345678", subject.getVariant("+22912345678"))
|
||||
|
||||
Assert.assertNull(subject.getVariant(""))
|
||||
Assert.assertNull(subject.getVariant("+535512345678"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isPreferredVariant() {
|
||||
val subject = BeninFuzzyMatcher()
|
||||
|
||||
Assert.assertTrue(subject.isPreferredVariant("+2290112345678"))
|
||||
Assert.assertFalse(subject.isPreferredVariant("+22912345678"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user