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 #13138 from jmcanterafonseca/fb_datastore_final
Browse files Browse the repository at this point in the history
Bug 923637 - Use DataStore instead of indexedDB in the fb_data.js module
  • Loading branch information
jmcanterafonseca committed Oct 29, 2013
2 parents 0f7b80d + 56d15f5 commit 33156ce
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 275 deletions.
22 changes: 14 additions & 8 deletions apps/communications/contacts/js/fb/fb_contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ fb.Contact = function(deviceContact, cid) {
}

// Persists FB Friend Data to the FB cache
function persistToFbCache(contactData) {
function persistToFbCache(contactData, mUpdate) {
var isUpdate = (mUpdate === true ? mUpdate : false);

var outReq = new fb.utils.Request();

window.setTimeout(function persist_fb_do() {
Expand All @@ -173,7 +175,9 @@ fb.Contact = function(deviceContact, cid) {
// thus restoring the contact (if unlinked) will be trivial
copyNames(contactData, data);

var fbReq = fb.contacts.save(data);
var updaterFn = (isUpdate === true ?
fb.contacts.update : fb.contacts.save);
var fbReq = updaterFn(data);

fbReq.onsuccess = function() {
outReq.done(fbReq.result);
Expand All @@ -197,7 +201,7 @@ fb.Contact = function(deviceContact, cid) {
var dataReq = fb.contacts.get(contactData.uid);
dataReq.onsuccess = function() {
contactData.fbInfo.photo = dataReq.result.photo;
auxCachePersist(contactData, outReq);
auxCachePersist(contactData, outReq, true);
};
dataReq.onerror = function() {
window.console.error('Error while retrieving existing photo for ',
Expand All @@ -209,15 +213,15 @@ fb.Contact = function(deviceContact, cid) {
utils.squareImage(contactData.fbInfo.photo[0],
function sq_img(squaredImg) {
contactData.fbInfo.photo[0] = squaredImg;
auxCachePersist(contactData, outReq);
auxCachePersist(contactData, outReq, true);
}
);
}
}

// Persist the data to the FB Cache
function auxCachePersist(contactData, outReq) {
var fbReq = persistToFbCache(contactData);
function auxCachePersist(contactData, outReq, isUpdate) {
var fbReq = persistToFbCache(contactData, isUpdate);

fbReq.onsuccess = function() {
outReq.done(fbReq.result);
Expand Down Expand Up @@ -733,7 +737,9 @@ fb.Contact = function(deviceContact, cid) {
};
}

this.remove = function() {
this.remove = function(pforceFlush) {
var forceFlush = (pforceFlush === true) ? pforceFlush : false;

var out = new fb.utils.Request();

window.setTimeout(function do_remove() {
Expand All @@ -748,7 +754,7 @@ fb.Contact = function(deviceContact, cid) {
var theContact = new mozContact(devContact);
var removeReq = navigator.mozContacts.remove(theContact);
removeReq.onsuccess = function(e) {
var fbReq = fb.contacts.remove(uid);
var fbReq = fb.contacts.remove(uid, forceFlush);
fbReq.onsuccess = function() {
out.done(fbReq.result);
};
Expand Down
Loading

0 comments on commit 33156ce

Please sign in to comment.