From b8b4dfb4969e1baf84a14fb65a5dc153b0f5fae4 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 9 May 2013 12:57:35 +0200 Subject: only make one request for mark all read and mark folder read, fix #171, fix a bug that prevented readding of feeds when its folder was deleted, fix a bug that would not allow mark read for feeds when the app was started for the first time --- controller/feedcontroller.php | 30 +++++++++++++++++++++++++++++- controller/foldercontroller.php | 28 +++++++++++++++++++++++++++- controller/itemcontroller.php | 16 +++++----------- 3 files changed, 61 insertions(+), 13 deletions(-) (limited to 'controller') diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index 63a2c3122..b453338d0 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -43,8 +43,8 @@ class FeedController extends Controller { private $itemBusinessLayer; public function __construct(API $api, Request $request, - FeedBusinessLayer $feedBusinessLayer, FolderBusinessLayer $folderBusinessLayer, + FeedBusinessLayer $feedBusinessLayer, ItemBusinessLayer $itemBusinessLayer){ parent::__construct($api, $request); $this->feedBusinessLayer = $feedBusinessLayer; @@ -138,6 +138,11 @@ class FeedController extends Controller { 'feeds' => array($feed) ); + try { + $params['newestItemId'] = + $this->itemBusinessLayer->getNewestItemId($userId); + } catch (BusinessLayerException $ex) {} + return $this->renderJSON($params); } catch(BusinessLayerException $ex) { return $this->renderJSON(array(), $ex->getMessage()); @@ -230,5 +235,28 @@ class FeedController extends Controller { return $this->renderJSON($params); } + /** + * @IsAdminExemption + * @IsSubAdminExemption + * @Ajax + */ + public function read(){ + $userId = $this->api->getUserId(); + $feedId = (int) $this->params('feedId'); + $highestItemId = (int) $this->params('highestItemId'); + + $this->itemBusinessLayer->readFeed($feedId, $highestItemId, $userId); + + $params = array( + 'feeds' => array( + array( + 'id' => $feedId, + 'unreadCount' => 0 + ) + ) + ); + return $this->renderJSON($params); + } + } \ No newline at end of file diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php index a2e0d028b..7542a5260 100644 --- a/controller/foldercontroller.php +++ b/controller/foldercontroller.php @@ -30,17 +30,25 @@ use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; use \OCA\News\BusinessLayer\FolderBusinessLayer; +use \OCA\News\BusinessLayer\FeedBusinessLayer; +use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; class FolderController extends Controller { private $folderBusinessLayer; + private $feedBusinessLayer; + private $itemBusinessLayer; public function __construct(API $api, Request $request, - FolderBusinessLayer $folderBusinessLayer){ + FolderBusinessLayer $folderBusinessLayer, + FeedBusinessLayer $feedBusinessLayer, + ItemBusinessLayer $itemBusinessLayer){ parent::__construct($api, $request); $this->folderBusinessLayer = $folderBusinessLayer; + $this->feedBusinessLayer = $feedBusinessLayer; + $this->itemBusinessLayer = $itemBusinessLayer; } @@ -161,5 +169,23 @@ class FolderController extends Controller { } } + /** + * @IsAdminExemption + * @IsSubAdminExemption + * @Ajax + */ + public function read(){ + $userId = $this->api->getUserId(); + $folderId = (int) $this->params('folderId'); + $highestItemId = (int) $this->params('highestItemId'); + + $this->itemBusinessLayer->readFolder($folderId, $highestItemId, $userId); + + $params = array( + 'feeds' => $this->feedBusinessLayer->findAll($userId) + ); + return $this->renderJSON($params); + } + } \ No newline at end of file diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php index d19707f90..698c7a093 100644 --- a/controller/itemcontroller.php +++ b/controller/itemcontroller.php @@ -40,8 +40,8 @@ class ItemController extends Controller { private $feedBusinessLayer; public function __construct(API $api, Request $request, - ItemBusinessLayer $itemBusinessLayer, - FeedBusinessLayer $feedBusinessLayer){ + FeedBusinessLayer $feedBusinessLayer, + ItemBusinessLayer $itemBusinessLayer){ parent::__construct($api, $request); $this->itemBusinessLayer = $itemBusinessLayer; $this->feedBusinessLayer = $feedBusinessLayer; @@ -171,20 +171,14 @@ class ItemController extends Controller { * @IsSubAdminExemption * @Ajax */ - public function readFeed(){ + public function readAll(){ $userId = $this->api->getUserId(); - $feedId = (int) $this->params('feedId'); $highestItemId = (int) $this->params('highestItemId'); - $this->itemBusinessLayer->readFeed($feedId, $highestItemId, $userId); + $this->itemBusinessLayer->readAll($highestItemId, $userId); $params = array( - 'feeds' => array( - array( - 'id' => $feedId, - 'unreadCount' => 0 - ) - ) + 'feeds' => $this->feedBusinessLayer->findAll($userId) ); return $this->renderJSON($params); } -- cgit v1.2.3