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 #17703 from jmcanterafonseca/multiple_contact_fb_d…
Browse files Browse the repository at this point in the history
…elete_done

Bug 988243 - Multiple contact delete does not work with Facebook Contact...
  • Loading branch information
jmcanterafonseca committed Mar 30, 2014
2 parents 5ba21c3 + 3037fde commit ebf839c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
23 changes: 19 additions & 4 deletions apps/communications/contacts/js/contacts_remover.js
Expand Up @@ -11,20 +11,35 @@
*/

function contactsRemover() {

var totalRemoved = 0;
var totalSelected = 0;
var cancelled = false;
/*jshint validthis:true */
var self = this;
var ids;
var fbData = Object.create(null);

this.init = function(cIds, cb) {
if (cIds === null || cIds.length === 0) {
return;
}
ids = cIds;
cb();

// In order to properly delete FB Contacts we need to obtain their data
// Take into account that we are querying all FB Contacts but we don't know
// beforehand if there will be any of them to be deleted
var req = fb.utils.getAllFbContacts();
req.onsuccess = function() {
var fbContacts = req.result;
fbContacts.forEach(function(aFbContact) {
fbData[aFbContact.id] = aFbContact;
});
cb();
};
req.onerror = function() {
console.error('Error while retrieving FB Contacts: ', req.error.name);
cb();
};
};

this.start = function() {
Expand Down Expand Up @@ -94,8 +109,8 @@ function contactsRemover() {
var contact = new mozContact();
contact.id = currentID;

if (fb.isFbContact(contact)) {
var fbContact = new fb.Contact(contact);
if (fbData[contact.id]) {
var fbContact = new fb.Contact(fbData[contact.id]);
request = fbContact.remove();
} else {
request = navigator.mozContacts.remove(contact);
Expand Down
11 changes: 11 additions & 0 deletions apps/communications/contacts/test/unit/mock_fb.js
Expand Up @@ -301,6 +301,17 @@ Mockfb.utils = (function() {

setCachedNumFriends: function() {

},

_fbData: [],

getAllFbContacts: function() {
return {
result: Mockfb.utils._fbData,
set onsuccess(cb) {
cb();
}
};
}
};
}());
Expand Down
Expand Up @@ -137,7 +137,7 @@ suite('Multiple Contacts Delete', function() {
});
});

test('Deleting several contact', function(done) {
test('Deleting several contacts', function(done) {
var ids = getContactIds();
subject.init(ids, function onInitDone() {
subject.start();
Expand All @@ -153,6 +153,26 @@ suite('Multiple Contacts Delete', function() {
assert.ok(ids, 'No Contact to delete');
});

test('Deleting several contacts, one of them FB Contact', function(done) {
var ids = getContactIds();
Mockfb._fbData = [
MockContactsList()[0]
];

subject.init(ids, function onInitDone() {
subject.start();
assert.ok(ids, 'No Contact to delete');
});
subject.onError = function onError() {
assert.ok(!ids, 'Error Deleting contacts');
};
subject.onFinished = function onFinished() {
assert.ok(ids, 'Finished Deleting contacts');
done();
};
assert.ok(ids, 'No Contact to delete');
});

test('Perform Delete Operation', function(done) {
var ids = getContactIds();
var promise = createSelectPromise();
Expand Down

0 comments on commit ebf839c

Please sign in to comment.