capacitor-community / contacts

Contacts Plugin for Capacitor
https://capacitor-community.github.io/contacts/
119 stars 52 forks source link

Contact fields duplicating in strange ways on Android #123

Open viking2917 opened 2 months ago

viking2917 commented 2 months ago

Describe the bug On Android, when retrieving contacts from the device (which are via Google Contacts), fields are frequently, but not always, duplicated, and sometimes altered.

For example, a contact that has a single email address when viewed in Google Contacts, will return in the following form:

emails: Array(2)
0: {type: 'custom', isPrimary: true, address: '<useremail>@gmail.com'}
1: {type: 'custom', isPrimary: true, address: '<useremail>@gmail.com'}

where <useremail> is the contact's real email. (also, isPrimary should not be true for two addresses should it?)

A contact with one phone number will often return two phone numbers, one of which will have +1 mysteriously prepended to it or be reformatted:

phones: Array(2)
0: {type: 'mobile', isPrimary: true, number: '111-222-3333'}
1: {type: 'mobile', isPrimary: true, number: '11112223333'}

(111-222-3333 is made up for privacy reasons, hiding the real phone number, which has been duplicated and reformatted by the plugin.)

The plug works perfectly, no duplication of entries, on iOS, with the same code base and same contact database.

To Reproduce

I am not sure how to reproduce this without using my contacts, but my code is roughly as follows:

import { Contacts, GetContactsResult, ContactPayload, EmailPayload, PhonePayload, EmailType, NamePayload } from '@capacitor-community/contacts';

...
const projection = { name: true, emails: true, phones: true, image: true, };
let result = await Contacts.getContacts({projection}).catch((err: any) => {
        console.log('error on contacts', err);
});

console.log(result);

and the offending contacts are in the result. Not every contact has undergone duplication, but many have been. I cannot see any pattern to when the duplication happens.

I am using Capacitor 6 and "@capacitor-community/contacts": "^6.0.5-alpha.0",

I do not know if Capacitor 6 might be the issue?

Expected behavior The plugin should not duplicate emails or phone numbers. If they are to be normalized, then only the normalized version should be returned - although normalization of phone #s is fraught with complications...

Screenshots None, but can be supplied if needed.

Desktop (please complete the following information): N/A

Smartphone (please complete the following information):

Additional context

Changing the projection seems to have no effect, only the requested fields show up, but with the same duplication.

I read this issue, which reports oddness with Android; I do not know if they might be related. https://github.com/capacitor-community/contacts/issues/94

stib commented 3 weeks ago

I am seeing similar issue with version 5.0.4 - some contacts are tripled, some doubled while some remain single. Don't see a pattern to explain what's going on.

I am on Samsung S22, Android version 13