summaryrefslogtreecommitdiffstats
path: root/js
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
parent02ae36eba33a5e0957defd4619d337bfdd0c178f (diff)
also update feedmodel if urlhash is the same
Diffstat (limited to 'js')
-rw-r--r--js/app/services/models/feedmodel.coffee26
-rw-r--r--js/app/services/models/itemmodel.coffee2
-rw-r--r--js/public/app.js26
-rw-r--r--js/tests/controllers/feedcontrollerSpec.coffee50
-rw-r--r--js/tests/services/models/feedmodelSpec.coffee18
5 files changed, 94 insertions, 28 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
diff --git a/js/public/app.js b/js/public/app.js
index d2ff687ae..e5b6e3cab 100644
--- a/js/public/app.js
+++ b/js/public/app.js
@@ -681,14 +681,38 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
function FeedModel(_utils) {
this._utils = _utils;
+ this._urlHash = {};
FeedModel.__super__.constructor.call(this);
}
+ FeedModel.prototype.clear = function() {
+ this._urlHash = {};
+ return FeedModel.__super__.clear.call(this);
+ };
+
FeedModel.prototype.add = function(item) {
+ var entry, key, value, _results;
if (item.faviconLink === null) {
item.faviconLink = 'url(' + this._utils.imagePath('news', 'rss.svg') + ')';
}
- return FeedModel.__super__.add.call(this, item);
+ entry = this._urlHash[item.urlHash];
+ if (angular.isDefined(entry)) {
+ delete this._dataMap[entry.id];
+ this._dataMap[item.id] = entry;
+ _results = [];
+ for (key in item) {
+ value = item[key];
+ if (key === 'urlHash') {
+ continue;
+ } else {
+ _results.push(entry[key] = value);
+ }
+ }
+ return _results;
+ } else {
+ this._urlHash[item.urlHash] = item;
+ return FeedModel.__super__.add.call(this, item);
+ }
};
FeedModel.prototype.getUnreadCount = function() {
diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee
index 6ec75e920..71c76d57e 100644
--- a/js/tests/controllers/feedcontrollerSpec.coffee
+++ b/js/tests/controllers/feedcontrollerSpec.coffee
@@ -108,25 +108,25 @@ describe '_FeedController', ->
it 'should get the correct unread count for feeds', =>
- @FeedModel.add({id: 3, unreadCount:134})
+ @FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'})
count = @scope.getUnreadCount(@FeedType.Feed, 3)
expect(count).toBe(134)
it 'should get the correct unread count for subscribtions', =>
- @FeedModel.add({id: 3, unreadCount:134})
- @FeedModel.add({id: 5, unreadCount:2})
+ @FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'})
+ @FeedModel.add({id: 5, unreadCount:2, urlHash: 'a2'})
count = @scope.getUnreadCount(@FeedType.Subscriptions, 0)
expect(count).toBe(136)
it 'should get the correct unread count for folders', =>
- @FeedModel.add({id: 3, unreadCount:134, folderId: 3})
- @FeedModel.add({id: 5, unreadCount:2, folderId: 2})
- @FeedModel.add({id: 1, unreadCount:12, folderId: 5})
- @FeedModel.add({id: 2, unreadCount:35, folderId: 3})
+ @FeedModel.add({id: 3, unreadCount:134, folderId: 3, urlHash: 'a1'})
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a2'})
+ @FeedModel.add({id: 1, unreadCount:12, folderId: 5, urlHash: 'a3'})
+ @FeedModel.add({id: 2, unreadCount:35, folderId: 3, urlHash: 'a4'})
count = @scope.getUnreadCount(@FeedType.Folder, 3)
expect(count).toBe(169)
@@ -182,18 +182,18 @@ describe '_FeedController', ->
it 'should return true if ShowAll is false but unreadcount is not 0', =>
@ShowAll.setShowAll(false)
- @FeedModel.add({id: 4, unreadCount: 0})
+ @FeedModel.add({id: 4, unreadCount: 0, urlHash: 'a1'})
expect(@scope.isShown(@FeedType.Feed, 4)).toBeFalsy()
- @FeedModel.add({id: 4, unreadCount: 12})
+ @FeedModel.add({id: 4, unreadCount: 12, urlHash: 'a2'})
expect(@scope.isShown(@FeedType.Feed, 4)).toBeTruthy()
it 'should return all feeds of a folder', =>
- @FeedModel.add({id: 3, unreadCount:134, folderId: 3})
- @FeedModel.add({id: 5, unreadCount:2, folderId: 2})
- @FeedModel.add({id: 1, unreadCount:12, folderId: 5})
- @FeedModel.add({id: 2, unreadCount:35, folderId: 3})
+ @FeedModel.add({id: 3, unreadCount:134, folderId: 3, urlHash: 'a1'})
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a2'})
+ @FeedModel.add({id: 1, unreadCount:12, folderId: 5, urlHash: 'a3'})
+ @FeedModel.add({id: 2, unreadCount:35, folderId: 3, urlHash: 'a4'})
result = @scope.getFeedsOfFolder(3)
@@ -204,10 +204,10 @@ describe '_FeedController', ->
it 'should return true when folder has feeds', =>
- @FeedModel.add({id: 5, unreadCount:2, folderId: 2})
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'})
expect(@scope.hasFeeds(3)).toBeFalsy()
- @FeedModel.add({id: 2, unreadCount:35, folderId: 3})
+ @FeedModel.add({id: 2, unreadCount:35, folderId: 3, urlHash: 'a2'})
expect(@scope.hasFeeds(3)).toBeTruthy()
@@ -231,10 +231,10 @@ describe '_FeedController', ->
it 'should mark feed as read', =>
@persistence.setFeedRead = jasmine.createSpy('setFeedRead')
- @FeedModel.add({id: 5, unreadCount:2, folderId: 2})
- @ItemModel.add({id: 6, feedId: 5, guidHash: 'a'})
- @ItemModel.add({id: 3, feedId: 5, guidHash: 'a1'})
- @ItemModel.add({id: 2, feedId: 5, guidHash: 'a2'})
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'})
+ @ItemModel.add({id: 6, feedId: 5, guidHash: 'a1'})
+ @ItemModel.add({id: 3, feedId: 5, guidHash: 'a2'})
+ @ItemModel.add({id: 2, feedId: 5, guidHash: 'a3'})
@scope.markAllRead(@FeedType.Feed, 5)
expect(@persistence.setFeedRead).toHaveBeenCalledWith(5, 6)
@@ -243,9 +243,9 @@ describe '_FeedController', ->
it 'should mark folder as read', =>
@persistence.setFeedRead = jasmine.createSpy('setFeedRead')
- @FeedModel.add({id: 3, unreadCount:134, folderId: 3})
- @FeedModel.add({id: 5, unreadCount:2, folderId: 2})
- @FeedModel.add({id: 1, unreadCount:12, folderId: 3})
+ @FeedModel.add({id: 3, unreadCount:134, folderId: 3, urlHash: 'a1'})
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a2'})
+ @FeedModel.add({id: 1, unreadCount:12, folderId: 3, urlHash: 'a3'})
@scope.markAllRead(@FeedType.Folder, 3)
@@ -256,9 +256,9 @@ describe '_FeedController', ->
it 'should mark all as read', =>
@persistence.setFeedRead = jasmine.createSpy('setFeedRead')
- @FeedModel.add({id: 3, unreadCount:134, folderId: 3})
- @FeedModel.add({id: 5, unreadCount:2, folderId: 2})
- @FeedModel.add({id: 1, unreadCount:12, folderId: 3})
+ @FeedModel.add({id: 3, unreadCount:134, folderId: 3, urlHash: 'a1'})
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a2'})
+ @FeedModel.add({id: 1, unreadCount:12, folderId: 3, urlHash: 'a3'})
@scope.markAllRead(@FeedType.Subscriptions, 0)
diff --git a/js/tests/services/models/feedmodelSpec.coffee b/js/tests/services/models/feedmodelSpec.coffee
index caddb35c0..2ae72eec2 100644
--- a/js/tests/services/models/feedmodelSpec.coffee
+++ b/js/tests/services/models/feedmodelSpec.coffee
@@ -37,6 +37,7 @@ describe '_FeedModel', ->
item =
id: 3
faviconLink: null
+ urlHash: 'hi'
utils =
imagePath: jasmine.createSpy('utils')
@@ -45,3 +46,20 @@ describe '_FeedModel', ->
expect(utils.imagePath).toHaveBeenCalledWith('news', 'rss.svg')
+
+ it 'should also update items when url is the same', =>
+ utils =
+ imagePath: jasmine.createSpy('utils')
+ model = new @_FeedModel(utils)
+
+ model.add({id: 2, faviconLink: null, urlHash: 'hi'})
+ expect(model.size()).toBe(1)
+
+ model.add({id: 2, faviconLink: null, urlHash: 'hi4'})
+ expect(model.size()).toBe(1)
+ expect(model.getById(2).urlHash).toBe('hi4')
+
+ model.add({id: 3, faviconLink: 'hey', urlHash: 'hi4'})
+ expect(model.size()).toBe(1)
+ expect(model.getById(2)).toBe(undefined)
+ expect(model.getById(3).faviconLink).toBe('hey') \ No newline at end of file