leftonread icon indicating copy to clipboard operation
leftonread copied to clipboard

Rethink how we match contacts to phone numbers

Open alexdanilowicz opened this issue 4 years ago • 0 comments

We need some way to JOIN between the addressbook.db tables and the chat.db tables (so that we can get the contact name, which is only stored in the addressbook.db).

We currently JOIN on phone number, as I don't know of any other shared field.

Unfortunately, the addressbook.db and chat.db store the phone number in different formats.

  • the chat.db always lists the country code.
  • the addressbook.db, however,only sometimes includes the country code.

As a result, we need to 'normalize' the two. We do this by stripping the country code if the phone_number is longer than 10 digits and ONLY matching when the phone numbers are both 10 digits.

This is bad because then contact names will not work for users outside the U.S. and Canada (the only countries where phone numbers are 10 digits).

Current implementation: normalization.ts

    THEN SUBSTR(
      replace(
        ${column}, "${COUNTRY_CODE_SYMBOL}", ""
      ),
    -${PHONE_NUMBER_LENGTH},
    ${PHONE_NUMBER_LENGTH}

alexdanilowicz avatar Mar 14 '21 07:03 alexdanilowicz