3 * @copyright Copyright (C) 2010-2023, 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\Conversation;
25 use Friendica\App\Mode;
26 use Friendica\Content\BoundariesPager;
27 use Friendica\Content\Conversation;
28 use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
29 use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
30 use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
31 use Friendica\Content\Conversation\Repository\Channel as ChannelRepository;
32 use Friendica\Content\Conversation\Factory\Channel as ChannelFactory;
33 use Friendica\Content\Conversation\Factory\Community as CommunityFactory;
34 use Friendica\Content\Conversation\Factory\Network as NetworkFactory;
35 use Friendica\Content\Conversation\Factory\UserDefinedChannel;
36 use Friendica\Content\Feature;
37 use Friendica\Content\Nav;
38 use Friendica\Content\Text\HTML;
39 use Friendica\Content\Widget;
40 use Friendica\Content\Widget\TrendingTags;
41 use Friendica\Core\Cache\Capability\ICanCache;
42 use Friendica\Core\Config\Capability\IManageConfigValues;
43 use Friendica\Core\L10n;
44 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
45 use Friendica\Core\Renderer;
46 use Friendica\Core\Session\Capability\IHandleUserSessions;
47 use Friendica\Module\Security\Login;
48 use Friendica\Network\HTTPException;
49 use Friendica\Database\Database;
50 use Friendica\Module\Response;
51 use Friendica\Navigation\SystemMessages;
52 use Friendica\Util\Profiler;
53 use Psr\Log\LoggerInterface;
55 class Channel extends Timeline
57 /** @var TimelineFactory */
59 /** @var Conversation */
60 protected $conversation;
63 /** @var SystemMessages */
64 protected $systemMessages;
65 /** @var ChannelFactory */
66 protected $channelFactory;
67 /** @var UserDefinedChannelFactory */
68 protected $userDefinedChannel;
69 /** @var CommunityFactory */
71 /** @var NetworkFactory */
72 protected $networkFactory;
74 public function __construct(UserDefinedChannelFactory $userDefinedChannel, NetworkFactory $network, CommunityFactory $community, ChannelFactory $channelFactory, ChannelRepository $channel, TimelineFactory $timeline, Conversation $conversation, App\Page $page, SystemMessages $systemMessages, Mode $mode, IHandleUserSessions $session, Database $database, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, ICanCache $cache, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
76 parent::__construct($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
78 $this->timeline = $timeline;
79 $this->conversation = $conversation;
81 $this->systemMessages = $systemMessages;
82 $this->channelFactory = $channelFactory;
83 $this->community = $community;
84 $this->networkFactory = $network;
85 $this->userDefinedChannel = $userDefinedChannel;
88 protected function content(array $request = []): string
90 if (!$this->session->getLocalUserId()) {
94 $this->parseRequest($request);
96 $t = Renderer::getMarkupTemplate("community.tpl");
97 $o = Renderer::replaceMacros($t, [
102 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
103 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
104 $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
107 if (empty($request['mode']) || ($request['mode'] != 'raw')) {
108 $tabs = $this->getTabArray($this->channelFactory->getTimelines($this->session->getLocalUserId()), 'channel');
109 $tabs = array_merge($tabs, $this->getTabArray($this->userDefinedChannel->getForUser($this->session->getLocalUserId()), 'channel'));
110 $tabs = array_merge($tabs, $this->getTabArray($this->community->getTimelines(true), 'channel'));
112 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
113 $o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
115 Nav::setSelected('channel');
117 $this->page['aside'] .= Widget::accountTypes('channel/' . $this->selectedTab, $this->accountTypeString);
119 if (!in_array($this->selectedTab, [ChannelEntity::FOLLOWERS, ChannelEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
120 $this->page['aside'] .= $this->getNoSharerWidget('channel');
123 if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
124 $this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
127 // We need the editor here to be able to reshare an item.
128 $o .= $this->conversation->statusEditor([], 0, true);
131 if ($this->channelFactory->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
132 $items = $this->getChannelItems();
135 $items = $this->getCommunityItems();
136 $order = 'commented';
139 if (!$this->database->isResult($items)) {
140 $this->systemMessages->addNotice($this->l10n->t('No results.'));
144 $o .= $this->conversation->render($items, Conversation::MODE_CHANNEL, false, false, $order, $this->session->getLocalUserId());
146 $pager = new BoundariesPager(
148 $this->args->getQueryString(),
150 $items[count($items) - 1][$order],
154 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
155 $o .= HTML::scrollLoader();
157 $o .= $pager->renderMinimal(count($items));
164 * Computes module parameters from the request and local configuration
166 * @throws HTTPException\BadRequestException
167 * @throws HTTPException\ForbiddenException
169 protected function parseRequest(array $request)
171 parent::parseRequest($request);
173 if (!$this->selectedTab) {
174 $this->selectedTab = ChannelEntity::FORYOU;
177 if (!$this->channelFactory->isTimeline($this->selectedTab) && !$this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) {
178 throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
181 $this->maxId = $request['last_created'] ?? $this->maxId;
182 $this->minId = $request['first_created'] ?? $this->minId;