Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 819628 #10981

Merged
merged 1 commit into from
Aug 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 44 additions & 45 deletions apps/calendar/js/provider/caldav.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ Calendar.ns('Provider').Caldav = (function() {
calendar: calendar
});

pull.on('complete', function() {
var trans = pull.calendarStore.db.transaction(
['calendars', 'events', 'busytimes', 'alarms', 'icalComponents'],
'readwrite'
);

calendar.error = undefined;

calendar.lastEventSyncToken = calendar.remote.syncToken;
calendar.lastEventSyncDate = syncStart;

calendarStore.persist(calendar, trans);
callback();

});
var calendarStore = this.app.store('Calendar');
var syncStart = new Date();

Expand All @@ -283,26 +298,6 @@ Calendar.ns('Provider').Caldav = (function() {
})
);
}

var trans = pull.commit(function(commitErr) {
if (commitErr) {
callback(err);
return;
}
callback(null);
});

/**
* Successfully synchronizing a calendar indicates we can remove this
* error.
*/
calendar.error = undefined;

calendar.lastEventSyncToken = calendar.remote.syncToken;
calendar.lastEventSyncDate = syncStart;

calendarStore.persist(calendar, trans);

});

return pull;
Expand Down Expand Up @@ -414,30 +409,34 @@ Calendar.ns('Provider').Caldav = (function() {
groups[calendarId].push(comp);
});

var pullGroups = [];
var streamAndPullGroup = [];
var pending = 0;
var options = {
maxDate: Calendar.Calc.dateToTransport(maxDate)
};

function next(err, pull) {
pullGroups.push(pull);
function next(err, streamAndPull) {
streamAndPullGroup.push(streamAndPull);
if (!(--pending)) {
var trans = self.app.db.transaction(
['icalComponents', 'alarms', 'busytimes'],
'readwrite'
);

trans.oncomplete = function() {
callback(null, true);
};

trans.onerror = function(event) {
callback(event.result.error.name);
};

pullGroups.forEach(function(pull) {
pull.commit(trans);
var pullCompleteCounter = 0;

/**
* Request stream data and wait for complete of all pulls
* and streams of streamAndPullGroup. When all pulls are
* complete, fire callback.
*/
streamAndPullGroup.forEach(function(streamPull) {
streamPull.pull.on('complete', function() {
pullCompleteCounter++;
if (pullCompleteCounter === streamAndPullGroup.length) {
callback(null, true);
}
});
streamPull.stream.request(function(err) {
if (err) {
callback(err);
}
});
});
}
}
Expand Down Expand Up @@ -484,13 +483,13 @@ Calendar.ns('Provider').Caldav = (function() {
]
}
);

stream.request(function(err) {
if (err) {
callback(err);
return;
}
callback(null, pull);
// We pass back the stream and its associated caldavpullevent,
// because we want to stream and commit events only when all
// calendar account combinations have had corresponding pull
// and stream objects created.
callback(null, {
stream: stream,
pull: pull
});

}.bind(this));
Expand Down
Loading