diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-26 10:46:32 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-26 11:52:50 +0200 |
commit | 5cc47b4f414026ecf16d8c7025571422367f7c58 (patch) | |
tree | f555d0769e0a594f3a8f873ff8b455e0bf2a00ee /controller | |
parent | 5d41833874a69d2c9322a20ebb7815b6bb1b5adf (diff) |
use last_modified column for finding new items (so we also see if they were updated or starred), use offset to paginate rather than item id
Diffstat (limited to 'controller')
-rw-r--r-- | controller/itemcontroller.php | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php index 84f177cd6..459435a7e 100644 --- a/controller/itemcontroller.php +++ b/controller/itemcontroller.php @@ -29,6 +29,7 @@ use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; +use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; @@ -59,32 +60,33 @@ class ItemController extends Controller { $limit = $this->params('limit'); $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); - - if($limit !== null){ - $offset = (int) $this->params('offset', 0); - $items = $this->itemBusinessLayer->findAll($id, $type, (int) $limit, - $offset, $showAll, $userId); - if($offset === 0) { - $feeds = $this->feedBusinessLayer->findAll($userId); - } - } else { - $updatedSince = (int) $this->params('updatedSince'); - $items = $this->itemBusinessLayer->findAllNew($id, $type, - $updatedSince, $showAll, $userId); - } - $params = array( - 'items' => $items - ); + $params = array(); - // we need to pass the newest feeds to not let the unread count get out - // of sync - if(isset($feeds)) { - $params['feeds'] = $feeds; - } + try { + + // the offset is 0 if the user clicks on a new feed + // we need to pass the newest feeds to not let the unread count get + // out of sync + if($offset === 0) { + $params['newestItemId'] = + $this->itemBusinessLayer->getNewestItemId($userId); + $newestItemId = $params['newestItemId']; + $params['feeds'] = $this->feedBusinessLayer->findAll($userId); + } + + $params['items'] = $this->itemBusinessLayer->findAll( + $id, $type, $limit, + $offset, $newestItemId, + $showAll, $userId); + // this gets thrown if there are no items + // in that case just return an empty array + } catch(BusinessLayerException $ex) {} return $this->renderJSON($params); } |