[Pkg-mozext-commits] [gcontactsync] 01/17: Issue #46 - Improve merging. Part 1 of changes (all simple attributes).
David Prévot
taffit at moszumanska.debian.org
Sat Nov 1 23:37:01 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 994b761c4e418e2939a8a38267cafa13f834d049
Author: Josh Geenen <joshgeenen at gmail.com>
Date: Thu Jul 31 20:47:54 2014 -0500
Issue #46 - Improve merging. Part 1 of changes (all simple attributes).
---
src/content/ContactConverter.js | 67 +++++++++++++++++++++++++++++++++++++++++
src/content/Sync.js | 15 ++++++---
2 files changed, 77 insertions(+), 5 deletions(-)
diff --git a/src/content/ContactConverter.js b/src/content/ContactConverter.js
index 2d4be23..3d49d52 100644
--- a/src/content/ContactConverter.js
+++ b/src/content/ContactConverter.js
@@ -530,6 +530,73 @@ com.gContactSync.ContactConverter = {
}
},
/**
+ * Merges the two contacts together. This is a very primitive merge and only
+ * copies values from both sides into the other.
+ * If both contacts have a value the updateGoogleInConflicts pref decides which
+ * value "wins".
+ * @param aTBContact {TBContact} The Thunderbird contact to merge.
+ * @param aGContact {GContact} The Google contact to merge.
+ * @return Whether the Google contact was updated.
+ */
+ merge: function ContactConverter_merge(aTBContact, aGContact) {
+
+ if (!this.mInitialized)
+ this.init();
+
+ this.mCurrentCard = aTBContact;
+ var ab = aTBContact.mAddressBook;
+
+ aTBContact.setValue("GoogleID", aGContact.id);
+ aTBContact.setValue("LastModifiedDate", 0);
+
+ var gContactUpdated = false;
+ var tbContactUpdated = false;
+ var arr = this.mConverterArr;
+
+ for (var i = 0, length = arr.length; i < length; i++) {
+
+ var obj = arr[i],
+ property = aGContact.getValue(obj.elementName, obj.index, obj.type),
+ value = this.checkValue(aTBContact.getValue(arr[i])),
+ type = aTBContact.getValue(obj.tbName + "Type");
+
+ if (!type || type === "")
+ type = obj.type;
+ property = property || new com.gContactSync.Property("", "");
+ if (obj.tbName === com.gContactSync.dummyEmailName &&
+ com.gContactSync.isDummyEmail(value)) {
+ value = null;
+ type = null;
+ }
+
+ com.gContactSync.LOGGER.VERBOSE_LOG(obj.tbName + ": '" + property.value +
+ "'/'" + value + " , type: '" + property.type +
+ "'/'" + type + "'");
+
+ // If TB has a value and (Google's is empty or update Google in conflict)
+ // update Google.
+ if (value && !property || value && !ab.mPrefs.updateGoogleInConflicts) {
+ gContactUpdated = true;
+ aGContact.setValue(obj.elementName, obj.index, type, value);
+ } else {
+ tbContactUpdated = true;
+ aTBContact.setValue(obj.tbName, property.value);
+ // set the type, if it is an attribute with a type
+ if (property.type)
+ aTBContact.setValue(obj.tbName + "Type", property.type);
+ }
+ }
+ // TODO:
+ // Birthday
+ // Anniversary
+ // Extended properties (TB -> Google only)
+ // Groups
+ // Photo
+ // Phonetic names
+ if (tbContactUpdated) aTBContact.update();
+ return gContactUpdated;
+ },
+ /**
* Saves the photo from the given Google contact to the given TB contact if present and if it has changed
* since the last sync.
* @param aGContact {GContact} A GContact object with the photo to save.
diff --git a/src/content/Sync.js b/src/content/Sync.js
index 1702048..a282ee5 100644
--- a/src/content/Sync.js
+++ b/src/content/Sync.js
@@ -487,21 +487,26 @@ com.gContactSync.Sync = {
// similar TB contacts during the first sync.
// This is very basic, and won't merge duplicates in Thunderbird or dups
// in Google; it just matches with the first contact it finds, if any.
- if (lastSync == 0) {
+ if (lastSync === 0) {
com.gContactSync.Overlay.setStatusBarText(com.gContactSync.StringBundle.getStr("firstSyncContacts"));
for (i = 0, length = abCards.length; i < length; i++) {
if (abCards[i].getValue("GoogleID")) continue;
for (var id in gContacts) {
- if (gContacts[id] && abCards[i] && !gContacts[id].merged &&
+ if (gContacts[id] && abCards[i] &&
com.gContactSync.GAbManager.compareContacts(
abCards[i],
gContacts[id],
["DisplayName", "PrimaryEmail"],
["fullName", "email"],
0.5)) {
- abCards[i].setValue("GoogleID", id);
- abCards[i].setValue("LastModifiedDate", 0);
- gContacts[id].merged = true;
+ com.gContactSync.LOGGER.LOG(abCards[i].getName() + ": " + id);
+ com.gContactSync.LOGGER.LOG(" * Merging");
+ if (com.gContactSync.ContactConverter.merge(abCards[i], gContacts[id])) {
+ com.gContactSync.Sync.mContactsToUpdate.push(toUpdate);
+ }
+ gContacts[id] = null;
+ abCards.splice(i, 1);
+ --i;
break;
}
}
--
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