diff --git a/src/js/controller/mail-list.js b/src/js/controller/mail-list.js index 033cad4..af34d63 100644 --- a/src/js/controller/mail-list.js +++ b/src/js/controller/mail-list.js @@ -24,8 +24,6 @@ define(function(require) { $scope.synchronize(function() { // show notification notificationForEmail(email); - // get message body - $scope.getBody($scope.filteredMessages[0]); }); }; chrome.notifications.onClicked.addListener(notificationClicked); @@ -135,6 +133,9 @@ define(function(require) { updateStatus('Last update: ', new Date()); $scope.$apply(); + // fetch visible bodies at the end of a successful sync + $scope.loadVisibleBodies(); + if (callback) { callback(); } @@ -397,22 +398,10 @@ define(function(require) { var model = attrs.ngIscroll, listEl = elm[0]; - scope.$watch(model, function() { - var myScroll; - // activate iscroll - myScroll = new IScroll(listEl, { - mouseWheel: true - }); - - // load the visible message bodies, when the list is re-initialized and when scrolling stopped - 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() { + scope.loadVisibleBodies = function() { var listBorder = listEl.getBoundingClientRect(), top = listBorder.top, bottom = listBorder.bottom, @@ -435,7 +424,20 @@ define(function(require) { scope.getBody(message); } } - } + }; + + // re-init iScroll when model length changes + scope.$watch(model, function() { + var myScroll; + // activate iscroll + myScroll = new IScroll(listEl, { + mouseWheel: true + }); + + // load the visible message bodies, when the list is re-initialized and when scrolling stopped + scope.loadVisibleBodies(); + myScroll.on('scrollEnd', scope.loadVisibleBodies); + }, true); } }; }); diff --git a/test/new-unit/mail-list-ctrl-test.js b/test/new-unit/mail-list-ctrl-test.js index e5cf93e..04ba791 100644 --- a/test/new-unit/mail-list-ctrl-test.js +++ b/test/new-unit/mail-list-ctrl-test.js @@ -82,6 +82,8 @@ define(function(require) { toggle: function() {} } }; + + scope.loadVisibleBodies = function() {}; ctrl = $controller(MailListCtrl, { $scope: scope }); @@ -148,13 +150,9 @@ define(function(require) { expect(opts.type).to.equal('basic'); expect(opts.message).to.equal('asdasd'); expect(opts.title).to.equal('asd'); - }; - - scope.getBody = function() { done(); }; - scope.filteredMessages = [{}]; emailDaoMock.onIncomingMessage(mail); }); });