summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-12 11:54:49 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-12 11:54:49 +0200
commit3baa8b51e42a1d353d5d9335a4c464d224027a40 (patch)
tree7e4ffdf3722b176836bbda84b046ab3d85e44b51
parente8cdb315693dce4212597932ab99ccc23ec8ab0c (diff)
implement mark as read for feeds and folders, fix #29
-rw-r--r--appinfo/routes.php2
-rw-r--r--controller/itemcontroller.php1
-rw-r--r--db/itemmapper.php19
-rw-r--r--tests/unit/db/ItemMapperTest.php17
-rw-r--r--tests/unit/utility/FeedFetcherTest.php2
5 files changed, 22 insertions, 19 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 2d7df74e7..40cf23149 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -120,7 +120,7 @@ $this->create('news_feeds_move', '/feeds/{feedId}/move')->post()->action(
$this->create('news_feeds_read', '/feeds/{feedId}/read')->post()->action(
function($params){
- App::main('FeedController', 'read', $params, new DIContainer());
+ App::main('ItemController', 'readFeed', $params, new DIContainer());
}
);
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php
index 23509fec2..c911fa3c6 100644
--- a/controller/itemcontroller.php
+++ b/controller/itemcontroller.php
@@ -168,6 +168,7 @@ class ItemController extends Controller {
$highestItemId = (int) $this->params('highestItemId');
$this->itemBl->readFeed($feedId, $highestItemId, $userId);
+ return $this->renderJSON();
}
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 2ba0a7f2c..077614695 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -115,15 +115,16 @@ class ItemMapper extends Mapper implements IMapper {
public function readFeed($feedId, $highestItemId, $userId){
- $sql = 'UPDATE `*PREFIX*news_feeds` `feeds` ' .
- 'JOIN `*PREFIX*news_items` `items` ' .
- 'ON `items`.`feed_id` = `feeds`.`id` ' .
- 'AND `feeds`.`user_id` = ? ' .
- 'AND `feeds`.`id` = ? ' .
- 'AND `items`.`id` <= ? ' .
- 'SET `items`.`status` = (`items`.`status` & ?) ';
- $params = array($userId, $feedId, $highestItemId, ~StatusFlag::UNREAD);
-
+ $sql = 'UPDATE `*PREFIX*news_items` ' .
+ 'SET `status` = `status` & ? ' .
+ 'WHERE `feed_id` = ? ' .
+ 'AND `id` <= ? ' .
+ 'AND EXISTS (' .
+ 'SELECT * FROM `*PREFIX*news_feeds` ' .
+ 'WHERE `user_id` = ? ' .
+ 'AND `id` = ? ) ';
+ $params = array(~StatusFlag::UNREAD, $feedId, $highestItemId, $userId,
+ $feedId);
$this->execute($sql, $params);
}
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index ee3678b3d..56cfe62ab 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -118,14 +118,15 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testReadFeed(){
- $sql = 'UPDATE `*PREFIX*news_feeds` `feeds` ' .
- 'JOIN `*PREFIX*news_items` `items` ' .
- 'ON `items`.`feed_id` = `feeds`.`id` ' .
- 'AND `feeds`.`user_id` = ? ' .
- 'AND `feeds`.`id` = ? ' .
- 'AND `items`.`id` <= ? ' .
- 'SET `items`.`status` = (`items`.`status` & ?) ';
- $params = array($this->user, 3, 6, ~StatusFlag::UNREAD);
+ $sql = 'UPDATE `*PREFIX*news_items` ' .
+ 'SET `status` = `status` & ? ' .
+ 'WHERE `feed_id` = ? ' .
+ 'AND `id` <= ? ' .
+ 'AND EXISTS (' .
+ 'SELECT * FROM `*PREFIX*news_feeds` ' .
+ 'WHERE `user_id` = ? ' .
+ 'AND `id` = ? ) ';
+ $params = array(~StatusFlag::UNREAD, 3, 6, $this->user, 3);
$this->setMapperResult($sql, $params);
$this->mapper->readFeed(3, 6, $this->user);
}
diff --git a/tests/unit/utility/FeedFetcherTest.php b/tests/unit/utility/FeedFetcherTest.php
index 61fe78c64..ba4a53db1 100644
--- a/tests/unit/utility/FeedFetcherTest.php
+++ b/tests/unit/utility/FeedFetcherTest.php
@@ -33,7 +33,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
private $fetcher;
protected function setUp(){
- $this->fetcher = new FeedFetcher($this->getAPIMock());
+ $this->fetcher = new FeedFetcher($this->getAPIMock(), 'dir', 300);
}