[Pkg-mozext-commits] [gcontactsync] 59/88: Issue #38 - Do not POST or PUT contacts with no fields set
David Prévot
taffit at moszumanska.debian.org
Thu Sep 18 20:52:30 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository gcontactsync.
commit 659ec321425e3697dff8b71290d08fae2b168b41
Author: Josh Geenen <joshgeenen at gmail.com>
Date: Sun Jun 22 17:36:23 2014 -0500
Issue #38 - Do not POST or PUT contacts with no fields set
---
src/content/ContactConverter.js | 16 +++++++++++++---
src/content/Sync.js | 18 ++++++++++++++----
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/src/content/ContactConverter.js b/src/content/ContactConverter.js
index 25d59c2..b91b911 100644
--- a/src/content/ContactConverter.js
+++ b/src/content/ContactConverter.js
@@ -204,6 +204,7 @@ com.gContactSync.ContactConverter = {
"ContactConverter.cardToAtomXML from " + this.caller;
}
this.mCurrentCard = aTBContact;
+ var nonEmpty = false;
// set the regular properties from the array mConverterArr
for (i = 0, length = arr.length; i < length; i++) {
// skip the URLs
@@ -224,6 +225,7 @@ com.gContactSync.ContactConverter = {
}
com.gContactSync.LOGGER.VERBOSE_LOG(" - " + value + " type: " + type);
aGContact.setValue(obj.elementName, obj.index, type, value);
+ nonEmpty = nonEmpty || value;
}
// Birthday can be either YYYY-M-D or --M-D for no year.
// TB can have all three, just a day/month, or just a year through the UI
@@ -260,6 +262,7 @@ com.gContactSync.ContactConverter = {
birthdayVal = birthYear + "-" + birthMonth + "-" + birthDay;
}
com.gContactSync.LOGGER.VERBOSE_LOG(" * Birthday: " + birthdayVal);
+ nonEmpty = nonEmpty || birthdayVal;
aGContact.setValue("birthday", 0, null, birthdayVal);
var anniversaryDay = parseInt(aTBContact.getValue("AnniversaryDay"), 10);
@@ -279,6 +282,7 @@ com.gContactSync.ContactConverter = {
}
var anniversaryVal = anniversaryYear ? anniversaryYear + "-" + anniversaryMonth + "-" + anniversaryDay : null;
com.gContactSync.LOGGER.VERBOSE_LOG(" * Anniversary: " + anniversaryVal);
+ nonEmpty = nonEmpty || anniversaryVal;
aGContact.setValue("event", 0, "anniversary", anniversaryVal);
// set the extended properties
@@ -290,6 +294,7 @@ com.gContactSync.ContactConverter = {
if (arr[i] && !props[arr[i]]) {
props[arr[i]] = true;
value = this.checkValue(aTBContact.getValue(arr[i]));
+ nonEmpty = nonEmpty || value;
aGContact.setExtendedProperty(arr[i], value);
}
else if (arr[i] != "") {
@@ -299,6 +304,7 @@ com.gContactSync.ContactConverter = {
}
// If the myContacts pref is set and this contact is new then add the
// myContactsName group
+ // Group membership does not make a contact not "empty" according to Google's API.
if (ab.mPrefs.myContacts === "true") {
if (isNew && com.gContactSync.Sync.mContactsUrl) {
aGContact.setGroups([com.gContactSync.Sync.mContactsUrl]);
@@ -324,25 +330,29 @@ com.gContactSync.ContactConverter = {
aGContact.setGroups(groups);
}
// Upload the photo
+ // Photos do not make a contact non-empty by Google's API.
if (com.gContactSync.Preferences.mSyncPrefs.sendPhotos.value) {
aGContact = this.savePhotoFromTBContact(aTBContact, aGContact);
}
// Add the phonetic first and last names
if (com.gContactSync.Preferences.mSyncPrefs.syncPhoneticNames.value) {
+ var phonFirstName = aTBContact.getValue("PhoneticFirstName");
+ var phonLastName = aTBContact.getValue("PhoneticLastName");
aGContact.setAttribute("givenName",
com.gContactSync.gdata.namespaces.GD.url,
0,
"yomi",
- aTBContact.getValue("PhoneticFirstName"));
+ phonFirstName);
aGContact.setAttribute("familyName",
com.gContactSync.gdata.namespaces.GD.url,
0,
"yomi",
- aTBContact.getValue("PhoneticLastName"));
+ phonLastName);
+ nonEmpty = nonEmpty || phonFirstName || phonLastName;
}
- return aGContact;
+ return nonEmpty ? aGContact : null;
},
/**
* Saves the photo from the given TB contact to the given Google contact if present and if it has changed
diff --git a/src/content/Sync.js b/src/content/Sync.js
index ffd07ac..1702048 100644
--- a/src/content/Sync.js
+++ b/src/content/Sync.js
@@ -769,11 +769,16 @@ com.gContactSync.Sync = {
com.gContactSync.StringBundle.getStr("remaining"));
var cardToAdd = com.gContactSync.Sync.mContactsToAdd.shift();
com.gContactSync.LOGGER.LOG("\n" + cardToAdd.getName());
+
// get the XML representation of the card
// NOTE: cardToAtomXML adds the contact to the current group, if any
var gcontact = com.gContactSync.ContactConverter.cardToAtomXML(cardToAdd);
- var xml = gcontact.xml;
- var string = com.gContactSync.serialize(xml);
+ if (!gcontact) {
+ com.gContactSync.LOGGER.LOG_WARNING("Skipping empty contact");
+ return com.gContactSync.Sync.processAddQueue();
+ }
+
+ var string = com.gContactSync.serialize(gcontact.xml);
if (com.gContactSync.Preferences.mSyncPrefs.verboseLog.value)
com.gContactSync.LOGGER.LOG(" * XML of contact being added:\n" + string + "\n");
var httpReq = new com.gContactSync.GHttpRequest("add",
@@ -854,9 +859,14 @@ com.gContactSync.Sync = {
var editURL = gContact.getValue("EditURL").value;
com.gContactSync.LOGGER.LOG("\nUpdating " + gContact.getName());
- var xml = com.gContactSync.ContactConverter.cardToAtomXML(abCard, gContact).xml;
+ gContact = com.gContactSync.ContactConverter.cardToAtomXML(abCard, gContact);
+
+ if (!gContact) {
+ com.gContactSync.LOGGER.LOG_WARNING("Skipping empty contact");
+ return com.gContactSync.Sync.processUpdateQueue();
+ }
- var string = com.gContactSync.serialize(xml);
+ var string = com.gContactSync.serialize(gContact.xml);
if (com.gContactSync.Preferences.mSyncPrefs.verboseLog.value)
com.gContactSync.LOGGER.LOG(" * XML of contact being updated:\n" + string + "\n");
var httpReq = new com.gContactSync.GHttpRequest("update",
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/gcontactsync.git
More information about the Pkg-mozext-commits
mailing list