ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.05k forks source link

Contacts API has no support to update an existing contact? #1304

Open jeffthompson1971 opened 8 years ago

jeffthompson1971 commented 8 years ago

I see examples out there of how to do this with the plugin code directly, but the ngCordova wrappers does not seem to support it at all. Am i missing something? If it can be done with ngCordova can you point me to example code?

gortok commented 8 years ago

If the wrapper doesn't support it, I'll happily accept a PR to support it.

jeffthompson1971 commented 8 years ago

Hmm... I've never done that before but if I'm going to have to add it for myself I may as well do it in a way that integrates properly into ngCordova. I'll give it a go. Can you tell me if there is any info or guidelines on how to extend ngCordova properly? I really don't want to have a mix of ngCordova APIs with direct plugin APIs.... feels sloppy right?

On Sat, Jul 23, 2016 at 12:13 PM, George Stocker notifications@github.com wrote:

If the wrapper doesn't support it, I'll happily accept a PR to support it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/driftyco/ng-cordova/issues/1304#issuecomment-234729285, or mute the thread https://github.com/notifications/unsubscribe-auth/AB7Nvgz08H8QYZ5hdYLmvFX3zvYVR9ngks5qYkuwgaJpZM4JTZK9 .

jeffthompson1971 commented 8 years ago

I have a question. I'm not understanding the existing ngCordova contacts wrapper. It doesn't seem to use the plugin as it was designed. The 'find' for example. Your 'find' is not using the approach of creating a proper object like:

// per cordova docs on contact plugin

var options      = new ContactFindOptions();
options.filter   = "Bob";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
var fields       = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccess, onError, options);

Your ngCordova code is just uses POJS object

find: function (options) {
        var q = $q.defer();
        var fields = options.fields || ['id', 'displayName'];
        delete options.fields;
        if (Object.keys(options).length === 0) {
          navigator.contacts.find(fields, function (results) {
            q.resolve(results);
          },function (err) {
            q.reject(err);
          });
        }

I'm just trying to get my head around the current implementation so I can make a pull request for the update bit. Can you explain why the divergence from cordova API. Can I have my API use the proper documented code?

gortok commented 8 years ago

I wouldn't be surprised if the contacts wrapper was based on an older version of the plugin.

gortok commented 8 years ago

Feel free to upgrade the wrapper to match the current implementation. I'll be happy to include the change in the release notes.

jeffthompson1971 commented 8 years ago

Ok... I have another question for you that is actually maybe more of a global approach question for dealing with plugins in general.

How would you propose to handle a flow with a plugin that needs user confirmation? Specific to Contacts, let say I want to add an API that is like an 'upsert' -meaning if the the contact does not exist it creates a new one, if it DOES exist we update it with the new data. Because it seems the plugin is quite limited in how it searches, meaning you can only search for ONE string like 'Bob' - I don't see any support for filtering on givenName='Bob' && familyName="Jones". So given that, when I go to 'upsert' and I find that there are 3 contacts with givenName=Bob, now I would want to show a dialog to the user asking them which one they want to update. But in the context of the Contacts plugin I have no clue if the app has support for navigator.notification.confirm (or whatever it is) so what would a plugin developer do in such a case? Is it just something that can't be done? meaning the best you could do with your API is let the app call a 'find' first, then if it returns more than one then the app handles the confirmation dialog in whatever way it wants to and then it uses the 'save' API (if new) and maybe a clone of the contact, 'remove' the original one and 'save' the cloned one (as a way to do an update). Is that the only viable option or is there any wrapper around 'confirm dialog' that is smart enough to detect what the platform has and uses it?

Dunno..sorry for the spam I'm just curious

jeffthompson1971 commented 8 years ago

Hi driftyco/ng-cordova,

I'd like to add you to my professional network on LinkedIn.

Confirm that you know Jeffrey: https://www.linkedin.com/comm/start/accept-invitation?sharedKey=FWayFBRj&invitationId=6184839341722910720&trk=eml-guest-invite-cta&trkEmail=eml-invite_guest-null-2-null-null-0%7Eitev9ape%7Eyk

You received an invitation to connect. LinkedIn will use your email address to make suggestions to our members in features like People You May Know. Unsubscribe here: https://www.linkedin.com/e/v2?e=0-itev9ape-yk&t=lun&midToken=AQFmrFVhGEd36Q&ek=invite_guest&loid=AQHdBg7nn92P_wAAAVdT2256aioHfOUsmUYgMvQlHnp_8hmABwmx2occGhKEvQbHLtnw3--XGSLK6htrN1EOWQMTpbnRqPSuDH7AHzvBhWONLDGyqkp5GHt2TGEzDnjX7V_pr7YzB6J_pZ_US1pvvCRcJYlt8eYm8_PEntVgbekFJvlEOU3HCUtndm1NN_D9y_qo&eid=0-itev9ape-yk

This email was sent to reply@reply.github.com.

If you need assistance or have questions, please contact LinkedIn Customer Service: https://www.linkedin.com/e/v2?e=0-itev9ape-yk&a=customerServiceUrl&ek=invite_guest

© 2016 LinkedIn Corporation, 2029 Stierlin Court, Mountain View CA 94043. LinkedIn and the LinkedIn logo are registered trademarks of LinkedIn.

jeffthompson1971 commented 8 years ago

Jeffrey Thompson would like to connect on LinkedIn. How would you like to respond?

Accept: https://www.linkedin.com/comm/start/accept-invitation?sharedKey=FWayFBRj&invitationId=6184839341722910720&trk=eml-first_guest_reminder_01-hero-121-accept_text&trkEmail=eml-first_guest_reminder_01-hero-121-accept_text-null-%7E2up9zg%7Eitndambu%7E68

View Jeffrey Thompson's profile: https://www.linkedin.com/comm/start/accept-invitation?sharedKey=FWayFBRj&invitationId=6184839341722910720&trk=eml-first_guest_reminder_01-hero-3-profile_text&trkEmail=eml-first_guest_reminder_01-hero-3-profile_text-null-%7E2up9zg%7Eitndambu%7E68

You received an invitation to connect. LinkedIn will use your email address to make suggestions to our members in features like People You May Know. Unsubscribe here: https://www.linkedin.com/e/v2?e=-2up9zg-itndambu-68&t=lun&midToken=AQFmrFVhGEd36Q&ek=first_guest_reminder_01&li=123&m=unsub&ts=HTML&eid=-2up9zg-itndambu-68&loid=AQGfKKQvLJur-AAAAVdzT1yPROr2zdkRtLIYUa_wqLMSpzCCHRawgC2FcR_WWMrfL2HA_viLG4r6C45WH15z14bQx5hKUk4IQFvyGV9gzTPCHp_JsIyu5lDGMnn_emdleKrBDOktXMycHsZ6KGNm1tz9neEFz7iL1KFZkcmQjqNNrUKjQBnLh0q9CoHFCD_CUBKO

This email was sent to reply@reply.github.com.

If you need assistance or have questions, please contact LinkedIn Customer Service: https://www.linkedin.com/e/v2?e=-2up9zg-itndambu-68&a=customerServiceUrl&ek=first_guest_reminder_01

© 2016 LinkedIn Corporation, 2029 Stierlin Court, Mountain View CA 94043. LinkedIn and the LinkedIn logo are registered trademarks of LinkedIn.