From 0f6ec7c99ca43da46766ca6126ae20d280e9b662 Mon Sep 17 00:00:00 2001 From: Marco Nassabain Date: Wed, 24 Feb 2021 23:23:29 +0100 Subject: =?UTF-8?q?=E2=9C=A8=20Implementer=20shared=20getter=20+=20add=20c?= =?UTF-8?q?ount=20in=20request=20-=20ItemServiceV2:=20added=20sharedWithUs?= =?UTF-8?q?er=20-=20returns=20unread=20shared=20items=20-=20ItemController?= =?UTF-8?q?=20&=20FeedController=20-=20returning=20shared=20count?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Nassabain --- lib/Controller/FeedController.php | 2 +- lib/Controller/ItemController.php | 58 ++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 23 deletions(-) (limited to 'lib/Controller') diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index 86a1f5e57..02fbbc625 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -82,7 +82,7 @@ class FeedController extends Controller $params = [ 'feeds' => $this->feedService->findAllForUser($this->getUserId()), 'starred' => count($this->itemService->starred($this->getUserId())), - // 'shared' => count($this->itemService->shared($this->getUserId())) // TODO: uncomment when implemented + 'shared' => count($this->itemService->sharedWithUser($this->getUserId())) ]; try { diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php index 7ebe48b69..ab875b31c 100644 --- a/lib/Controller/ItemController.php +++ b/lib/Controller/ItemController.php @@ -130,13 +130,10 @@ class ItemController extends Controller // we need to pass the newest feeds to not let the unread count get // out of sync if ($offset === 0) { - $params['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); - $params['feeds'] = $this->feedService->findAllForUser($this->userId); - $params['starred'] = - $this->itemService->starredCount($this->userId); - $params['shared'] = - $this->itemService->sharedCount($this->userId); + $return['newestItemId'] = $this->itemService->newest($this->getUserId())->getId(); + $return['feeds'] = $this->feedService->findAllForUser($this->getUserId()); + $return['starred'] = count($this->itemService->starred($this->getUserId())); + $return['shared'] = count($this->itemService->sharedWithUser($this->getUserId())); } switch ($type) { @@ -215,20 +212,37 @@ class ItemController extends Controller $return = []; try { - $params['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); - $params['feeds'] = $this->feedService->findAllForUser($this->userId); - $params['starred'] = - $this->itemService->starredCount($this->userId); - $params['shared'] = - $this->itemService->sharedCount($this->userId); - $params['items'] = $this->itemService->findAllNew( - $id, - $type, - $lastModified, - $showAll, - $this->userId - ); + switch ($type) { + case ListType::FEED: + $items = $this->itemService->findAllInFeedAfter( + $this->getUserId(), + $id, + $lastModified, + !$showAll + ); + break; + case ListType::FOLDER: + $items = $this->itemService->findAllInFolderAfter( + $this->getUserId(), + $id, + $lastModified, + !$showAll + ); + break; + default: + $items = $this->itemService->findAllAfter( + $this->getUserId(), + $type, + $lastModified + ); + break; + } + + $return['newestItemId'] = $this->itemService->newest($this->getUserId())->getId(); + $return['feeds'] = $this->feedService->findAllForUser($this->getUserId()); + $return['starred'] = count($this->itemService->starred($this->getUserId())); + $return['shared'] = count($this->itemService->sharedWithUser($this->getUserId())); + $return['items'] = $items; // this gets thrown if there are no items // in that case just return an empty array @@ -323,7 +337,7 @@ class ItemController extends Controller * @NoAdminRequired * * @param int $itemId Item to share - * @param string $shareWithId User to share with + * @param string $shareWithId User to share with */ public function share($itemId, $shareWithId) { -- cgit v1.2.3