diff --git a/src/js/app-controller.js b/src/js/app-controller.js index 8a4a3c1..fc65f2b 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -72,10 +72,10 @@ app.Controller = function() { } else if (cmd === 'listEmails') { // list emails from folder - emailDao.listItems(args.folder, args.offset, args.num, function(err, collection) { + emailDao.listItems(args.folder, args.offset, args.num, function(err, emails) { callback({ err: err, - collection: collection.toJSON() + emails: emails }); }); @@ -84,7 +84,7 @@ app.Controller = function() { var mail = emailDao.getItem(args.folder, args.messageId); callback({ err: null, - email: mail.toJSON() + email: mail }); } else if (cmd === 'sendEmail') { diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index e54a2dc..996a855 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -63,7 +63,7 @@ app.dao.EmailDAO = function(jsonDB, crypto, devicestorage, cloudstorage, util, k var folder = this.account.get('folders').where({ name: folderName })[0]; - var mail = _.find(folder.get('items').models, function(email) { + var mail = _.find(folder.get('items'), function(email) { return email.id + '' === itemId + ''; }); return mail; @@ -91,7 +91,7 @@ app.dao.EmailDAO = function(jsonDB, crypto, devicestorage, cloudstorage, util, k return; } if (encryptedList.length === 0) { - callback(null, new app.model.EmailCollection()); + callback(null, []); return; } @@ -122,19 +122,16 @@ app.dao.EmailDAO = function(jsonDB, crypto, devicestorage, cloudstorage, util, k return; } - // parse to backbone model collection - collection = new app.model.EmailCollection(decryptedList); - // cache collection in folder memory if (decryptedList.length > 0) { folder = new app.model.Folder({ name: folderName }); - folder.set('items', collection); + folder.set('items', decryptedList); self.account.get('folders').add(folder); } - callback(null, collection); + callback(null, decryptedList); }); }); diff --git a/src/js/view/messagelist-view.js b/src/js/view/messagelist-view.js index f04cb57..55a9525 100644 --- a/src/js/view/messagelist-view.js +++ b/src/js/view/messagelist-view.js @@ -72,7 +72,7 @@ num: 10 }, function(resArgs) { var err = resArgs.err; - var collection = resArgs.collection; + var emails = resArgs.emails; // check for error if (err) { @@ -85,8 +85,8 @@ list.html(''); // append items to list in reverse order so mails with the most recent date will be displayed first - for (i = collection.length - 1; i >= 0; i--) { - email = collection[i]; + for (i = emails.length - 1; i >= 0; i--) { + email = emails[i]; listItemArgs = { account: self.options.account, folder: self.folder, diff --git a/test/integration/cloudstorage-dao-test.js b/test/integration/cloudstorage-dao-test.js index b863751..45e584e 100644 --- a/test/integration/cloudstorage-dao-test.js +++ b/test/integration/cloudstorage-dao-test.js @@ -1,3 +1,5 @@ +'use strict'; + module("CloudStorage DAO"); var cloudstoragedao_test = { @@ -187,9 +189,9 @@ asyncTest("Sync emails from cloud", 1, function() { asyncTest("List emails from cloud", 2, function() { - cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, collection) { + cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, gotten) { ok(!err); - ok(collection.length > 0, 'Read synced items'); + ok(gotten.length > 0, 'Read synced items'); start(); }); diff --git a/test/unit/email-dao-test.js b/test/unit/email-dao-test.js index 067af45..dc1e00b 100644 --- a/test/unit/email-dao-test.js +++ b/test/unit/email-dao-test.js @@ -1,3 +1,5 @@ +'use strict'; + module("Email DAO"); var emaildao_test = { @@ -78,11 +80,10 @@ asyncTest("Persist test emails", 4, function() { }); asyncTest("List Email models", 2, function() { - emaildao_test.emailDao.listItems('inbox', 0, emaildao_test.list.length, function(err, collection) { + emaildao_test.emailDao.listItems('inbox', 0, emaildao_test.list.length, function(err, gotten) { ok(!err); - var gotten = collection.toJSON(), - reference = emaildao_test.list.toJSON(); + var reference = emaildao_test.list.toJSON(); deepEqual(gotten, reference, 'Compare collection'); @@ -93,6 +94,6 @@ asyncTest("List Email models", 2, function() { asyncTest("Get item", 1, function() { var item = emaildao_test.list.toJSON()[0]; var mail = emaildao_test.emailDao.getItem('inbox', item.id); - deepEqual(mail.toJSON(), item, 'Item correct'); + deepEqual(mail, item, 'Item correct'); start(); }); \ No newline at end of file