From 3cbd11e1621a9d4a4c2c00525aa388ad1b722015 Mon Sep 17 00:00:00 2001 From: "Jose M. Cantera" Date: Wed, 19 Dec 2012 13:30:49 +0100 Subject: [PATCH] Bug 820028 - If a Facebook contact has several phone numbers only two are imported --- .../contacts/js/fb/fb_contact_utils.js | 46 +++++++++---------- .../contacts/js/fb/fb_import.js | 2 +- apps/communications/facebook/js/fb_sync.js | 2 + .../communications/facebook/js/sync_worker.js | 2 +- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/apps/communications/contacts/js/fb/fb_contact_utils.js b/apps/communications/contacts/js/fb/fb_contact_utils.js index 466465ad047c..8e290ff86025 100644 --- a/apps/communications/contacts/js/fb/fb_contact_utils.js +++ b/apps/communications/contacts/js/fb/fb_contact_utils.js @@ -87,6 +87,20 @@ fb.setFriendPictureUrl = function(devContact, url) { // Adapts data to the mozContact format names fb.friend2mozContact = function(f) { + + function normalizeFbPhoneNumber(phone) { + var out = phone.number; + if (phone.country_code && out.indexOf('+') !== 0) { + out = '+' + phone.country_code + out; + } + return out; + } + + // Check whether this has been already normalized to mozContact + if (Array.isArray(f.familyName)) { + return f; + } + // givenName is put as name but it should be f.first_name f.familyName = [f.last_name ? f.last_name.trim() : (f.last_name || '')]; var middleName = f.middle_name ? f.middle_name.trim() : (f.middle_name || ''); @@ -111,31 +125,17 @@ fb.friend2mozContact = function(f) { f.email1 = ''; } - var nextidx = 0; - if (f.cell) { - - f.tel = [{ - type: [privateType], - value: f.cell - }]; - - nextidx = 1; - } - - if (f.other_phone) { - if (!f.tel) { - f.tel = []; - } - - f.tel[nextidx] = { - type: [privateType], - value: f.other_phone - }; - + if (Array.isArray(f.phones) && f.phones.length > 0) { + f.tel = []; + f.phones.forEach(function(aphone) { + f.tel.push({ + type: [privateType], + value: normalizeFbPhoneNumber(aphone) + }); + }); } - delete f.other_phone; - delete f.cell; + delete f.phones; f.uid = f.uid.toString(); diff --git a/apps/communications/contacts/js/fb/fb_import.js b/apps/communications/contacts/js/fb/fb_import.js index 376a8875c512..7c2a357ce021 100644 --- a/apps/communications/contacts/js/fb/fb_import.js +++ b/apps/communications/contacts/js/fb/fb_import.js @@ -49,7 +49,7 @@ if (typeof fb.importer === 'undefined') { var FRIENDS_QUERY = [ 'SELECT uid, name, first_name, last_name, pic_big, current_location, ' , 'middle_name, birthday_date, email, profile_update_time, ' , - ' work, education, cell, other_phone, hometown_location' , + ' work, education, phones, hometown_location' , ' FROM user' , ' WHERE uid ', 'IN (SELECT uid1 FROM friend WHERE uid2=me())' , diff --git a/apps/communications/facebook/js/fb_sync.js b/apps/communications/facebook/js/fb_sync.js index 795775a48792..ad16234f9ab4 100644 --- a/apps/communications/facebook/js/fb_sync.js +++ b/apps/communications/facebook/js/fb_sync.js @@ -144,6 +144,8 @@ if (!fb.sync) { // Updates the FB data from a friend function updateFbFriend(contactId, cfdata) { + fb.friend2mozContact(cfdata); + cfdata.fbInfo = cfdata.fbInfo || {}; cfdata.fbInfo.org = [fb.getWorksAt(cfdata)]; diff --git a/apps/communications/facebook/js/sync_worker.js b/apps/communications/facebook/js/sync_worker.js index 1bce58719476..c6ee22d3117f 100644 --- a/apps/communications/facebook/js/sync_worker.js +++ b/apps/communications/facebook/js/sync_worker.js @@ -18,7 +18,7 @@ importScripts('/contacts/js/fb/fb_query.js', var UPDATED_QUERY = [ 'SELECT uid, name, first_name, last_name, ' , 'middle_name, birthday_date, email, current_location, ' , - 'work, cell, other_phone, hometown_location, pic_big ' , + 'work, phones, hometown_location, pic_big ' , ' FROM user' , ' WHERE uid ', ' IN (SELECT uid1 FROM friend WHERE uid2=me()',