3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Contact;
25 use Friendica\BaseModule;
26 use Friendica\Contact\LocalRelationship\Repository\LocalRelationship;
27 use Friendica\Content\Conversation;
28 use Friendica\Content\Nav;
29 use Friendica\Content\Widget;
30 use Friendica\Core\L10n;
31 use Friendica\Core\Protocol;
32 use Friendica\Core\Session\Capability\IHandleUserSessions;
33 use Friendica\Core\Theme;
35 use Friendica\Module\Contact;
36 use Friendica\Module\Response;
37 use Friendica\Module\Security\Login;
38 use Friendica\Network\HTTPException\NotFoundException;
39 use Friendica\Util\Profiler;
40 use Psr\Log\LoggerInterface;
43 * Manages and show Contacts and their content
45 class Conversations extends BaseModule
54 private $conversation;
56 * @var LocalRelationship
58 private $localRelationship;
60 * @var IHandleUserSessions
64 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 = [])
66 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
69 $this->conversation = $conversation;
70 $this->localRelationship = $localRelationship;
71 $this->userSession = $userSession;
74 protected function content(array $request = []): string
76 if (!$this->userSession->getLocalUserId()) {
77 return Login::form($_SERVER['REQUEST_URI']);
80 // Backward compatibility: Ensure to use the public contact when the user contact is provided
81 // Remove by version 2022.03
82 $data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
84 throw new NotFoundException($this->t('Contact not found.'));
87 $contact = Model\Contact::getById($data['public']);
88 if (empty($contact)) {
89 throw new NotFoundException($this->t('Contact not found.'));
92 // Don't display contacts that are about to be deleted
93 if (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM) {
94 throw new NotFoundException($this->t('Contact not found.'));
97 $localRelationship = $this->localRelationship->getForUserContact($this->userSession->getLocalUserId(), $contact['id']);
98 if ($localRelationship->rel === Model\Contact::SELF) {
99 $this->baseUrl->redirect('profile/' . $contact['nick']);
102 // Load necessary libraries for the status editor
103 $this->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
104 $this->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
105 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
106 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
108 $this->page['aside'] .= Widget\VCard::getHTML($contact);
110 Nav::setSelected('contact');
112 // We need the editor here to be able to reshare an item.
113 $o = $this->conversation->statusEditor([], 0, true);
115 $o .= Contact::getTabsHTML($contact, Contact::TAB_CONVERSATIONS);
116 $o .= Model\Contact::getPostsFromId($contact['id'], true);