diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/app/services/models/feedmodel.coffee | 29 | ||||
-rw-r--r-- | js/public/app.js | 20 | ||||
-rw-r--r-- | js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee | 4 | ||||
-rw-r--r-- | js/tests/services/models/feedmodelSpec.coffee | 16 |
4 files changed, 45 insertions, 24 deletions
diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee index fb0ba8e14..f0296957e 100644 --- a/js/app/services/models/feedmodel.coffee +++ b/js/app/services/models/feedmodel.coffee @@ -62,24 +62,27 @@ angular.module('News').factory 'FeedModel', if updateById or updateByUrlHash @update(data, clearCache) else - # if the item is not yet in the name cache it must be added - @_urlHash[data.urlHash] = data - - # in case there is an id it can go through the normal add method - if angular.isDefined(data.id) - super(data, clearCache) - - # if there is no id we just want it to appear in the list - else - @_data.push(data) - if clearCache - @_invalidateCache() + if angular.isDefined(data.urlHash) + # if the item is not yet in the name cache it must be added + @_urlHash[data.urlHash] = data + + # in case there is an id it can go through the normal add method + if angular.isDefined(data.id) + super(data, clearCache) + + # if there is no id we just want it to appear in the list + else + @_data.push(data) + if clearCache + @_invalidateCache() update: (data, clearCache=true) -> # only when the id on the updated item does not exist we wish # to update by name, otherwise we always update by id - item = @_urlHash[data.urlHash] + if angular.isDefined(data.urlHash) + item = @_urlHash[data.urlHash] + # update by name if angular.isUndefined(data.id) and angular.isDefined(item) angular.extend(item, data) diff --git a/js/public/app.js b/js/public/app.js index 624c4575d..15504d914 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -1617,13 +1617,15 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. if (updateById || updateByUrlHash) { return this.update(data, clearCache); } else { - this._urlHash[data.urlHash] = data; - if (angular.isDefined(data.id)) { - return FeedModel.__super__.add.call(this, data, clearCache); - } else { - this._data.push(data); - if (clearCache) { - return this._invalidateCache(); + if (angular.isDefined(data.urlHash)) { + this._urlHash[data.urlHash] = data; + if (angular.isDefined(data.id)) { + return FeedModel.__super__.add.call(this, data, clearCache); + } else { + this._data.push(data); + if (clearCache) { + return this._invalidateCache(); + } } } } @@ -1635,7 +1637,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. if (clearCache == null) { clearCache = true; } - item = this._urlHash[data.urlHash]; + if (angular.isDefined(data.urlHash)) { + item = this._urlHash[data.urlHash]; + } if (angular.isUndefined(data.id) && angular.isDefined(item)) { return angular.extend(item, data); } else { diff --git a/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee b/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee index 8ab904c0a..48ae9e03c 100644 --- a/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee @@ -40,7 +40,7 @@ describe 'SubscriptionsBusinessLayer', -> it 'should be visible shows all items is set to true and there are feeds', => - @FeedModel.add({id: 3, unreadCount: 5}) + @FeedModel.add({id: 3, unreadCount: 5, urlHash: 'hi'}) expect(@SubscriptionsBusinessLayer.isVisible()).toBe(true) @@ -66,7 +66,7 @@ describe 'SubscriptionsBusinessLayer', -> it 'should mark all feeds as read', => - item = {id: 3, unreadCount: 132} + item = {id: 3, unreadCount: 132, urlHash: 'hi'} @FeedModel.add(item) @SubscriptionsBusinessLayer.markAllRead() diff --git a/js/tests/services/models/feedmodelSpec.coffee b/js/tests/services/models/feedmodelSpec.coffee index 6df9d6e9f..6b6eb85f6 100644 --- a/js/tests/services/models/feedmodelSpec.coffee +++ b/js/tests/services/models/feedmodelSpec.coffee @@ -120,4 +120,18 @@ describe 'FeedModel', -> item2 = {faviconLink: null, urlHash: 'his', test: 'heheh', folderId: 0} @FeedModel.add(item2) - expect(@FeedModel.getAllOfFolder(0).length).toBe(2)
\ No newline at end of file + expect(@FeedModel.getAllOfFolder(0).length).toBe(2) + + + it 'should only update feeds that contain only an id but no url hash', => + item = {id: 3, unreadCount: 232} + @FeedModel.add(item) + expect(@FeedModel.size()).toBe(0) + + item2 = {id: 3, unreadCount: 2, faviconLink: null, urlHash: 'his'} + @FeedModel.add(item2) + @FeedModel.add(item) + + expect(@FeedModel.size()).toBe(1) + expect(@FeedModel.getById(3).unreadCount).toBe(232) + |