diff options
Diffstat (limited to 'js/app')
-rw-r--r-- | js/app/controllers/feedcontroller.coffee | 4 | ||||
-rw-r--r-- | js/app/services/models/itemmodel.coffee | 38 |
2 files changed, 35 insertions, 7 deletions
diff --git a/js/app/controllers/feedcontroller.coffee b/js/app/controllers/feedcontroller.coffee index 1c04cd92e..14e1aea5b 100644 --- a/js/app/controllers/feedcontroller.coffee +++ b/js/app/controllers/feedcontroller.coffee @@ -179,7 +179,7 @@ angular.module('News').factory '_FeedController', -> @_persistence.getItems(type, id, 0) @_active.handle({id: id, type: type}) else - lastModified = @_itemModel.getLastModified() + lastModified = @_itemModel.getHighestId() @_persistence.getItems(type, id, 0, null, lastModified) @@ -208,6 +208,8 @@ angular.module('News').factory '_FeedController', -> feed = @_feedModel.getById(id) if angular.isDefined(feed) feed.unreadCount = 0 + # TODO: also update items in the right field if id is the + # the same highestItemId = @_itemModel.getHighestId() @_persistence.setFeedRead(id, highestItemId) when @_feedType.Folder diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee index 18af373d9..16250ecf7 100644 --- a/js/app/services/models/itemmodel.coffee +++ b/js/app/services/models/itemmodel.coffee @@ -27,14 +27,40 @@ angular.module('News').factory '_ItemModel', class ItemModel extends _Model - getLastModified: -> - query = new _MaximumQuery('lastModified') - lastModified = @get(query) + constructor: -> + @_guidFeedIdHash = {} + super() + + + clear: -> + @_guidFeedIdHash = {} + super() + + + # items have two unique fields: feed_id and guidhash + # in case we get updated items with the same two fields we + # also need to update the field + add: (data, clearCache=true) -> + hash = data.feedId + '_' + data.guidHash + entry = @_guidFeedIdHash[hash] + + # update entry if exists with same feedid and guidhash + if angular.isDefined(entry) + + # first update id that could have changed + delete @_dataMap[entry.id] + @_dataMap[data.id] = entry + + # now copy over the elements data attrs + for key, value of data + if key == 'feedId' or key == 'guidHash' + continue + else + entry[key] = value - if angular.isDefined(lastModified) - return lastModified.lastModified else - return null + @_guidFeedIdHash[hash] = data + super(data, clearCache) getHighestId: -> |