Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7087 from jmcanterafonseca/fix_tel
Browse files Browse the repository at this point in the history
Bug 820028 - If a Facebook contact has several phone numbers only two ar...
  • Loading branch information
jmcanterafonseca committed Dec 19, 2012
2 parents ff651e8 + 3cbd11e commit e342b96
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
46 changes: 23 additions & 23 deletions apps/communications/contacts/js/fb/fb_contact_utils.js
Expand Up @@ -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 || '');
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion apps/communications/contacts/js/fb/fb_import.js
Expand Up @@ -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())' ,
Expand Down
2 changes: 2 additions & 0 deletions apps/communications/facebook/js/fb_sync.js
Expand Up @@ -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)];
Expand Down
2 changes: 1 addition & 1 deletion apps/communications/facebook/js/sync_worker.js
Expand Up @@ -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()',
Expand Down

0 comments on commit e342b96

Please sign in to comment.