diff options
author | Marco Nassabain <marco.nassabain@hotmail.com> | 2021-03-03 22:32:53 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-04-08 22:31:21 +0200 |
commit | d2e831fbaa02699516749d5d8fe455259eebf912 (patch) | |
tree | 872de4735825370b7b4c0af2dcbd89bf490b019f /lib/Service/ItemServiceV2.php | |
parent | 525c47bd016c3365341ae2b29fea1f89621c798b (diff) |
🎨 Update item share: add items to dummy feed
- create/find a 'shared with me' dummy feed
- clone item, initialize fields, add to dummy feed
Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
Diffstat (limited to 'lib/Service/ItemServiceV2.php')
-rw-r--r-- | lib/Service/ItemServiceV2.php | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php index 47656c12d..3dd1b04d7 100644 --- a/lib/Service/ItemServiceV2.php +++ b/lib/Service/ItemServiceV2.php @@ -439,10 +439,10 @@ class ItemServiceV2 extends Service * @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 + * Sharing by copying - the item is duplicated, and the 'sharedBy' + * field is filled accordingly. + * The item is then placed in a dummy feed reserved for items + * shared with the user * * @return Item * @throws ServiceNotFoundException|ServiceConflictException @@ -457,19 +457,32 @@ class ItemServiceV2 extends Service } // duplicate the item - $sharedItem = Item::fromImport($item->jsonSerialize()); + $sharedItem = clone $item; - // copy and initialize fields + // 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); + + // get 'shared with me' dummy feed + // TODO: move to feedService->createSharedWithMeFeed() ? + $feedUrl = 'http://nextcloud/sharedwithme'; + $feed = $this->feedService->findByUrl($shareWithId, $feedUrl); + if (is_null($feed)) { + $feed = new Feed(); + $feed->setUserId($shareWithId) + ->setUrlHash(md5($feedUrl)) + ->setLink($feedUrl) + ->setUrl($feedUrl) + ->setTitle('Shared with me') + ->setAdded(time()) + ->setFolderId(null) + ->setPreventUpdate(true); + + $feed = $this->feedService->insert($feed); + } + + $sharedItem->setFeedId($feed->getId()); return $this->mapper->insert($sharedItem); } |