summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarco Nassabain <marco.nassabain@hotmail.com>2021-02-24 23:23:29 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-04-08 22:31:21 +0200
commit0f6ec7c99ca43da46766ca6126ae20d280e9b662 (patch)
tree6335999fb503cbebe5d5670801ae79b12a4aad6f /lib
parent7e1a0b47cf369f33eedfbd628dea40fd8589a97b (diff)
✨ Implementer shared getter + add count in request
- ItemServiceV2: added sharedWithUser - returns unread shared items - ItemController & FeedController - returning shared count Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/FeedController.php2
-rw-r--r--lib/Controller/ItemController.php58
-rw-r--r--lib/Service/ItemServiceV2.php15
3 files changed, 51 insertions, 24 deletions
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)
{
diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php
index 442fcc1ce..10463b13a 100644
--- a/lib/Service/ItemServiceV2.php
+++ b/lib/Service/ItemServiceV2.php
@@ -460,5 +460,18 @@ class ItemServiceV2 extends Service
return $this->mapper->insert($sharedItem);
}
- // TODO: implement shared() -> return all items shared with user
+ /**
+ * Return all items shared with a given user
+ *
+ * @param string $userId
+ *
+ * @return Item[]
+ */
+ public function sharedWithUser(string $userId): array
+ {
+ return $this->findAllForUser($userId, [
+ 'shared_with' => $userId,
+ 'unread' => true
+ ]);
+ }
}