Fix bug 699280 - Adapt to the calIChangeLog interface changes (wcap offline support). r=redDragon
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 02 Aug 2012 09:10:59 +0200
changeset 13185 7155880be5bb07b933ae6d451a097dc47635c371
parent 13184 7d005aa5bd49e3d59ed7640cddfe998110eb37d1
child 13186 8ba28b3daf3cbaebd36da7c0fef4faf8e9fa1f77
push idunknown
push userunknown
push dateunknown
reviewersredDragon
bugs699280
Fix bug 699280 - Adapt to the calIChangeLog interface changes (wcap offline support). r=redDragon
calendar/providers/wcap/calWcapCalendarItems.js
--- a/calendar/providers/wcap/calWcapCalendarItems.js
+++ b/calendar/providers/wcap/calWcapCalendarItems.js
@@ -578,20 +578,17 @@ function calWcapCalendar_storeItem(bAddI
         params += "&emailorcalid=1&fmt-out=text%2Fcalendar";
 
         function netRespFunc(err, icalRootComp) {
             if (err) {
                 throw err;
             }
             var items = this_.parseItems(icalRootComp, calICalendar.ITEM_FILTER_ALL_ITEMS,
                                          0, null, null, true /* bLeaveMutable */);
-            if (items.length < 1) {
-                throw new Components.Exception("empty VCALENDAR returned!");
-            }
-            if (items.length > 1) {
+            if (items.length != 1) {
                 this_.notifyError(NS_ERROR_UNEXPECTED,
                                   "unexpected number of items: " + items.length);
             }
             var newItem = items[0];
             this_.tunnelXProps(newItem, item);
             newItem.makeImmutable();
             // invalidate cached results:
             delete this_.m_cachedResults;
@@ -646,17 +643,17 @@ function calWcapCalendar_adoptItem(item,
     var this_ = this;
     var request = new calWcapRequest(
         function adoptItem_resp(request, err, newItem) {
             this_.notifyOperationComplete(listener,
                                           getResultCode(err),
                                           calIOperationListener.ADD,
                                           err ? item.id : newItem.id,
                                           err ? err : newItem);
-            if (!err) {
+            if (!err && this_ == this_.superCalendar) {
                 this_.notifyObservers("onAddItem", [newItem]);
             }
         },
         log("adoptItem() call: " + item.title, this));
 
     try {
         this.storeItem(true /* bAddItem */, item, null, request);
     } catch (exc) {
@@ -674,17 +671,17 @@ calWcapCalendar.prototype.modifyItem =
 function calWcapCalendar_modifyItem(newItem, oldItem, listener) {
     var this_ = this;
     var request = new calWcapRequest(
         function modifyItem_resp(request, err, item) {
             this_.notifyOperationComplete(listener,
                                           getResultCode(err),
                                           calIOperationListener.MODIFY,
                                           newItem.id, err ? err : item);
-            if (!err) {
+            if (!err && this_ == this_.superCalendar) {
                 this_.notifyObservers("onModifyItem", [item, oldItem]);
             }
         },
         log("modifyItem() call: " + newItem.id, this));
 
     try {
         if (!newItem.id) {
             throw new Components.Exception("new item has no id!");
@@ -757,17 +754,17 @@ function calWcapCalendar_deleteItem(item
     var this_ = this;
     var request = new calWcapRequest(
         function deleteItem_resp(request, err) {
             // xxx todo: need to notify about each deleted item if multiple?
             this_.notifyOperationComplete(listener,
                                           getResultCode(err),
                                           calIOperationListener.DELETE,
                                           item.id, err ? err : item);
-            if (!err) {
+            if (!err && this_ == this_.superCalendar) {
                 this_.notifyObservers("onDeleteItem", [item]);
             }
         },
         log("deleteItem() call: " + item.id, this));
 
     try {
         if (!item.id) {
             throw new Components.Exception("no item id!");
@@ -1310,40 +1307,42 @@ function calWcapCalendar_getItems(itemFi
             },
             stringToIcal, "fetchcomponents_by_range", params, calIWcapCalendar.AC_COMP_READ);
     } catch (exc) {
         request.execRespFunc(exc);
     }
     return request;
 };
 
+calWcapCalendar.prototype.offlineStorage = null;
+
 calWcapCalendar.prototype.resetLog =
 function calWcapCalendar_resetLog() {
     this.deleteProperty("replay.last_stamp");
 };
 
 calWcapCalendar.prototype.replayChangesOn =
-function calWcapCalendar_replayChangesOn(destCal, listener) {
+function calWcapCalendar_replayChangesOn(listener) {
     var this_ = this;
     var itemFilter = calICalendar.ITEM_FILTER_ALL_ITEMS;
     var dtFrom = getDatetimeFromIcalString(this.getProperty("replay.last_stamp"));
     var now = getTime(); // new stamp for this sync
 
     var request_ = new calWcapRequest(
         function replayChangesOn_resp(request, err) {
             if (err) {
                 logError("error replaying changes: " + errorToString(err));
                 this_.notifyError(err);
             } else {
                 log("replay succeeded.", this_);
                 this_.setProperty("replay.last_stamp", getIcalUTC(now));
                 log("new replay stamp: " + getIcalUTC(now), this_);
             }
-            if (opListener) {
-                opListener.onResult(request, null);
+            if (listener) {
+                listener.onResult(request, null);
             }
         },
         log("replayChangesOn():\n\titemFilter=0x" + itemFilter.toString(0x10) +
             "\n\tdtFrom=" + getIcalUTC(dtFrom), this));
 
     try {
         var writeListener = {
             onGetResult: function() {},
@@ -1357,42 +1356,42 @@ function calWcapCalendar_replayChangesOn
             function netFinishedRespFunc(err, data) {
                 var modifiedIds = {};
                 for each (var item in request.m_modifiedItems) {
                     var dtCreated = item.getProperty("CREATED");
                     var bAdd = (!dtCreated || !dtFrom || dtCreated.compare(dtFrom) >= 0);
                     modifiedIds[item.id] = true;
                     if (bAdd) {
                         log("replayChangesOn(): new item " + item.id, this_);
-                        if (destCal) {
-                            destCal.addItem(item, writeListener);
+                        if (this_.offlineStorage) {
+                            this_.offlineStorage.addItem(item, writeListener);
                         }
                     } else {
                         log("replayChangesOn(): modified item " + item.id, this_);
-                        if (destCal) {
-                            destCal.modifyItem(item, null, writeListener);
+                        if (this_.offlineStorage) {
+                            this_.modifyItem(item, null, writeListener);
                         }
                     }
                 }
                 for each (var item in request.m_deletedItems) {
                     // don't delete anything that has been touched by lastmods:
                     if (modifiedIds[item.id]) {
                         log("replayChangesOn(): skipping deletion of " + item.id, this_);
                     } else if (isParent(item)) {
                         log("replayChangesOn(): deleted item " + item.id, this_);
-                        if (destCal) {
-                            destCal.deleteItem(item, writeListener);
+                        if (this_.offlineStorage) {
+                            this_.offlineStorage.deleteItem(item, writeListener);
                         }
                     } else { // modify parent instead of
                              // straight-forward deleteItem(). WTF.
                         var parent = item.parentItem.clone();
                         parent.recurrenceInfo.removeOccurrenceAt(item.recurrenceId);
                         log("replayChangesOn(): modified parent "+ parent.id, this_);
-                        if (destCal) {
-                            destCal.modifyItem(parent, item, writeListener);
+                        if (this_.offlineStorage) {
+                            this_.offlineStorage.modifyItem(parent, item, writeListener);
                         }
                     }
                 }
             }, "replayChangesOn() netFinishedRespFunc");
         request_.attachSubRequest(request);
 
         // assure being logged in to calc server times:
         this.session.getSessionId(