mirror of
https://github.com/friendica/friendica
synced 2025-04-25 05:10:11 +00:00
UserSession class [6] - Refactor src/Module/ files without DI
This commit is contained in:
parent
bf39b5a948
commit
22198ea495
8 changed files with 74 additions and 38 deletions
|
@ -29,7 +29,7 @@ use Friendica\Content\Nav;
|
|||
use Friendica\Content\Widget;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Core\Theme;
|
||||
use Friendica\Model;
|
||||
use Friendica\Module\Contact;
|
||||
|
@ -56,25 +56,30 @@ class Conversations extends BaseModule
|
|||
* @var LocalRelationship
|
||||
*/
|
||||
private $localRelationship;
|
||||
/**
|
||||
* @var IHandleUserSessions
|
||||
*/
|
||||
private $userSession;
|
||||
|
||||
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, Conversation $conversation, array $server, array $parameters = [])
|
||||
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, Conversation $conversation, IHandleUserSessions $userSession, $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->page = $page;
|
||||
$this->conversation = $conversation;
|
||||
$this->localRelationship = $localRelationship;
|
||||
$this->userSession = $userSession;
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!$this->userSession->getLocalUserId()) {
|
||||
return Login::form($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
// Backward compatibility: Ensure to use the public contact when the user contact is provided
|
||||
// Remove by version 2022.03
|
||||
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), Session::getLocalUser());
|
||||
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
|
||||
if (empty($data)) {
|
||||
throw new NotFoundException($this->t('Contact not found.'));
|
||||
}
|
||||
|
@ -89,7 +94,7 @@ class Conversations extends BaseModule
|
|||
throw new NotFoundException($this->t('Contact not found.'));
|
||||
}
|
||||
|
||||
$localRelationship = $this->localRelationship->getForUserContact(Session::getLocalUser(), $contact['id']);
|
||||
$localRelationship = $this->localRelationship->getForUserContact($this->userSession->getLocalUserId(), $contact['id']);
|
||||
if ($localRelationship->rel === Model\Contact::SELF) {
|
||||
$this->baseUrl->redirect('profile/' . $contact['nick']);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ use Friendica\Content\Nav;
|
|||
use Friendica\Content\Widget;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model;
|
||||
use Friendica\Module\Contact;
|
||||
|
@ -51,24 +51,29 @@ class Posts extends BaseModule
|
|||
* @var App\Page
|
||||
*/
|
||||
private $page;
|
||||
/**
|
||||
* @var IHandleUserSessions
|
||||
*/
|
||||
private $userSession;
|
||||
|
||||
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, array $server, array $parameters = [])
|
||||
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, IHandleUserSessions $userSession, $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->localRelationship = $localRelationship;
|
||||
$this->page = $page;
|
||||
$this->userSession = $userSession;
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!$this->userSession->getLocalUserId()) {
|
||||
return Login::form($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
// Backward compatibility: Ensure to use the public contact when the user contact is provided
|
||||
// Remove by version 2022.03
|
||||
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), Session::getLocalUser());
|
||||
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
|
||||
if (empty($data)) {
|
||||
throw new NotFoundException($this->t('Contact not found.'));
|
||||
}
|
||||
|
@ -83,7 +88,7 @@ class Posts extends BaseModule
|
|||
throw new NotFoundException($this->t('Contact not found.'));
|
||||
}
|
||||
|
||||
$localRelationship = $this->localRelationship->getForUserContact(Session::getLocalUser(), $contact['id']);
|
||||
$localRelationship = $this->localRelationship->getForUserContact($this->userSession->getLocalUserId(), $contact['id']);
|
||||
if ($localRelationship->rel === Model\Contact::SELF) {
|
||||
$this->baseUrl->redirect('profile/' . $contact['nick']);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue