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

Commit

Permalink
Bug 1135044 - merge pull request #28894 from gabrielesvelto:bug-11350…
Browse files Browse the repository at this point in the history
…44-update-call-information-when-contact-changes to mozilla-b2g:master
  • Loading branch information
mozilla-autolander-deprecated committed Mar 18, 2015
2 parents 70bac3a + b51ef23 commit 1bd1a1b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
34 changes: 7 additions & 27 deletions apps/communications/dialer/js/call_log.js
Expand Up @@ -951,16 +951,11 @@ var CallLog = {
* param contactId
* Contact identifier if any. Only 'oncontactchange' events with
* 'update' or 'remove' reasons will provide a contactId parameter.
* param phoneNumbers
* Array of phoneNumbers associated with a contact. Only
* 'oncontactchange' events with 'update' or 'add' reasons will
* provide this paramater.
* param target
* DOM element to be updated. We default to the whole log if no
* 'target' param is provided.
*/
updateListWithContactInfo: function cl_updateList(reason, contactId,
phoneNumbers, target) {
updateListWithContactInfo: function cl_updateList(reason, contactId, target) {
var container = target || this.callLogContainer;

if (!container) {
Expand Down Expand Up @@ -1084,31 +1079,16 @@ var CallLog = {
};

navigator.mozContacts.oncontactchange = function oncontactchange(event) {
function contactChanged(contact, reason) {
var phoneNumbers = [];
if (contact.tel && contact.tel.length) {
phoneNumbers = contact.tel.map(function(tel) {
return tel.value;
});
}
switch (reason) {
case 'create':
CallLog.updateListWithContactInfo('create', null, phoneNumbers);
break;
case 'update':
CallLog.updateListWithContactInfo('update', event.contactID,
phoneNumbers);
break;
}
}

var reason = event.reason;
var options = {
filterBy: ['id'],
filterOp: 'equals',
filterValue: event.contactID
};

/* FIXME: We should use the contact information (id, phone number, etc...) to
* reduce the number of elements we try to update. */

if (reason === 'remove') {
CallLog.updateListWithContactInfo('remove', event.contactID);
return;
Expand All @@ -1123,17 +1103,17 @@ navigator.mozContacts.oncontactchange = function oncontactchange(event) {

var contact = e.target.result[0];
if (!fb.isFbContact(contact)) {
contactChanged(contact, reason);
CallLog.updateListWithContactInfo(reason, event.contactID);
return;
}

var fbReq = fb.getData(contact);
fbReq.onsuccess = function fbContactSuccess() {
contactChanged(fbReq.result, reason);
CallLog.updateListWithContactInfo(reason, event.contactID);
};
fbReq.onerror = function fbContactError() {
console.error('Error while querying FB: ', fbReq.error.name);
contactChanged(contact, reason);
CallLog.updateListWithContactInfo(reason, event.contactID);
};
};

Expand Down
2 changes: 2 additions & 0 deletions apps/communications/dialer/js/call_log_db.js
Expand Up @@ -1305,6 +1305,7 @@ var CallLogDBManager = {
}
}
cursor.update(group);
self._dispatchCallLogDbNewCall(self._getGroupObject(group));
count++;
cursor.continue();
} else {
Expand Down Expand Up @@ -1389,6 +1390,7 @@ var CallLogDBManager = {
if (group.contactPhoto) {
delete group.contactPhoto;
}
self._dispatchCallLogDbNewCall(self._getGroupObject(group));
cursor.update(group);
count++;
cursor.continue();
Expand Down
30 changes: 30 additions & 0 deletions apps/communications/dialer/test/unit/call_log_db_test.js
Expand Up @@ -1198,6 +1198,10 @@ suite('dialer/call_log_db', function() {
duration: duration
};

var contact = {
id: 'test'
};

teardown(function(done) {
CallLogDBManager.deleteAll(function() {
done();
Expand All @@ -1223,5 +1227,31 @@ suite('dialer/call_log_db', function() {
CallLogDBManager.add(call2);
});
});

test('when updating contact information', function(done) {
CallLogDBManager.add(call, function() {
window.addEventListener('CallLogDbNewCall', function checkEvt(evt) {
window.removeEventListener('CallLogDbNewCall', checkEvt);
assert.equal(evt.detail.group.contact.id, contact.id);
assert.equal(evt.detail.group.contact.primaryInfo, numbers[0]);
done();
});
CallLogDBManager.updateGroupContactInfo(contact, { value: numbers[0] });
});
});

test('when removing contact information', function(done) {
CallLogDBManager.add(call, function() {
CallLogDBManager.updateGroupContactInfo(contact, { value: numbers[0] },
function() {
window.addEventListener('CallLogDbNewCall', function checkEvt(evt) {
window.removeEventListener('CallLogDbNewCall', checkEvt);
assert.isUndefined(evt.detail.group.contact);
done();
});
});
CallLogDBManager.removeGroupContactInfo(contact.id, null);
});
});
});
});
1 change: 1 addition & 0 deletions shared/test/unit/mocks/dialer/mock_contacts.js
Expand Up @@ -43,6 +43,7 @@ var MockContacts = {
findListByNumber: function cm_getContactData(number, maxitems, callback) {
callback(this.mResult);
},
getRevision: function cm_getRevision() {},
mId: 'id',
mPhoto: null,
mName: null,
Expand Down

0 comments on commit 1bd1a1b

Please sign in to comment.