summaryrefslogtreecommitdiffstats
path: root/controller
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-29 13:25:04 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-29 13:30:01 +0200
commit3fc18156ae0b586e8de0c82949acfa6291317536 (patch)
tree201e97511bea44c58b5e9d78d8cf36ae2e2b54f9 /controller
parenta03b54c6a59837d0045c140ea7aef3fae95daa95 (diff)
go back to order by id, fix #138, use a newest item id to prevent marking items as read that the user didnt see yet fix #141, also update the starred count periodically
Diffstat (limited to 'controller')
-rw-r--r--controller/feedcontroller.php18
-rw-r--r--controller/itemcontroller.php26
2 files changed, 18 insertions, 26 deletions
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php
index 09f638170..d19008b5a 100644
--- a/controller/feedcontroller.php
+++ b/controller/feedcontroller.php
@@ -29,6 +29,7 @@ use \OCA\AppFramework\Controller\Controller;
use \OCA\AppFramework\Core\API;
use \OCA\AppFramework\Http\Request;
+use \OCA\News\BusinessLayer\ItemBusinessLayer;
use \OCA\News\BusinessLayer\FeedBusinessLayer;
use \OCA\News\BusinessLayer\FolderBusinessLayer;
use \OCA\News\BusinessLayer\BusinessLayerException;
@@ -39,13 +40,16 @@ class FeedController extends Controller {
private $feedBusinessLayer;
private $folderBusinessLayer;
+ private $itemBusinessLayer;
public function __construct(API $api, Request $request,
FeedBusinessLayer $feedBusinessLayer,
- FolderBusinessLayer $folderBusinessLayer){
+ FolderBusinessLayer $folderBusinessLayer,
+ ItemBusinessLayer $itemBusinessLayer){
parent::__construct($api, $request);
$this->feedBusinessLayer = $feedBusinessLayer;
$this->folderBusinessLayer = $folderBusinessLayer;
+ $this->itemBusinessLayer = $itemBusinessLayer;
}
@@ -56,12 +60,20 @@ class FeedController extends Controller {
*/
public function feeds(){
$userId = $this->api->getUserId();
- $result = $this->feedBusinessLayer->findAll($userId);
+ // this method is also used to update the interface
+ // because of this we also pass the starred count and the newest
+ // item id which will be used for marking feeds read
$params = array(
- 'feeds' => $result
+ 'feeds' => $this->feedBusinessLayer->findAll($userId),
+ 'starred' => $this->itemBusinessLayer->starredCount($userId)
);
+ try {
+ $params['newestItemId'] =
+ $this->itemBusinessLayer->getNewestItemId($userId);
+ } catch (BusinessLayerException $ex) {}
+
return $this->renderJSON($params);
}
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php
index 459435a7e..a4d9abf3f 100644
--- a/controller/itemcontroller.php
+++ b/controller/itemcontroller.php
@@ -61,7 +61,6 @@ class ItemController extends Controller {
$type = (int) $this->params('type');
$id = (int) $this->params('id');
$offset = (int) $this->params('offset', 0);
- $newestItemId = (int) $this->params('newestItemId');
$this->api->setUserValue('lastViewedFeedId', $id);
$this->api->setUserValue('lastViewedFeedType', $type);
@@ -76,14 +75,12 @@ class ItemController extends Controller {
if($offset === 0) {
$params['newestItemId'] =
$this->itemBusinessLayer->getNewestItemId($userId);
- $newestItemId = $params['newestItemId'];
$params['feeds'] = $this->feedBusinessLayer->findAll($userId);
+ $params['starred'] = $this->itemBusinessLayer->starredCount($userId);
}
- $params['items'] = $this->itemBusinessLayer->findAll(
- $id, $type, $limit,
- $offset, $newestItemId,
- $showAll, $userId);
+ $params['items'] = $this->itemBusinessLayer->findAll($id, $type, $limit,
+ $offset, $showAll, $userId);
// this gets thrown if there are no items
// in that case just return an empty array
} catch(BusinessLayerException $ex) {}
@@ -92,23 +89,6 @@ class ItemController extends Controller {
}
- /**
- * @IsAdminExemption
- * @IsSubAdminExemption
- * @Ajax
- */
- public function starred(){
- $userId = $this->api->getUserId();
- $starredCount = $this->itemBusinessLayer->starredCount($userId);
-
- $params = array(
- 'starred' => (int) $starredCount
- );
-
- return $this->renderJSON($params);
- }
-
-
private function setStarred($isStarred){
$userId = $this->api->getUserId();
$feedId = (int) $this->params('feedId');