removed email collection usage in email dao

This commit is contained in:
Tankred Hase 2013-06-06 19:19:37 +02:00
parent 15008a23e9
commit 8f54f1c544
5 changed files with 19 additions and 19 deletions

View File

@ -72,10 +72,10 @@ app.Controller = function() {
} else if (cmd === 'listEmails') { } else if (cmd === 'listEmails') {
// list emails from folder // 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({ callback({
err: err, err: err,
collection: collection.toJSON() emails: emails
}); });
}); });
@ -84,7 +84,7 @@ app.Controller = function() {
var mail = emailDao.getItem(args.folder, args.messageId); var mail = emailDao.getItem(args.folder, args.messageId);
callback({ callback({
err: null, err: null,
email: mail.toJSON() email: mail
}); });
} else if (cmd === 'sendEmail') { } else if (cmd === 'sendEmail') {

View File

@ -63,7 +63,7 @@ app.dao.EmailDAO = function(jsonDB, crypto, devicestorage, cloudstorage, util, k
var folder = this.account.get('folders').where({ var folder = this.account.get('folders').where({
name: folderName name: folderName
})[0]; })[0];
var mail = _.find(folder.get('items').models, function(email) { var mail = _.find(folder.get('items'), function(email) {
return email.id + '' === itemId + ''; return email.id + '' === itemId + '';
}); });
return mail; return mail;
@ -91,7 +91,7 @@ app.dao.EmailDAO = function(jsonDB, crypto, devicestorage, cloudstorage, util, k
return; return;
} }
if (encryptedList.length === 0) { if (encryptedList.length === 0) {
callback(null, new app.model.EmailCollection()); callback(null, []);
return; return;
} }
@ -122,19 +122,16 @@ app.dao.EmailDAO = function(jsonDB, crypto, devicestorage, cloudstorage, util, k
return; return;
} }
// parse to backbone model collection
collection = new app.model.EmailCollection(decryptedList);
// cache collection in folder memory // cache collection in folder memory
if (decryptedList.length > 0) { if (decryptedList.length > 0) {
folder = new app.model.Folder({ folder = new app.model.Folder({
name: folderName name: folderName
}); });
folder.set('items', collection); folder.set('items', decryptedList);
self.account.get('folders').add(folder); self.account.get('folders').add(folder);
} }
callback(null, collection); callback(null, decryptedList);
}); });
}); });

View File

@ -72,7 +72,7 @@
num: 10 num: 10
}, function(resArgs) { }, function(resArgs) {
var err = resArgs.err; var err = resArgs.err;
var collection = resArgs.collection; var emails = resArgs.emails;
// check for error // check for error
if (err) { if (err) {
@ -85,8 +85,8 @@
list.html(''); list.html('');
// append items to list in reverse order so mails with the most recent date will be displayed first // 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--) { for (i = emails.length - 1; i >= 0; i--) {
email = collection[i]; email = emails[i];
listItemArgs = { listItemArgs = {
account: self.options.account, account: self.options.account,
folder: self.folder, folder: self.folder,

View File

@ -1,3 +1,5 @@
'use strict';
module("CloudStorage DAO"); module("CloudStorage DAO");
var cloudstoragedao_test = { var cloudstoragedao_test = {
@ -187,9 +189,9 @@ asyncTest("Sync emails from cloud", 1, function() {
asyncTest("List emails from cloud", 2, 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(!err);
ok(collection.length > 0, 'Read synced items'); ok(gotten.length > 0, 'Read synced items');
start(); start();
}); });

View File

@ -1,3 +1,5 @@
'use strict';
module("Email DAO"); module("Email DAO");
var emaildao_test = { var emaildao_test = {
@ -78,11 +80,10 @@ asyncTest("Persist test emails", 4, function() {
}); });
asyncTest("List Email models", 2, 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); ok(!err);
var gotten = collection.toJSON(), var reference = emaildao_test.list.toJSON();
reference = emaildao_test.list.toJSON();
deepEqual(gotten, reference, 'Compare collection'); deepEqual(gotten, reference, 'Compare collection');
@ -93,6 +94,6 @@ asyncTest("List Email models", 2, function() {
asyncTest("Get item", 1, function() { asyncTest("Get item", 1, function() {
var item = emaildao_test.list.toJSON()[0]; var item = emaildao_test.list.toJSON()[0];
var mail = emaildao_test.emailDao.getItem('inbox', item.id); var mail = emaildao_test.emailDao.getItem('inbox', item.id);
deepEqual(mail.toJSON(), item, 'Item correct'); deepEqual(mail, item, 'Item correct');
start(); start();
}); });