morenoh149 / react-native-contacts

React Native Contacts
MIT License
1.64k stars 560 forks source link

isStarred is not working #727

Closed theshilovs closed 5 months ago

theshilovs commented 9 months ago

Thanks for the library!

Android, "react": "18.2.0", "react-native-contacts": "^7.0.8",

  const newContactPhone = () => {
    Contacts.addContact({
      familyName: 'test',
      givenName: 'test',
      isStarred: true,
    }).then(contact => {
      console.log(contact, 'CONTACTPHONE');
    });
  };

LOG {"company": null, "department": null, "displayName": "test test", "emailAddresses": [], "familyName": "test", "givenName": "test", "hasThumbnail": false, "imAddresses": [], "isStarred": false, "jobTitle": null, "middleName": "", "note": null, "phoneNumbers": [], "postalAddresses": [], "prefix": null, "rawContactId": "4765", "recordID": "4766", "suffix": null, "thumbnailPath": "", "urlAddresses": []} CONTACTPHONE

How is it?

morenoh149 commented 9 months ago

looks like the starred option is never unpacked on android

import android.provider.ContactsContract.ContactOptionsColumns

https://developer.android.com/reference/android/provider/ContactsContract.ContactOptionsColumns#STARRED

    @ReactMethod
    public void addContact(ReadableMap contact, Promise promise) {
        if (contact == null) {
            promise.reject("New contact cannot be null.");
            return;
        }
        String givenName = contact.hasKey("givenName") ? contact.getString("givenName") : null;
        String middleName = contact.hasKey("middleName") ? contact.getString("middleName") : null;
        String familyName = contact.hasKey("familyName") ? contact.getString("familyName") : null;
        String prefix = contact.hasKey("prefix") ? contact.getString("prefix") : null;
...

https://github.com/morenoh149/react-native-contacts/blob/0258847f17b116bf38a343f2ac339606f4c76f9c/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsManager.java#L602

ayelenguini commented 8 months ago

Hello! I might have a similar issue to address here. I noticed that the isStarred property though present on the example contact record is not showing on the Contact interface provided by the library:

export interface Contact {
    recordID: string;
    backTitle: string;
    company: string|null;
    emailAddresses: EmailAddress[];
    displayName: string;
    familyName: string;
    givenName: string;
    middleName: string;
    jobTitle: string;
    phoneNumbers: PhoneNumber[];
    hasThumbnail: boolean;
    thumbnailPath: string;
    postalAddresses: PostalAddress[];
    prefix: string;
    suffix: string;
    department: string;
    birthday: Birthday;
    imAddresses: InstantMessageAddress[]
    note: string;
}

Is there a reason for this? Has this property been recently unsupported? Is it because this property is only supposed to be available on Android devices?

Thanks!

morenoh149 commented 8 months ago

@ayelenguini its just an oversight. When we first wrote the example we did not support typescript. Ts annotations were added later by another author. isStarred should be added to the ts definition but we should also check that they are properly set when creating a new contact.

ayelenguini commented 8 months ago

@morenoh149 and what about when requesting the contact list itself? would this property be available on the return object? is it only available on android?

morenoh149 commented 8 months ago

@ayelenguini it's probably missing when requesting the contact list itself as well

github-actions[bot] commented 6 months ago

This issue is stale, please provide more information about the status