summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorMarco Nassabain <marco.nassabain@hotmail.com>2021-02-23 22:59:14 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-04-08 22:31:21 +0200
commit907e7647493ee10a6a41d0a8e39b6214ce2752cd (patch)
tree7ab42d6120d7e39f31441bb3adf3ad5de9601002 /lib/Service
parent237363e087c629f8902828575908d3c54e5aa348 (diff)
🚧 ItemService, Controller: added basic sharing
- TODO: check if relation already exists Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/ItemServiceV2.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php
index 57804a8c3..a32eef314 100644
--- a/lib/Service/ItemServiceV2.php
+++ b/lib/Service/ItemServiceV2.php
@@ -392,4 +392,48 @@ class ItemServiceV2 extends Service
): array {
return $this->mapper->findAllItems($userId, $type, $limit, $offset, $oldestFirst, $search);
}
+
+
+ /**
+ * Share an item with a user
+ *
+ * @param string $userId Item owner
+ * @param int $id Item ID
+ * @param bool $shareWithId User to share with
+ *
+ * Sharing by copying - the item is duplicated, and the 'sharedBy' and
+ * 'sharedWith' fields are filled accordingly.
+ * We copy the 'feedId', because the article will still be owned by
+ * $userId, and it'll be stored in his feed
+ *
+ * @return Item
+ * @throws ServiceNotFoundException|ServiceConflictException
+ */
+ public function share(string $userId, int $id, string $shareWithId): Entity
+ {
+ // TODO: check if item is already shared with the user
+
+ /** @var Item $item */
+ $item = $this->find($userId, $id);
+
+ // duplicate the item
+ $sharedItem = Item::fromImport($item->jsonSerialize());
+
+ // copy and initialize fields
+ $sharedItem->setUnread(true);
+ $sharedItem->setStarred(false);
+ $sharedItem->setFeedId($item->getFeedId());
+ $sharedItem->setFingerprint($item->getFingerprint());
+ $sharedItem->setContentHash($item->getContentHash());
+ $sharedItem->setSearchIndex($item->getSearchIndex());
+
+ // set share data
+ $sharedItem->setSharedBy($userId);
+ $sharedItem->setSharedWith($shareWithId);
+
+ // return $this->mapper->update($item);
+ return $this->mapper->insert($sharedItem);
+ }
+
+ // TODO: implement shared() -> return all items shared with user
}