]> git.mxchange.org Git - friendica.git/blob - src/Module/Contact/Conversations.php
Merge remote-tracking branch 'upstream/develop' into api-status
[friendica.git] / src / Module / Contact / Conversations.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license   GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Contact;
23
24 use Friendica\App;
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\Theme;
33 use Friendica\Model;
34 use Friendica\Module\Contact;
35 use Friendica\Module\Security\Login;
36 use Friendica\Network\HTTPException\NotFoundException;
37
38 /**
39  *  Manages and show Contacts and their content
40  */
41 class Conversations extends BaseModule
42 {
43         /**
44          * @var App\Page
45          */
46         private $page;
47         /**
48          * @var Conversation
49          */
50         private $conversation;
51         /**
52          * @var App\BaseURL
53          */
54         private $baseUrl;
55         /**
56          * @var LocalRelationship
57          */
58         private $localRelationship;
59
60         public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Page $page, Conversation $conversation, array $parameters = [])
61         {
62                 parent::__construct($l10n, $parameters);
63
64                 $this->page              = $page;
65                 $this->conversation      = $conversation;
66                 $this->baseUrl           = $baseUrl;
67                 $this->localRelationship = $localRelationship;
68         }
69
70         public function content(): string
71         {
72                 if (!local_user()) {
73                         return Login::form($_SERVER['REQUEST_URI']);
74                 }
75
76                 // Backward compatibility: Ensure to use the public contact when the user contact is provided
77                 // Remove by version 2022.03
78                 $data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), local_user());
79                 if (empty($data)) {
80                         throw new NotFoundException($this->t('Contact not found.'));
81                 }
82
83                 $contact = Model\Contact::getById($data['public']);
84                 if (empty($contact)) {
85                         throw new NotFoundException($this->t('Contact not found.'));
86                 }
87
88                 // Don't display contacts that are about to be deleted
89                 if (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM) {
90                         throw new NotFoundException($this->t('Contact not found.'));
91                 }
92
93                 $localRelationship = $this->localRelationship->getForUserContact(local_user(), $contact['id']);
94                 if ($localRelationship->rel === Model\Contact::SELF) {
95                         $this->baseUrl->redirect('profile/' . $contact['nick']);
96                 }
97
98                 // Load necessary libraries for the status editor
99                 $this->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
100                 $this->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
101                 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
102                 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
103
104                 $this->page['aside'] .= Widget\VCard::getHTML($contact);
105
106                 Nav::setSelected('contact');
107
108                 // We need the editor here to be able to reshare an item.
109                 $o = $this->conversation->statusEditor([], 0, true);
110
111                 $o .= Contact::getTabsHTML($contact, Contact::TAB_CONVERSATIONS);
112                 $o .= Model\Contact::getPostsFromId($contact['id'], true);
113
114                 return $o;
115         }
116 }