From 5cc47b4f414026ecf16d8c7025571422367f7c58 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 26 Apr 2013 10:46:32 +0200 Subject: 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 --- controller/itemcontroller.php | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'controller/itemcontroller.php') 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); } -- cgit v1.2.3