diff options
-rw-r--r-- | js/app/services/bl/itembl.coffee | 8 | ||||
-rw-r--r-- | js/public/app.js | 16 | ||||
-rw-r--r-- | js/tests/services/bl/itemblSpec.coffee | 31 |
3 files changed, 47 insertions, 8 deletions
diff --git a/js/app/services/bl/itembl.coffee b/js/app/services/bl/itembl.coffee index fb9f04623..eb50b8d55 100644 --- a/js/app/services/bl/itembl.coffee +++ b/js/app/services/bl/itembl.coffee @@ -73,6 +73,10 @@ angular.module('News').factory 'ItemBl', item.setRead() @_persistence.readItem(itemId) + feed = @_feedModel.getById(item.feedId) + if angular.isDefined(feed) + feed.unreadCount -= 1 + setUnread: (itemId) -> item = @_itemModel.getById(itemId) @@ -80,6 +84,10 @@ angular.module('News').factory 'ItemBl', item.setUnread() @_persistence.unreadItem(itemId) + feed = @_feedModel.getById(item.feedId) + if angular.isDefined(feed) + feed.unreadCount += 1 + getFeedTitle: (itemId) -> item = @_itemModel.getById(itemId) diff --git a/js/public/app.js b/js/public/app.js index 9c340462f..a70e513a4 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -863,20 +863,28 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. }; ItemBl.prototype.setRead = function(itemId) { - var item; + var feed, item; item = this._itemModel.getById(itemId); if (angular.isDefined(item)) { item.setRead(); - return this._persistence.readItem(itemId); + this._persistence.readItem(itemId); + feed = this._feedModel.getById(item.feedId); + if (angular.isDefined(feed)) { + return feed.unreadCount -= 1; + } } }; ItemBl.prototype.setUnread = function(itemId) { - var item; + var feed, item; item = this._itemModel.getById(itemId); if (angular.isDefined(item)) { item.setUnread(); - return this._persistence.unreadItem(itemId); + this._persistence.unreadItem(itemId); + feed = this._feedModel.getById(item.feedId); + if (angular.isDefined(feed)) { + return feed.unreadCount += 1; + } } }; diff --git a/js/tests/services/bl/itemblSpec.coffee b/js/tests/services/bl/itemblSpec.coffee index 01b02bfb2..cbaef5488 100644 --- a/js/tests/services/bl/itemblSpec.coffee +++ b/js/tests/services/bl/itemblSpec.coffee @@ -32,6 +32,8 @@ describe 'ItemBl', -> beforeEach inject (@ItemModel, @ItemBl, @StatusFlag, @ActiveFeed @FeedType, @FeedModel, @StarredBl) => + @item1 = {id: 5, title: 'hi', unreadCount:134, urlHash: 'a3', folderId: 3} + @FeedModel.add(@item1) it 'should return all items', => @@ -68,9 +70,6 @@ describe 'ItemBl', -> it 'should return the correct feed title', => - item1 = {id: 5, title: 'hi', unreadCount:134, urlHash: 'a3', folderId: 3} - @FeedModel.add(item1) - item2 = {id: 2, feedId: 5, guidHash: 'a3'} @ItemModel.add(item2) @@ -131,7 +130,7 @@ describe 'ItemBl', -> it 'should toggle an item as kept unread', => @persistence.unreadItem = jasmine.createSpy('unread item') - + item = {id: 2, feedId: 5, guidHash: 'a3', status: 0} @ItemModel.add(item) @@ -168,3 +167,27 @@ describe 'ItemBl', -> expect(item.isRead()).toBe(false) expect(@persistence.unreadItem).toHaveBeenCalledWith(2) + + + it 'should lower the unread count of a feed when its items get read', => + @persistence.readItem = jasmine.createSpy('read item') + + item = {id: 2, feedId: 5, guidHash: 'a3', status: 0} + @ItemModel.add(item) + item.setUnread() + + @ItemBl.setRead(2) + + expect(@item1.unreadCount).toBe(133) + + + it 'should increase the unread count of a feed when its items get unread', => + @persistence.unreadItem = jasmine.createSpy('unread item') + + item = {id: 2, feedId: 5, guidHash: 'a3', status: 0} + @ItemModel.add(item) + item.setRead() + + @ItemBl.setUnread(2) + + expect(@item1.unreadCount).toBe(135)
\ No newline at end of file |