1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 12:22:22 -05:00

review mail-list

This commit is contained in:
Tankred Hase 2014-02-20 15:42:51 +01:00
parent 6a8bb527fc
commit b093b069f6
4 changed files with 74 additions and 61 deletions

View File

@ -58,13 +58,13 @@ define(function(require) {
// scope functions // scope functions
// //
$scope.getContent = function(email) { $scope.getBody = function(email) {
// don't stream message content of outbox messages... // don't stream message content of outbox messages...
if (getFolder().type === 'Outbox') { if (getFolder().type === 'Outbox') {
return; return;
} }
emailDao.getMessageContent({ emailDao.getBody({
folder: getFolder().path, folder: getFolder().path,
message: email message: email
}, function(error) { }, function(error) {
@ -410,29 +410,36 @@ define(function(require) {
ngModule.directive('ngIscroll', function() { ngModule.directive('ngIscroll', function() {
return { return {
link: function(scope, elm, attrs) { link: function(scope, elm, attrs) {
var model = attrs.ngIscroll; var model = attrs.ngIscroll,
listEl = elm[0];
scope.$watch(model, function() { scope.$watch(model, function() {
var myScroll; var myScroll;
// activate iscroll // activate iscroll
myScroll = new IScroll(elm[0], { myScroll = new IScroll(listEl, {
mouseWheel: true, mouseWheel: true
}); });
// load the visible message bodies, when the list is re-initialized and when scrolling stopped // load the visible message bodies, when the list is re-initialized and when scrolling stopped
loadVisible(); loadVisible();
myScroll.on('scrollEnd', loadVisible); myScroll.on('scrollEnd', loadVisible);
}, true);
/*
* iterates over the mails in the mail list and loads their bodies if they are visible in the viewport
*/
function loadVisible() { function loadVisible() {
var list = elm[0].getBoundingClientRect(), var listBorder = listEl.getBoundingClientRect(),
footerHeight = elm[0].nextElementSibling.getBoundingClientRect().height, top = listBorder.top,
top = list.top, bottom = listBorder.bottom,
bottom = list.bottom - footerHeight, listItems = listEl.children[0].children,
listItems = elm[0].children[0].children,
i = listItems.length, i = listItems.length,
listItem, message, listItem, message,
isPartiallyVisibleTop, isPartiallyVisibleBottom, isVisible; isPartiallyVisibleTop, isPartiallyVisibleBottom, isVisible;
while (i--) { while (i--) {
// the n-th list item (the dom representation of an email) corresponds to
// the n-th message model in the filteredMessages array
listItem = listItems.item(i).getBoundingClientRect(); listItem = listItems.item(i).getBoundingClientRect();
message = scope.filteredMessages[i]; message = scope.filteredMessages[i];
@ -440,13 +447,11 @@ define(function(require) {
isPartiallyVisibleBottom = listItem.top < bottom && listItem.bottom > bottom; // a portion of the list item is visible on the bottom isPartiallyVisibleBottom = listItem.top < bottom && listItem.bottom > bottom; // a portion of the list item is visible on the bottom
isVisible = listItem.top >= top && listItem.bottom <= bottom; // the list item is visible as a whole isVisible = listItem.top >= top && listItem.bottom <= bottom; // the list item is visible as a whole
if (isPartiallyVisibleTop || isVisible || isPartiallyVisibleBottom) { if (isPartiallyVisibleTop || isVisible || isPartiallyVisibleBottom) {
scope.getContent(message); scope.getBody(message);
} }
} }
} }
}, true);
} }
}; };
}); });

View File

@ -737,7 +737,7 @@ define(function(require) {
* @param {Object} options.folder The IMAP folder * @param {Object} options.folder The IMAP folder
* @param {Function} callback(error, message) Invoked when the message is streamed, or provides information if an error occurred * @param {Function} callback(error, message) Invoked when the message is streamed, or provides information if an error occurred
*/ */
EmailDAO.prototype.getMessageContent = function(options, callback) { EmailDAO.prototype.getBody = function(options, callback) {
var self = this, var self = this,
message = options.message, message = options.message,
folder = options.folder; folder = options.folder;
@ -1179,7 +1179,7 @@ define(function(require) {
return; return;
} }
self._imapClient.streamPlaintext({ self._imapClient.getBody({
path: options.folder, path: options.folder,
message: options.message message: options.message
}, callback); }, callback);

View File

@ -821,7 +821,7 @@ define(function(require) {
it('should work', function(done) { it('should work', function(done) {
var path = 'FOLDAAAA'; var path = 'FOLDAAAA';
imapClientStub.streamPlaintext.withArgs({ imapClientStub.getBody.withArgs({
path: path, path: path,
message: {} message: {}
}).yields(null, {}); }).yields(null, {});
@ -833,16 +833,16 @@ define(function(require) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(msg).to.exist; expect(msg).to.exist;
expect(imapClientStub.streamPlaintext.calledOnce).to.be.true; expect(imapClientStub.getBody.calledOnce).to.be.true;
done(); done();
}); });
}); });
it('should not work when streamPlaintext fails', function(done) { it('should not work when getBody fails', function(done) {
var path = 'FOLDAAAA'; var path = 'FOLDAAAA';
imapClientStub.streamPlaintext.yields({}); imapClientStub.getBody.yields({});
dao._imapStreamText({ dao._imapStreamText({
folder: path, folder: path,
@ -851,7 +851,7 @@ define(function(require) {
expect(err).to.exist; expect(err).to.exist;
expect(msg).to.not.exist; expect(msg).to.not.exist;
expect(imapClientStub.streamPlaintext.calledOnce).to.be.true; expect(imapClientStub.getBody.calledOnce).to.be.true;
done(); done();
}); });
@ -928,13 +928,13 @@ define(function(require) {
}); });
}); });
describe('getMessageContent', function() { describe('getBody', function() {
it('should not do anything if the message already has content', function() { it('should not do anything if the message already has content', function() {
var message = { var message = {
body: 'bender is great!' body: 'bender is great!'
}; };
dao.getMessageContent({ dao.getBody({
message: message message: message
}); });
@ -959,7 +959,7 @@ define(function(require) {
}]); }]);
dao.getMessageContent({ dao.getBody({
message: message, message: message,
folder: folder folder: folder
}, function(err, msg) { }, function(err, msg) {
@ -995,7 +995,7 @@ define(function(require) {
}]); }]);
dao.getMessageContent({ dao.getBody({
message: message, message: message,
folder: folder folder: folder
}, function(err, msg) { }, function(err, msg) {
@ -1045,7 +1045,7 @@ define(function(require) {
}); });
dao.getMessageContent({ dao.getBody({
message: message, message: message,
folder: folder folder: folder
}, function(err, msg) { }, function(err, msg) {
@ -1096,7 +1096,7 @@ define(function(require) {
}); });
dao.getMessageContent({ dao.getBody({
message: message, message: message,
folder: folder folder: folder
}, function(err, msg) { }, function(err, msg) {
@ -1141,7 +1141,7 @@ define(function(require) {
emails: [message] emails: [message]
}).yields({}); }).yields({});
dao.getMessageContent({ dao.getBody({
message: message, message: message,
folder: folder folder: folder
}, function(err, msg) { }, function(err, msg) {
@ -1178,7 +1178,7 @@ define(function(require) {
localStoreStub = sinon.stub(dao, '_localStoreMessages'); localStoreStub = sinon.stub(dao, '_localStoreMessages');
dao.getMessageContent({ dao.getBody({
message: message, message: message,
folder: folder folder: folder
}, function(err, msg) { }, function(err, msg) {
@ -1225,7 +1225,9 @@ define(function(require) {
var message, parsedBody, mimeBody, parseStub; var message, parsedBody, mimeBody, parseStub;
message = { message = {
from: [{address: 'asdasdasd'}], from: [{
address: 'asdasdasd'
}],
encrypted: true, encrypted: true,
decrypted: false, decrypted: false,
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----' body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
@ -1268,7 +1270,9 @@ define(function(require) {
var message, plaintextBody, parseStub; var message, plaintextBody, parseStub;
message = { message = {
from: [{address: 'asdasdasd'}], from: [{
address: 'asdasdasd'
}],
encrypted: true, encrypted: true,
decrypted: false, decrypted: false,
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----' body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
@ -1303,7 +1307,9 @@ define(function(require) {
var message, plaintextBody, parseStub, errMsg; var message, plaintextBody, parseStub, errMsg;
message = { message = {
from: [{address: 'asdasdasd'}], from: [{
address: 'asdasdasd'
}],
encrypted: true, encrypted: true,
decrypted: false, decrypted: false,
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----' body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
@ -1340,7 +1346,9 @@ define(function(require) {
var message, parseStub; var message, parseStub;
message = { message = {
from: [{address: 'asdasdasd'}], from: [{
address: 'asdasdasd'
}],
encrypted: true, encrypted: true,
decrypted: false, decrypted: false,
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----' body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'

View File

@ -225,7 +225,7 @@ define(function(require) {
}); });
}); });
describe('getContent', function() { describe('getBody', function() {
it('should get the mail content', function() { it('should get the mail content', function() {
scope.state.nav = { scope.state.nav = {
currentFolder: { currentFolder: {
@ -233,8 +233,8 @@ define(function(require) {
} }
}; };
scope.getContent(); scope.getBody();
expect(emailDaoMock.getMessageContent.calledOnce).to.be.true; expect(emailDaoMock.getBody.calledOnce).to.be.true;
}); });
}); });