summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-12 12:25:58 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-12 12:25:58 +0200
commite8767f75116ff7ef2b7a349480151c9f66bbade0 (patch)
tree5879fe01fa8113a299daaba4d2c6cfa84769a104
parente9eaa93826c75097d95d21a556e1b1aae6610bcd (diff)
implement clientside update requests, fix #27
-rw-r--r--bl/feedbl.php4
-rw-r--r--js/app/app.coffee10
-rw-r--r--js/app/services/bl/feedbl.coffee6
-rw-r--r--js/public/app.js25
-rw-r--r--js/tests/services/bl/feedblSpec.coffee17
-rw-r--r--tests/unit/bl/FeedBlTest.php44
6 files changed, 92 insertions, 14 deletions
diff --git a/bl/feedbl.php b/bl/feedbl.php
index 0c0bbe9e0..b70d95342 100644
--- a/bl/feedbl.php
+++ b/bl/feedbl.php
@@ -146,7 +146,9 @@ class FeedBl extends Bl {
// failed updating is not really a problem, so only log it
$this->api->log('Can not update feed with url' . $existingFeed->getUrl() .
': Not found or bad source');
- }
+ }
+
+ return $this->mapper->find($feedId, $userId);
}
diff --git a/js/app/app.coffee b/js/app/app.coffee
index 82a839c8c..9a8e54d6a 100644
--- a/js/app/app.coffee
+++ b/js/app/app.coffee
@@ -26,12 +26,18 @@ angular.module('News', ['OC', 'ui']).config ($provide) ->
$provide.value 'Config', config =
markReadTimeout: 500
scrollTimeout: 500
- feedUpdateInterval: 6000000
+ feedUpdateInterval: 600000
itemBatchSize: 20
-angular.module('News').run ['Persistence', (Persistence) ->
+angular.module('News').run ['Persistence', 'Config', 'FeedBl',
+(Persistence, Config, FeedBl) ->
+
Persistence.init()
+
+ setInterval ->
+ FeedBl.updateFeeds()
+ , Config.feedUpdateInterval
]
diff --git a/js/app/services/bl/feedbl.coffee b/js/app/services/bl/feedbl.coffee
index 4c9ff7c99..ead15fcd7 100644
--- a/js/app/services/bl/feedbl.coffee
+++ b/js/app/services/bl/feedbl.coffee
@@ -164,6 +164,12 @@ NewLoading, _ExistsError) ->
@_feedModel.removeByUrlHash(urlHash)
+ updateFeeds: ->
+ for feed in @_feedModel.getAll()
+ if angular.isDefined(feed.id)
+ @_persistence.updateFeed(feed.id)
+
+
return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType,
ItemModel, NewLoading)
diff --git a/js/public/app.js b/js/public/app.js
index 4f44689c3..e11c2e976 100644
--- a/js/public/app.js
+++ b/js/public/app.js
@@ -41,14 +41,17 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return $provide.value('Config', config = {
markReadTimeout: 500,
scrollTimeout: 500,
- feedUpdateInterval: 6000000,
+ feedUpdateInterval: 600000,
itemBatchSize: 20
});
});
angular.module('News').run([
- 'Persistence', function(Persistence) {
- return Persistence.init();
+ 'Persistence', 'Config', 'FeedBl', function(Persistence, Config, FeedBl) {
+ Persistence.init();
+ return setInterval(function() {
+ return FeedBl.updateFeeds();
+ }, Config.feedUpdateInterval);
}
]);
@@ -800,6 +803,22 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return this._feedModel.removeByUrlHash(urlHash);
};
+ FeedBl.prototype.updateFeeds = function() {
+ var feed, _i, _len, _ref, _results;
+
+ _ref = this._feedModel.getAll();
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ feed = _ref[_i];
+ if (angular.isDefined(feed.id)) {
+ _results.push(this._persistence.updateFeed(feed.id));
+ } else {
+ _results.push(void 0);
+ }
+ }
+ return _results;
+ };
+
return FeedBl;
})(_Bl);
diff --git a/js/tests/services/bl/feedblSpec.coffee b/js/tests/services/bl/feedblSpec.coffee
index c77922574..0303dd4c1 100644
--- a/js/tests/services/bl/feedblSpec.coffee
+++ b/js/tests/services/bl/feedblSpec.coffee
@@ -321,3 +321,20 @@ describe 'FeedBl', ->
expect(@FeedModel.size()).toBe(0)
expect(@FeedModel.getByUrlHash('john')).toBe(undefined)
+
+ it 'should update all feeds', =>
+ @persistence.updateFeed = jasmine.createSpy('update')
+ @FeedModel.add({id: 3, urlHash: 'john'})
+
+ @FeedBl.updateFeeds()
+
+ expect(@persistence.updateFeed).toHaveBeenCalledWith(3)
+
+
+ it 'should not update feeds without ids', =>
+ @persistence.updateFeed = jasmine.createSpy('update')
+ @FeedModel.add({urlHash: 'john'})
+
+ @FeedBl.updateFeeds()
+
+ expect(@persistence.updateFeed).not.toHaveBeenCalled() \ No newline at end of file
diff --git a/tests/unit/bl/FeedBlTest.php b/tests/unit/bl/FeedBlTest.php
index b1c5ba3c8..0fadf2c24 100644
--- a/tests/unit/bl/FeedBlTest.php
+++ b/tests/unit/bl/FeedBlTest.php
@@ -164,7 +164,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
$fetchReturn = array($feed, $items);
- $this->mapper->expects($this->once())
+ $this->mapper->expects($this->at(0))
->method('find')
->with($this->equalTo($feed->getId()),
$this->equalTo($this->user))
@@ -182,7 +182,14 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
->method('insert')
->with($this->equalTo($items[0]));
- $this->bl->update($feed->getId(), $this->user);
+ $this->mapper->expects($this->at(1))
+ ->method('find')
+ ->with($feed->getId(), $this->user)
+ ->will($this->returnValue($feed));
+
+ $return = $this->bl->update($feed->getId(), $this->user);
+
+ $this->assertEquals($return, $feed);
}
@@ -200,7 +207,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
$fetchReturn = array($feed, $items);
- $this->mapper->expects($this->once())
+ $this->mapper->expects($this->at(0))
->method('find')
->with($this->equalTo($feed->getId()),
$this->equalTo($this->user))
@@ -219,7 +226,14 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
$this->itemMapper->expects($this->never())
->method('delete');
- $this->bl->update($feed->getId(), $this->user);
+ $this->mapper->expects($this->at(1))
+ ->method('find')
+ ->with($feed->getId(), $this->user)
+ ->will($this->returnValue($feed));
+
+ $return = $this->bl->update($feed->getId(), $this->user);
+
+ $this->assertEquals($return, $feed);
}
@@ -241,7 +255,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
$fetchReturn = array($feed, $items);
- $this->mapper->expects($this->once())
+ $this->mapper->expects($this->at(0))
->method('find')
->with($this->equalTo($feed->getId()),
$this->equalTo($this->user))
@@ -262,7 +276,14 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
->method('insert')
->with($this->equalTo($item));
- $this->bl->update($feed->getId(), $this->user);
+ $this->mapper->expects($this->at(1))
+ ->method('find')
+ ->with($feed->getId(), $this->user)
+ ->will($this->returnValue($feed));
+
+ $return = $this->bl->update($feed->getId(), $this->user);
+
+ $this->assertEquals($return, $feed);
$this->assertTrue($item->isUnread());
}
@@ -273,7 +294,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
$feed->getUrl('test');
$ex = new FetcherException('');
- $this->mapper->expects($this->once())
+ $this->mapper->expects($this->at(0))
->method('find')
->with($this->equalTo($feed->getId()),
$this->equalTo($this->user))
@@ -284,7 +305,14 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
$this->api->expects($this->once())
->method('log');
- $this->bl->update($feed->getId(), $this->user);
+ $this->mapper->expects($this->at(1))
+ ->method('find')
+ ->with($feed->getId(), $this->user)
+ ->will($this->returnValue($feed));
+
+ $return = $this->bl->update($feed->getId(), $this->user);
+
+ $this->assertEquals($return, $feed);
}
public function testMove(){