1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 19:02:20 -05:00

add outboxBusy flag

This commit is contained in:
Felix Hammerl 2013-10-24 17:37:16 +02:00
parent 2a201e52e6
commit 4ad8ccbc45

View File

@ -5,7 +5,8 @@ define(function(require) {
appController = require('js/app-controller'), appController = require('js/app-controller'),
_ = require('underscore'), _ = require('underscore'),
config = require('js/app-config').config, config = require('js/app-config').config,
emailDao, senderIntervalId; emailDao, senderIntervalId,
outboxBusy = false;
// //
// Controller // Controller
@ -101,10 +102,17 @@ define(function(require) {
checkStorage(); checkStorage();
function checkStorage() { function checkStorage() {
if (outboxBusy) {
return;
}
outboxBusy = true;
// get last item from outbox // get last item from outbox
emailDao._devicestorage.listItems(dbType, 0, null, function(err, pending) { emailDao._devicestorage.listItems(dbType, 0, null, function(err, pending) {
if (err) { if (err) {
console.error(err); console.error(err);
outboxBusy = false;
return; return;
} }
@ -119,6 +127,7 @@ define(function(require) {
function send(emails) { function send(emails) {
if (emails.length === 0) { if (emails.length === 0) {
outboxBusy = false;
return; return;
} }
@ -126,6 +135,7 @@ define(function(require) {
emailDao.smtpSend(email, function(err) { emailDao.smtpSend(email, function(err) {
if (err) { if (err) {
console.error(err); console.error(err);
outboxBusy = false;
return; return;
} }
@ -137,6 +147,7 @@ define(function(require) {
function removeFromStorage(id) { function removeFromStorage(id) {
if (!id) { if (!id) {
console.error('Cannot remove email from storage without a valid id!'); console.error('Cannot remove email from storage without a valid id!');
outboxBusy = false;
return; return;
} }
@ -145,11 +156,13 @@ define(function(require) {
emailDao._devicestorage.removeList(key, function(err) { emailDao._devicestorage.removeList(key, function(err) {
if (err) { if (err) {
console.error(err); console.error(err);
outboxBusy = false;
return; return;
} }
outbox.count = (outbox.count > 0) ? outbox.count - 1 : outbox.count; outbox.count = (outbox.count > 0) ? outbox.count - 1 : outbox.count;
$scope.$apply(); $scope.$apply();
outboxBusy = false;
}); });
} }
}; };