From 9e4162618211830a94a0787f330c3df18a660fe3 Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Wed, 4 Dec 2013 17:13:45 +0100 Subject: [PATCH] mails in outbox are correctly displayed --- src/js/app-controller.js | 6 +++++- src/js/bo/outbox.js | 14 ++++++++++++-- test/new-unit/outbox-bo-test.js | 7 ++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/js/app-controller.js b/src/js/app-controller.js index 26395f7..39f0d5d 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -224,7 +224,11 @@ define(function(require) { self._emailDao.init({ account: account - }, callback); + }, function(err, keypair) { + self._outboxBo.init(); + callback(err, keypair); + }); + } }; diff --git a/src/js/bo/outbox.js b/src/js/bo/outbox.js index 22a697e..648986e 100644 --- a/src/js/bo/outbox.js +++ b/src/js/bo/outbox.js @@ -37,6 +37,13 @@ define(function(require) { this.pendingEmails = []; }; + OutboxBO.prototype.init = function() { + var outboxFolder = _.findWhere(this._emailDao._account.folders, { + type: 'Outbox' + }); + outboxFolder.messages = this.pendingEmails; + }; + /** * This function activates the periodic checking of the local device storage for pending mails. * @param {Function} callback(error, pendingMailsCount) Callback that informs you about the count of pending mails. @@ -89,8 +96,11 @@ define(function(require) { // update outbox folder count emails = pending; - // keep an independent shallow copy of the pending mails array in the member - self.pendingEmails = pending.slice(); + // fill all the pending mails into the pending mails array + self.pendingEmails.length = 0; //fastest way to empty an array + pending.forEach(function(i) { + self.pendingEmails.push(i); + }); // sending pending mails processMails(); diff --git a/test/new-unit/outbox-bo-test.js b/test/new-unit/outbox-bo-test.js index e7e3111..efcbce5 100644 --- a/test/new-unit/outbox-bo-test.js +++ b/test/new-unit/outbox-bo-test.js @@ -16,12 +16,16 @@ define(function(require) { beforeEach(function() { emailDaoStub = sinon.createStubInstance(EmailDAO); emailDaoStub._account = { - emailAddress: dummyUser + emailAddress: dummyUser, + folders: [{ + type: 'Outbox' + }] }; devicestorageStub = sinon.createStubInstance(DeviceStorageDAO); keychainStub = sinon.createStubInstance(KeychainDAO); invitationDaoStub = sinon.createStubInstance(InvitationDAO); outbox = new OutboxBO(emailDaoStub, keychainStub, devicestorageStub, invitationDaoStub); + outbox.init(); }); afterEach(function() {}); @@ -35,6 +39,7 @@ define(function(require) { expect(outbox._invitationDao).to.equal(invitationDaoStub); expect(outbox._outboxBusy).to.be.false; expect(outbox.pendingEmails).to.be.empty; + expect(emailDaoStub._account.folders[0].messages).to.equal(outbox.pendingEmails); }); });