summaryrefslogtreecommitdiffstats
path: root/js/app/services/models
diff options
context:
space:
mode:
Diffstat (limited to 'js/app/services/models')
-rw-r--r--js/app/services/models/feedmodel.coffee42
-rw-r--r--js/app/services/models/itemmodel.coffee43
2 files changed, 60 insertions, 25 deletions
diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee
index 4a186e659..96f187e75 100644
--- a/js/app/services/models/feedmodel.coffee
+++ b/js/app/services/models/feedmodel.coffee
@@ -37,7 +37,7 @@ angular.module('News').factory '_FeedModel',
super()
- add: (item) ->
+ add: (item, clearCache=true) ->
if item.faviconLink == null
item.faviconLink = 'url(' +
@_utils.imagePath('news', 'rss.svg') + ')'
@@ -46,20 +46,36 @@ angular.module('News').factory '_FeedModel',
# 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
-
+ @update(item, clearCache)
else
@_urlHash[item.urlHash] = item
- super(item)
+ super(item, clearCache)
+
+
+ update: (item, clearCache=true) ->
+ entry = @_urlHash[item.urlHash]
+
+ # 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
+
+
+
+ removeById: (id) ->
+ item = @getById(id)
+ delete @_urlHash[item.urlHash]
+ super(id)
+
+
+ getByUrlHash: (urlHash) ->
+ return @_urlHash[urlHash]
getUnreadCount: ->
diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee
index 3101c52f1..09c187443 100644
--- a/js/app/services/models/itemmodel.coffee
+++ b/js/app/services/models/itemmodel.coffee
@@ -46,23 +46,42 @@ angular.module('News').factory '_ItemModel',
# 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
-
+ @update(data, clearCache)
else
@_guidFeedIdHash[hash] = data
super(data, clearCache)
+ update: (data, clearCache=true) ->
+ hash = data.feedId + '_' + data.guidHash
+ entry = @_guidFeedIdHash[hash]
+
+ # 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
+
+ super(entry, clearCache)
+
+
+ getByGuidHashAndFeedId: (guidHash, feedId) ->
+ hash = feedId + '_' + guidHash
+ return @_guidFeedIdHash[hash]
+
+
+ removeById: (id) ->
+ item = @getById(id)
+ hash = item.feedId + '_' + item.guidHash
+ delete @_guidFeedIdHash[hash]
+ super(id)
+
+
getHighestId: ->
query = new _MaximumQuery('id')
highestId = @get(query)