fix: normalize phone numbers in search comparison
Problem
Searching contacts yields no results most of the time because I don't type it in the exact format I stored it.
I usually have contacts stored in the format: +44 7…
(Sometimes more spaces if I copy and pasted it from a company website.)
However, I often search for contacts in the format: +447…
Because I don't specify the whitespace, it doesn't match most of the numbers. I think this is a pretty big usability issue.
Someone else also had a similar problem and reported it in GNOME Calls, see calls#325 (closed).
Solution
If the phone number is not an exact match, normalize the string, and try and match the normalized phone number in #_string_matches_token
.
- If it matches, return
2
similarly to a phone number match. - If it doesn't match, just continue with the usual logic.
I've added 3 test cases.
-
+1-800
matched before anyway. -
8675309
matched before anyway. -
1800
did not match before, but now does.👍
Manually tested on my PinePhone Pro running postmarketOS 23.06, Phosh 0.27.0, GNOME 44.
Related
- Fixes calls#325 (closed)
- Partially fulfills #135
Chores
Performs a chore on the side. There were 2 for
loops that had a comment noting why they couldn't be foreach
. However, the bug referenced by the comments appears to have been resolved, and with the change all tests are passing.