summaryrefslogtreecommitdiffstats
path: root/js/app/services/models
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-27 12:49:18 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-27 12:49:18 +0100
commit03e4ec51b3444be4f0bdc324370c3416aa7d64c0 (patch)
treef1302e55560de06c0d4990745ff5dfef96365d1e /js/app/services/models
parent02ae36eba33a5e0957defd4619d337bfdd0c178f (diff)
also update feedmodel if urlhash is the same
Diffstat (limited to 'js/app/services/models')
-rw-r--r--js/app/services/models/feedmodel.coffee26
-rw-r--r--js/app/services/models/itemmodel.coffee2
2 files changed, 26 insertions, 2 deletions
diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee
index 046ac7ec2..4a186e659 100644
--- a/js/app/services/models/feedmodel.coffee
+++ b/js/app/services/models/feedmodel.coffee
@@ -28,6 +28,12 @@ angular.module('News').factory '_FeedModel',
class FeedModel extends _Model
constructor: (@_utils) ->
+ @_urlHash = {}
+ super()
+
+
+ clear: ->
+ @_urlHash = {}
super()
@@ -35,7 +41,25 @@ angular.module('News').factory '_FeedModel',
if item.faviconLink == null
item.faviconLink = 'url(' +
@_utils.imagePath('news', 'rss.svg') + ')'
- super(item)
+
+ # since the feedurl is also unique, we want to update items that have
+ # the same url
+ entry = @_urlHash[item.urlHash]
+ if angular.isDefined(entry)
+ # first update id that could have changed
+ delete @_dataMap[entry.id]
+ @_dataMap[item.id] = entry
+
+ # now copy over the elements data attrs
+ for key, value of item
+ if key == 'urlHash'
+ continue
+ else
+ entry[key] = value
+
+ else
+ @_urlHash[item.urlHash] = item
+ super(item)
getUnreadCount: ->
diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee
index 16250ecf7..3101c52f1 100644
--- a/js/app/services/models/itemmodel.coffee
+++ b/js/app/services/models/itemmodel.coffee
@@ -38,7 +38,7 @@ angular.module('News').factory '_ItemModel',
# items have two unique fields: feed_id and guidhash
- # in case we get updated items with the same two fields we
+ # 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