Skip to content

Commit

Permalink
Updated phone number matching logic based on @DjArt suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Aug 26, 2019
1 parent 10f23f4 commit 6750ede
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
29 changes: 24 additions & 5 deletions Chat.Common/ContactUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Windows.Devices.Sms;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.Globalization.PhoneNumberFormatting;

namespace Chat.Common
{
Expand Down Expand Up @@ -36,15 +37,15 @@ public static async Task<Contact> GetMyself()
return blankcontact;
}

private class PhoneNumberInfo
private class PhoneNumberInfo2
{
public string Number { get; set; }
public string CountryCode { get; set; }
}

private static PhoneNumberInfo GetPhoneNumberInformation(string phonenumber)
private static PhoneNumberInfo2 GetPhoneNumberInformation(string phonenumber)
{
PhoneNumberInfo info = new PhoneNumberInfo();
PhoneNumberInfo2 info = new PhoneNumberInfo2();
/*PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance();
PhoneNumber number;
Expand All @@ -68,14 +69,32 @@ private static PhoneNumberInfo GetPhoneNumberInformation(string phonenumber)

public static bool ArePhoneNumbersMostLikelyTheSame(string num1, string num2)
{
var formatter = new PhoneNumberFormatter();

var fnum1 = formatter.FormatPartialString(num1);
var fnum2 = formatter.FormatPartialString(num2);

if (fnum1 == fnum2)
return true;

var inum1 = new PhoneNumberInfo(fnum1);
var inum2 = new PhoneNumberInfo(fnum2);

var match = inum1.CheckNumberMatch(inum2);

if (match == PhoneNumberMatchResult.ExactMatch || match == PhoneNumberMatchResult.NationalSignificantNumberMatch || match == PhoneNumberMatchResult.ShortNationalSignificantNumberMatch)
{
return true;
}

var info = GetPhoneNumberInformation(num1);

string number = info.Number;
string countrycode = info.CountryCode;

if (string.IsNullOrEmpty(countrycode))
{
if (num2.ToLower().Replace(" ", "") == number.ToLower().Replace(" ", ""))
if (num2.ToLower().Replace(" ", "").Replace("(", "").Replace(")", "") == number.ToLower().Replace(" ", "").Replace("(", "").Replace(")", ""))
return true;
}
else
Expand All @@ -91,7 +110,7 @@ public static bool ArePhoneNumbersMostLikelyTheSame(string num1, string num2)
}
else if (string.IsNullOrEmpty(countrycode2))
{
if (num2.Replace(" ", "") == number.ToLower().Replace(" ", ""))
if (num2.Replace(" ", "").Replace("(", "").Replace(")", "") == number.ToLower().Replace(" ", "").Replace("(", "").Replace(")", ""))
return true;
}
else if (number == number2)
Expand Down
2 changes: 1 addition & 1 deletion Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Identity
Name="LumiaWOA.Chat"
Publisher="CN=Windows On Lumia Second Party Application Publisher"
Version="0.0.91.0" />
Version="0.0.92.0" />

<mp:PhoneIdentity PhoneProductId="d8719107-e9ed-450f-be3e-88003464d950" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down

0 comments on commit 6750ede

Please sign in to comment.