Move DI dependency for Content\Item class

This commit is contained in:
Philipp 2022-10-20 21:36:38 +02:00
parent 37ff477b55
commit d76a2b6ad6
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432
1 changed files with 15 additions and 12 deletions

View File

@ -27,9 +27,9 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item as ItemModel; use Friendica\Model\Item as ItemModel;
@ -53,12 +53,15 @@ class Item
private $l10n; private $l10n;
/** @var Profiler */ /** @var Profiler */
private $profiler; private $profiler;
/** @var IHandleUserSessions */
private $userSession;
public function __construct(Profiler $profiler, Activity $activity, L10n $l10n) public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession)
{ {
$this->profiler = $profiler; $this->profiler = $profiler;
$this->activity = $activity; $this->activity = $activity;
$this->l10n = $l10n; $this->l10n = $l10n;
$this->userSession = $userSession;
} }
/** /**
@ -110,7 +113,7 @@ class Item
$categories[] = [ $categories[] = [
'name' => $savedFolderName, 'name' => $savedFolderName,
'url' => $url, 'url' => $url,
'removeurl' => DI::userSession()->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '', 'removeurl' => $this->userSession->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '',
'first' => $first, 'first' => $first,
'last' => false 'last' => false
]; ];
@ -121,12 +124,12 @@ class Item
$categories[count($categories) - 1]['last'] = true; $categories[count($categories) - 1]['last'] = true;
} }
if (DI::userSession()->getLocalUserId() == $uid) { if ($this->userSession->getLocalUserId() == $uid) {
foreach (Post\Category::getArrayByURIId($item['uri-id'], $uid, Post\Category::FILE) as $savedFolderName) { foreach (Post\Category::getArrayByURIId($item['uri-id'], $uid, Post\Category::FILE) as $savedFolderName) {
$folders[] = [ $folders[] = [
'name' => $savedFolderName, 'name' => $savedFolderName,
'url' => "#", 'url' => "#",
'removeurl' => DI::userSession()->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '', 'removeurl' => $this->userSession->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '',
'first' => $first, 'first' => $first,
'last' => false 'last' => false
]; ];
@ -332,7 +335,7 @@ class Item
$sub_link = $contact_url = $pm_url = $status_link = ''; $sub_link = $contact_url = $pm_url = $status_link = '';
$photos_link = $posts_link = $block_link = $ignore_link = ''; $photos_link = $posts_link = $block_link = $ignore_link = '';
if (DI::userSession()->getLocalUserId() && DI::userSession()->getLocalUserId() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) { if ($this->userSession->getLocalUserId() && $this->userSession->getLocalUserId() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
$sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;'; $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
} }
@ -349,7 +352,7 @@ class Item
$pcid = $item['author-id']; $pcid = $item['author-id'];
$network = ''; $network = '';
$rel = 0; $rel = 0;
$condition = ['uid' => DI::userSession()->getLocalUserId(), 'uri-id' => $item['author-uri-id']]; $condition = ['uid' => $this->userSession->getLocalUserId(), 'uri-id' => $item['author-uri-id']];
$contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition); $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
$cid = $contact['id']; $cid = $contact['id'];
@ -379,7 +382,7 @@ class Item
} }
} }
if (DI::userSession()->getLocalUserId()) { if ($this->userSession->getLocalUserId()) {
$menu = [ $menu = [
$this->l10n->t('Follow Thread') => $sub_link, $this->l10n->t('Follow Thread') => $sub_link,
$this->l10n->t('View Status') => $status_link, $this->l10n->t('View Status') => $status_link,
@ -440,7 +443,7 @@ class Item
return (!($this->activity->match($item['verb'], Activity::FOLLOW) && return (!($this->activity->match($item['verb'], Activity::FOLLOW) &&
$item['object-type'] === Activity\ObjectType::NOTE && $item['object-type'] === Activity\ObjectType::NOTE &&
empty($item['self']) && empty($item['self']) &&
$item['uid'] == DI::userSession()->getLocalUserId()) $item['uid'] == $this->userSession->getLocalUserId())
); );
} }