1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-23 09:22:23 -05:00

add documentation

This commit is contained in:
Felix Hammerl 2014-02-25 20:47:59 +01:00
parent 7385af2056
commit 844a743d81

View File

@ -199,9 +199,21 @@ define(function(require) {
} }
}; };
/**
* Syncs outbox content from disk to memory, not vice-versa
*/
EmailDAO.prototype.syncOutbox = function(options, callback) { EmailDAO.prototype.syncOutbox = function(options, callback) {
var self = this; var self = this;
// check busy status
if (self._account.busy) {
callback({
errMsg: 'Sync aborted: Previous sync still in progress',
code: 409
});
return;
}
// make sure two syncs for the same folder don't interfere // make sure two syncs for the same folder don't interfere
self._account.busy = true; self._account.busy = true;
@ -220,30 +232,37 @@ define(function(require) {
return; return;
} }
// calculate the diffs between memory and disk
var storedIds = _.pluck(storedMessages, 'id'), var storedIds = _.pluck(storedMessages, 'id'),
inMemoryIds = _.pluck(folder.messages, 'id'), inMemoryIds = _.pluck(folder.messages, 'id'),
newIds = _.difference(storedIds, inMemoryIds), newIds = _.difference(storedIds, inMemoryIds),
removedIds = _.difference(inMemoryIds, storedIds); removedIds = _.difference(inMemoryIds, storedIds);
// which messages are new on the disk that are not yet in memory?
var newMessages = _.filter(storedMessages, function(msg) { var newMessages = _.filter(storedMessages, function(msg) {
return _.contains(newIds, msg.id); return _.contains(newIds, msg.id);
}); });
// which messages are no longer on disk, i.e. have been sent
var removedMessages = _.filter(folder.messages, function(msg) { var removedMessages = _.filter(folder.messages, function(msg) {
return _.contains(removedIds, msg.id); return _.contains(removedIds, msg.id);
}); });
// add the new messages to memory
newMessages.forEach(function(newMessage) { newMessages.forEach(function(newMessage) {
folder.messages.push(newMessage); folder.messages.push(newMessage);
}); });
// remove the sent messages from memory
removedMessages.forEach(function(removedMessage) { removedMessages.forEach(function(removedMessage) {
var index = folder.messages.indexOf(removedMessage); var index = folder.messages.indexOf(removedMessage);
folder.messages.splice(index, 1); folder.messages.splice(index, 1);
}); });
// update the folder count and we're done.
folder.count = folder.messages.length; folder.count = folder.messages.length;
self._account.busy = false; self._account.busy = false;
callback(); callback();
}); });
}; };