summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorMarco Nassabain <marco.nassabain@hotmail.com>2021-03-19 20:11:49 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-04-08 22:31:21 +0200
commit1a5ca7417249a991aaea4b36ab61e088cc827993 (patch)
treee2aca1c41bf242176b20cd2f4299fd3c068cd688 /lib/Service
parentbbdd95c30d545cc7dd9719836a94c7b21b381c68 (diff)
✨ Add sharer display name into shared items
- Add mapSharedByDisplayNames in ShareService - Update ItemController to call function on items Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/ShareService.php34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index 2b4edafac..429ec46b0 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -15,6 +15,7 @@ use \OCA\News\Db\Feed;
use \Psr\Log\LoggerInterface;
use OCP\IURLGenerator;
+use OCP\IUserManager;
use \OCP\IL10N;
use OCA\News\Service\Exceptions\ServiceNotFoundException;
@@ -40,7 +41,7 @@ class ShareService
* @var FeedServiceV2
*/
protected $feedService;
-
+
/**
* @var LoggerInterface
*/
@@ -52,6 +53,11 @@ class ShareService
private $urlGenerator;
/**
+ * @var IUserManager
+ */
+ private $userManager;
+
+ /**
* @var IL10N
*/
private $l;
@@ -69,12 +75,14 @@ class ShareService
FeedServiceV2 $feedService,
ItemServiceV2 $itemService,
IURLGenerator $urlGenerator,
+ IUserManager $userManager,
IL10N $l,
LoggerInterface $logger
) {
$this->itemService = $itemService;
$this->feedService = $feedService;
$this->urlGenerator = $urlGenerator;
+ $this->userManager = $userManager;
$this->l = $l;
$this->logger = $logger;
}
@@ -127,4 +135,28 @@ class ShareService
return $this->itemService->insertOrUpdate($sharedItem);
}
+
+ /**
+ * Map sharers display name to shared items.
+ *
+ * Loops through an array of news items. For all shared items, the function
+ * fetches the sharers display name and adds it into the item.
+ *
+ * @param Item[] Array containing items that are shared or not
+ * @return Item[]
+ */
+ public function mapSharedByDisplayNames(array $items): array
+ {
+ foreach ($items as $item) {
+ $sharedBy = $item->getSharedBy();
+ if (!is_null($sharedBy)) {
+ $user = $this->userManager->get($sharedBy);
+ if (!is_null($user)) {
+ $item->setSharedByDisplayName($user->getDisplayName());
+ }
+ }
+ }
+
+ return $items;
+ }
}