Channels can now be created by users

This commit is contained in:
Michael 2023-09-19 09:05:28 +00:00
parent 9ed97caf7b
commit d68572ea44
14 changed files with 306 additions and 35 deletions

View file

@ -27,6 +27,7 @@ use Friendica\Content\BoundariesPager;
use Friendica\Content\Conversation;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
use Friendica\Content\Conversation\Repository\Channel as RepositoryChannel;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Text\HTML;
@ -57,9 +58,9 @@ class Channel extends Timeline
/** @var SystemMessages */
protected $systemMessages;
public function __construct(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 = [])
public function __construct(RepositoryChannel $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 = [])
{
parent::__construct($mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->timeline = $timeline;
$this->conversation = $conversation;
@ -109,7 +110,7 @@ class Channel extends Timeline
$o .= $this->conversation->statusEditor([], 0, true);
}
if ($this->timeline->isChannel($this->selectedTab)) {
if ($this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId())) {
$items = $this->getChannelItems();
$order = 'created';
} else {
@ -155,7 +156,7 @@ class Channel extends Timeline
$this->selectedTab = TimelineEntity::FORYOU;
}
if (!$this->timeline->isChannel($this->selectedTab) && !$this->timeline->isCommunity($this->selectedTab)) {
if (!$this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId()) && !$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
}

View file

@ -28,6 +28,7 @@ use Friendica\Content\BoundariesPager;
use Friendica\Content\Conversation;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
use Friendica\Content\Conversation\Repository\Channel;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Text\HTML;
@ -69,9 +70,9 @@ class Community extends Timeline
/** @var SystemMessages */
protected $systemMessages;
public function __construct(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 = [])
public function __construct(Channel $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 = [])
{
parent::__construct($mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->timeline = $timeline;
$this->conversation = $conversation;

View file

@ -27,6 +27,7 @@ use Friendica\Content\BoundariesPager;
use Friendica\Content\Conversation;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
use Friendica\Content\Conversation\Repository\Channel;
use Friendica\Content\Feature;
use Friendica\Content\GroupManager;
use Friendica\Content\Nav;
@ -96,9 +97,9 @@ class Network extends Timeline
/** @var TimelineFactory */
protected $timeline;
public function __construct(App $app, TimelineFactory $timeline, SystemMessages $systemMessages, Mode $mode, Conversation $conversation, App\Page $page, 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 = [])
public function __construct(Channel $channel, App $app, TimelineFactory $timeline, SystemMessages $systemMessages, Mode $mode, Conversation $conversation, App\Page $page, 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 = [])
{
parent::__construct($mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->timeline = $timeline;
@ -125,7 +126,7 @@ class Network extends Timeline
$o = '';
if ($this->timeline->isChannel($this->selectedTab)) {
if ($this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId())) {
if (!in_array($this->selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget($module);
}
@ -274,7 +275,6 @@ class Network extends Timeline
*/
private function getTabsHTML()
{
// @todo user confgurable selection of tabs
$tabs = $this->getTabArray($this->timeline->getNetworkFeeds($this->args->getCommand()), 'network');
$network_timelines = $this->pConfig->get($this->session->getLocalUserId(), 'system', 'network_timelines', []);
@ -289,7 +289,7 @@ class Network extends Timeline
if (!empty($network_timelines)) {
$tabs = [];
foreach (array_keys($arr['tabs']) as $tab) {
foreach (array_column($arr['tabs'], 'code') as $tab) {
if (in_array($tab, $network_timelines)) {
$tabs[] = $arr['tabs'][$tab];
}
@ -313,11 +313,11 @@ class Network extends Timeline
if (!$this->selectedTab) {
$this->selectedTab = self::getTimelineOrderBySession($this->session, $this->pConfig);
} elseif (!$this->timeline->isChannel($this->selectedTab) && !$this->timeline->isCommunity($this->selectedTab)) {
} elseif (!$this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId()) && !$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Network feed not available.'));
}
if (($this->network || $this->circleId || $this->groupContactId) && ($this->timeline->isChannel($this->selectedTab) || $this->timeline->isCommunity($this->selectedTab))) {
if (($this->network || $this->circleId || $this->groupContactId) && ($this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId()) || $this->timeline->isCommunity($this->selectedTab))) {
$this->selectedTab = TimelineEntity::RECEIVED;
}
@ -342,7 +342,7 @@ class Network extends Timeline
$this->mention = false;
} elseif (in_array($this->selectedTab, [TimelineEntity::RECEIVED, TimelineEntity::STAR]) || $this->timeline->isCommunity($this->selectedTab)) {
$this->order = 'received';
} elseif (($this->selectedTab == TimelineEntity::CREATED) || $this->timeline->isChannel($this->selectedTab)) {
} elseif (($this->selectedTab == TimelineEntity::CREATED) || $this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId())) {
$this->order = 'created';
} else {
$this->order = 'commented';

View file

@ -26,6 +26,7 @@ use Friendica\App\Mode;
use Friendica\BaseModule;
use Friendica\Content\Conversation\Collection\Timelines;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Repository\Channel;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Config\Capability\IManageConfigValues;
@ -79,11 +80,14 @@ class Timeline extends BaseModule
protected $config;
/** @var ICanCache */
protected $cache;
/** @var Channel */
protected $channel;
public function __construct(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 = [])
public function __construct(Channel $channel, 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 = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->channel = $channel;
$this->mode = $mode;
$this->session = $session;
$this->database = $database;
@ -176,6 +180,7 @@ class Timeline extends BaseModule
$path = $tab->path ?? $prefix . '/' . $tab->code;
}
$tabs[$tab->code] = [
'code' => $tab->code,
'label' => $tab->label,
'url' => $path,
'sel' => $this->selectedTab == $tab->code ? 'active' : '',
@ -300,6 +305,8 @@ class Timeline extends BaseModule
$condition = ["`media-type` & ?", 4];
} elseif ($this->selectedTab == TimelineEntity::LANGUAGE) {
$condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", $this->l10n->convertCodeForLanguageDetection(User::getLanguageCode($uid))];
} elseif (is_numeric($this->selectedTab)) {
$condition = $this->getUserChannelConditions($this->selectedTab, $this->session->getLocalUserId());
}
if ($this->selectedTab != TimelineEntity::LANGUAGE) {
@ -359,6 +366,39 @@ class Timeline extends BaseModule
return $items;
}
private function getUserChannelConditions(int $id, int $uid): array
{
$channel = $this->channel->selectById($id, $uid);
if (empty($channel)) {
return [];
}
$condition = [];
if (!empty($channel->fullTextSearch)) {
$first = $this->database->selectFirst('post-engagement', ['uri-id']);
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-content` WHERE `uri-id` >= ? AND MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))", $first['uri-id'], $channel->fullTextSearch]);
}
if (!empty($channel->includeTags)) {
$search = explode(',', mb_strtolower($channel->includeTags));
$placeholders = substr(str_repeat("?, ", count($search)), 0, -2);
$condition = DBA::mergeConditions($condition, array_merge(["`uri-id` IN (SELECT `uri-id` FROM `post-tag` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` WHERE `post-tag`.`type` = 1 AND `name` IN (" . $placeholders . "))"], $search));
}
if (!empty($channel->excludeTags)) {
$search = explode(',', mb_strtolower($channel->excludeTags));
$placeholders = substr(str_repeat("?, ", count($search)), 0, -2);
$condition = DBA::mergeConditions($condition, array_merge(["NOT `uri-id` IN (SELECT `uri-id` FROM `post-tag` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` WHERE `post-tag`.`type` = 1 AND `name` IN (" . $placeholders . "))"], $search));
}
if (!empty($channel->mediaType)) {
$condition = DBA::mergeConditions($condition, ["`media-type` & ?", $channel->mediaType]);
}
return $condition;
}
private function addLanguageCondition(int $uid, array $condition): array
{
$conditions = [];

View file

@ -38,7 +38,7 @@ class Channel extends ChannelModule
$o = '';
if ($this->update || $this->force) {
if ($this->timeline->isChannel($this->selectedTab)) {
if ($this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId())) {
$items = $this->getChannelItems();
} else {
$items = $this->getCommunityItems();

View file

@ -41,7 +41,7 @@ class Network extends NetworkModule
System::htmlUpdateExit($o);
}
if ($this->timeline->isChannel($this->selectedTab)) {
if ($this->timeline->isChannel($this->selectedTab, $this->session->getLocalUserId())) {
$items = $this->getChannelItems();
} elseif ($this->timeline->isCommunity($this->selectedTab)) {
$items = $this->getCommunityItems();