mirror of
https://github.com/moparisthebest/mail
synced 2025-02-16 15:10:10 -05:00
removed email collection usage in email dao
This commit is contained in:
parent
15008a23e9
commit
8f54f1c544
@ -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') {
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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();
|
||||
});
|
Loading…
Reference in New Issue
Block a user