summaryrefslogtreecommitdiffstats
path: root/js/app/services/models
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-27 12:26:04 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-27 12:26:04 +0100
commit02ae36eba33a5e0957defd4619d337bfdd0c178f (patch)
treed80f58cdf9eb774d00fc5fc322bf0750b644dab2 /js/app/services/models
parent89a1713f062cc78b727c6240a91408d91611dbab (diff)
fixed mark all unread serverside (was missing highestitemid, dont use lastmodified to compare for new versions but use the highest item id. if items are updated and the guidHash and feedId are the same then it will be deleted and newly inserted to make the lastmodified feasable
Diffstat (limited to 'js/app/services/models')
-rw-r--r--js/app/services/models/itemmodel.coffee38
1 files changed, 32 insertions, 6 deletions
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: ->