Now there are user defined channels
This commit is contained in:
parent
bc3bdf3cb0
commit
ed24d06e0c
12 changed files with 132 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2023.09-rc (Giant Rhubarb)
|
||||
-- DB_UPDATE_VERSION 1535
|
||||
-- DB_UPDATE_VERSION 1536
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ final class Channel extends Timeline
|
|||
* @param integer $uid
|
||||
* @return Timelines
|
||||
*/
|
||||
public function getForUser(int $uid): Timelines
|
||||
public function getTimelines(int $uid): Timelines
|
||||
{
|
||||
$language = User::getLanguageCode($uid);
|
||||
$languages = $this->l10n->getAvailableLanguages(true);
|
||||
|
@ -58,18 +58,11 @@ final class Channel extends Timeline
|
|||
new ChannelEntity(ChannelEntity::VIDEO, $this->l10n->t('Videos'), $this->l10n->t('Posts with videos'), 'v'),
|
||||
];
|
||||
|
||||
foreach ($this->channel->selectByUid($uid) as $channel) {
|
||||
$tabs[] = $channel;
|
||||
}
|
||||
|
||||
return new Timelines($tabs);
|
||||
}
|
||||
|
||||
public function isTimeline(string $selectedTab, int $uid): bool
|
||||
public function isTimeline(string $selectedTab): bool
|
||||
{
|
||||
if (is_numeric($selectedTab) && $uid && $this->channel->existsById($selectedTab, $uid)) {
|
||||
return true;
|
||||
}
|
||||
return in_array($selectedTab, [ChannelEntity::WHATSHOT, ChannelEntity::FORYOU, ChannelEntity::FOLLOWERS, ChannelEntity::SHARERSOFSHARERS, ChannelEntity::IMAGE, ChannelEntity::VIDEO, ChannelEntity::AUDIO, ChannelEntity::LANGUAGE]);
|
||||
}
|
||||
}
|
||||
|
|
56
src/Content/Conversation/Factory/UserDefinedChannel.php
Normal file
56
src/Content/Conversation/Factory/UserDefinedChannel.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Content\Conversation\Factory;
|
||||
|
||||
use Friendica\Content\Conversation\Collection\Timelines;
|
||||
use Friendica\Content\Conversation\Repository\Channel as ChannelRepository;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
final class UserDefinedChannel extends Timeline
|
||||
{
|
||||
public function __construct(ChannelRepository $channel, L10n $l10n, LoggerInterface $logger, IManageConfigValues $config)
|
||||
{
|
||||
parent::__construct($channel, $l10n, $logger, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* List of available user defined channels
|
||||
*
|
||||
* @param integer $uid
|
||||
* @return Timelines
|
||||
*/
|
||||
public function getForUser(int $uid): Timelines
|
||||
{
|
||||
foreach ($this->channel->selectByUid($uid) as $channel) {
|
||||
$tabs[] = $channel;
|
||||
}
|
||||
|
||||
return new Timelines($tabs);
|
||||
}
|
||||
|
||||
public function isTimeline(string $selectedTab, int $uid): bool
|
||||
{
|
||||
return is_numeric($selectedTab) && $uid && $this->channel->existsById($selectedTab, $uid);
|
||||
}
|
||||
}
|
|
@ -568,7 +568,13 @@ class Widget
|
|||
}
|
||||
}
|
||||
|
||||
foreach (DI::ChannelFactory()->getForUser($uid) as $channel) {
|
||||
foreach (DI::ChannelFactory()->getTimelines($uid) as $channel) {
|
||||
if (empty($enabled) || in_array($channel->code, $enabled)) {
|
||||
$channels[] = ['ref' => $channel->code, 'name' => $channel->label];
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DI::UserDefinedChannelFactory()->getForUser($uid) as $channel) {
|
||||
if (empty($enabled) || in_array($channel->code, $enabled)) {
|
||||
$channels[] = ['ref' => $channel->code, 'name' => $channel->label];
|
||||
}
|
||||
|
|
|
@ -571,6 +571,14 @@ abstract class DI
|
|||
return self::$dice->create(Content\Conversation\Factory\Channel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Content\Conversation\Factory\UserDefinedChannel
|
||||
*/
|
||||
public static function UserDefinedChannelFactory()
|
||||
{
|
||||
return self::$dice->create(Content\Conversation\Factory\UserDefinedChannel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Content\Conversation\Factory\Network
|
||||
*/
|
||||
|
|
|
@ -26,11 +26,13 @@ use Friendica\App\Mode;
|
|||
use Friendica\Content\BoundariesPager;
|
||||
use Friendica\Content\Conversation;
|
||||
use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
|
||||
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
|
||||
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
|
||||
use Friendica\Content\Conversation\Repository\Channel as ChannelRepository;
|
||||
use Friendica\Content\Conversation\Factory\Channel as ChannelFactory;
|
||||
use Friendica\Content\Conversation\Factory\Community as CommunityFactory;
|
||||
use Friendica\Content\Conversation\Factory\Network as NetworkFactory;
|
||||
use Friendica\Content\Conversation\Factory\UserDefinedChannel;
|
||||
use Friendica\Content\Feature;
|
||||
use Friendica\Content\Nav;
|
||||
use Friendica\Content\Text\HTML;
|
||||
|
@ -62,22 +64,25 @@ class Channel extends Timeline
|
|||
protected $systemMessages;
|
||||
/** @var ChannelFactory */
|
||||
protected $channel;
|
||||
/** @var UserDefinedChannelFactory */
|
||||
protected $userDefinedChannel;
|
||||
/** @var CommunityFactory */
|
||||
protected $community;
|
||||
/** @var NetworkFactory */
|
||||
protected $networkFactory;
|
||||
|
||||
public function __construct(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 = [])
|
||||
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 = [])
|
||||
{
|
||||
parent::__construct($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->timeline = $timeline;
|
||||
$this->conversation = $conversation;
|
||||
$this->page = $page;
|
||||
$this->systemMessages = $systemMessages;
|
||||
//$this->channel = $channelFactory;
|
||||
$this->community = $community;
|
||||
$this->networkFactory = $network;
|
||||
$this->timeline = $timeline;
|
||||
$this->conversation = $conversation;
|
||||
$this->page = $page;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->channel = $channelFactory;
|
||||
$this->community = $community;
|
||||
$this->networkFactory = $network;
|
||||
$this->userDefinedChannel = $userDefinedChannel;
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
|
@ -100,7 +105,8 @@ class Channel extends Timeline
|
|||
}
|
||||
|
||||
if (empty($request['mode']) || ($request['mode'] != 'raw')) {
|
||||
$tabs = $this->getTabArray($this->channel->getForUser($this->session->getLocalUserId()), 'channel');
|
||||
$tabs = $this->getTabArray($this->channel->getTimelines($this->session->getLocalUserId()), 'channel');
|
||||
$tabs = array_merge($tabs, $this->getTabArray($this->userDefinedChannel->getForUser($this->session->getLocalUserId()), 'channel'));
|
||||
$tabs = array_merge($tabs, $this->getTabArray($this->community->getTimelines(true), 'channel'));
|
||||
|
||||
$tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
|
||||
|
@ -122,7 +128,7 @@ class Channel extends Timeline
|
|||
$o .= $this->conversation->statusEditor([], 0, true);
|
||||
}
|
||||
|
||||
if ($this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
if ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
$items = $this->getChannelItems();
|
||||
$order = 'created';
|
||||
} else {
|
||||
|
@ -168,7 +174,7 @@ class Channel extends Timeline
|
|||
$this->selectedTab = ChannelEntity::FORYOU;
|
||||
}
|
||||
|
||||
if (!$this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) {
|
||||
if (!$this->channel->isTimeline($this->selectedTab) && !$this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) {
|
||||
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ use Friendica\Content\Conversation\Entity\Network as NetworkEntity;
|
|||
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
|
||||
use Friendica\Content\Conversation\Repository\Channel;
|
||||
use Friendica\Content\Conversation\Factory\Channel as ChannelFactory;
|
||||
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
|
||||
use Friendica\Content\Conversation\Factory\Community as CommunityFactory;
|
||||
use Friendica\Content\Conversation\Factory\Network as NetworkFactory;
|
||||
use Friendica\Content\Feature;
|
||||
|
@ -101,23 +102,26 @@ class Network extends Timeline
|
|||
protected $timeline;
|
||||
/** @var ChannelFactory */
|
||||
protected $channel;
|
||||
/** @var UserDefinedChannelFactory */
|
||||
protected $userDefinedChannel;
|
||||
/** @var CommunityFactory */
|
||||
protected $community;
|
||||
/** @var NetworkFactory */
|
||||
protected $networkFactory;
|
||||
|
||||
public function __construct(NetworkFactory $network, CommunityFactory $community, ChannelFactory $channelFactory, 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 = [])
|
||||
public function __construct(UserDefinedChannelFactory $userDefinedChannel, NetworkFactory $network, CommunityFactory $community, ChannelFactory $channelFactory, 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($channel, $mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->app = $app;
|
||||
$this->timeline = $timeline;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->conversation = $conversation;
|
||||
$this->page = $page;
|
||||
$this->channel = $channelFactory;
|
||||
$this->community = $community;
|
||||
$this->networkFactory = $network;
|
||||
$this->app = $app;
|
||||
$this->timeline = $timeline;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->conversation = $conversation;
|
||||
$this->page = $page;
|
||||
$this->channel = $channelFactory;
|
||||
$this->community = $community;
|
||||
$this->networkFactory = $network;
|
||||
$this->userDefinedChannel = $userDefinedChannel;
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
|
@ -135,7 +139,7 @@ class Network extends Timeline
|
|||
|
||||
$o = '';
|
||||
|
||||
if ($this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
if ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
$items = $this->getChannelItems();
|
||||
} elseif ($this->community->isTimeline($this->selectedTab)) {
|
||||
$items = $this->getCommunityItems();
|
||||
|
@ -282,7 +286,8 @@ class Network extends Timeline
|
|||
|
||||
$network_timelines = $this->pConfig->get($this->session->getLocalUserId(), 'system', 'network_timelines', []);
|
||||
if (!empty($network_timelines)) {
|
||||
$tabs = array_merge($tabs, $this->getTabArray($this->channel->getForUser($this->session->getLocalUserId()), 'network', 'channel'));
|
||||
$tabs = array_merge($tabs, $this->getTabArray($this->channel->getTimelines($this->session->getLocalUserId()), 'network', 'channel'));
|
||||
$tabs = array_merge($tabs, $this->getTabArray($this->userDefinedChannel->getForUser($this->session->getLocalUserId()), 'network', 'channel'));
|
||||
$tabs = array_merge($tabs, $this->getTabArray($this->community->getTimelines(true), 'network', 'channel'));
|
||||
}
|
||||
|
||||
|
@ -316,11 +321,11 @@ class Network extends Timeline
|
|||
|
||||
if (!$this->selectedTab) {
|
||||
$this->selectedTab = self::getTimelineOrderBySession($this->session, $this->pConfig);
|
||||
} elseif (!$this->networkFactory->isTimeline($this->selectedTab) && !$this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) {
|
||||
} elseif (!$this->networkFactory->isTimeline($this->selectedTab) && !$this->channel->isTimeline($this->selectedTab) && !$this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) && !$this->community->isTimeline($this->selectedTab)) {
|
||||
throw new HTTPException\BadRequestException($this->l10n->t('Network feed not available.'));
|
||||
}
|
||||
|
||||
if (($this->network || $this->circleId || $this->groupContactId) && ($this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) || $this->community->isTimeline($this->selectedTab))) {
|
||||
if (($this->network || $this->circleId || $this->groupContactId) && ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId()) || $this->community->isTimeline($this->selectedTab))) {
|
||||
$this->selectedTab = NetworkEntity::RECEIVED;
|
||||
}
|
||||
|
||||
|
@ -345,7 +350,7 @@ class Network extends Timeline
|
|||
$this->mention = false;
|
||||
} elseif (in_array($this->selectedTab, [NetworkEntity::RECEIVED, NetworkEntity::STAR]) || $this->community->isTimeline($this->selectedTab)) {
|
||||
$this->order = 'received';
|
||||
} elseif (($this->selectedTab == NetworkEntity::CREATED) || $this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
} elseif (($this->selectedTab == NetworkEntity::CREATED) || $this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
$this->order = 'created';
|
||||
} else {
|
||||
$this->order = 'commented';
|
||||
|
|
|
@ -26,6 +26,7 @@ use Friendica\App\Mode;
|
|||
use Friendica\BaseModule;
|
||||
use Friendica\Content\Conversation\Collection\Timelines;
|
||||
use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
|
||||
use Friendica\Content\Conversation\Entity\UserDefinedChannel as UserDefinedChannelEntity;
|
||||
use Friendica\Content\Conversation\Repository\Channel;
|
||||
use Friendica\Core\Cache\Capability\ICanCache;
|
||||
use Friendica\Core\Cache\Enum\Duration;
|
||||
|
|
|
@ -28,6 +28,7 @@ use Friendica\Content\Conversation\Factory\Channel as ChannelFactory;
|
|||
use Friendica\Content\Conversation\Factory\Community as CommunityFactory;
|
||||
use Friendica\Content\Conversation\Factory\Network as NetworkFactory;
|
||||
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
|
||||
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
|
@ -58,6 +59,8 @@ class Display extends BaseSettings
|
|||
private $systemMessages;
|
||||
/** @var ChannelFactory */
|
||||
protected $channel;
|
||||
/** @var UserDefinedChannelFactory */
|
||||
protected $userDefinedChannel;
|
||||
/** @var CommunityFactory */
|
||||
protected $community;
|
||||
/** @var NetworkFactory */
|
||||
|
@ -65,18 +68,19 @@ class Display extends BaseSettings
|
|||
/** @var TimelineFactory */
|
||||
protected $timeline;
|
||||
|
||||
public function __construct(NetworkFactory $network, CommunityFactory $community, ChannelFactory $channel, TimelineFactory $timeline, SystemMessages $systemMessages, App $app, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
public function __construct(UserDefinedChannelFactory $userDefinedChannel, NetworkFactory $network, CommunityFactory $community, ChannelFactory $channel, TimelineFactory $timeline, SystemMessages $systemMessages, App $app, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->config = $config;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->app = $app;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->timeline = $timeline;
|
||||
$this->channel = $channel;
|
||||
$this->community = $community;
|
||||
$this->network = $network;
|
||||
$this->config = $config;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->app = $app;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->timeline = $timeline;
|
||||
$this->channel = $channel;
|
||||
$this->community = $community;
|
||||
$this->network = $network;
|
||||
$this->userDefinedChannel = $userDefinedChannel;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
|
@ -349,7 +353,11 @@ class Display extends BaseSettings
|
|||
return new Timelines($timelines);
|
||||
}
|
||||
|
||||
foreach ($this->channel->getForUser($uid) as $channel) {
|
||||
foreach ($this->channel->getTimelines($uid) as $channel) {
|
||||
$timelines[] = $channel;
|
||||
}
|
||||
|
||||
foreach ($this->userDefinedChannel->getForUser($uid) as $channel) {
|
||||
$timelines[] = $channel;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class Channel extends ChannelModule
|
|||
|
||||
$o = '';
|
||||
if ($this->update || $this->force) {
|
||||
if ($this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
if ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
$items = $this->getChannelItems();
|
||||
} else {
|
||||
$items = $this->getCommunityItems();
|
||||
|
|
|
@ -41,7 +41,7 @@ class Network extends NetworkModule
|
|||
System::htmlUpdateExit($o);
|
||||
}
|
||||
|
||||
if ($this->channel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
if ($this->channel->isTimeline($this->selectedTab) || $this->userDefinedChannel->isTimeline($this->selectedTab, $this->session->getLocalUserId())) {
|
||||
$items = $this->getChannelItems();
|
||||
} elseif ($this->community->isTimeline($this->selectedTab)) {
|
||||
$items = $this->getCommunityItems();
|
||||
|
|
|
@ -56,7 +56,7 @@ use Friendica\Database\DBA;
|
|||
|
||||
// This file is required several times during the test in DbaDefinition which justifies this condition
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1535);
|
||||
define('DB_UPDATE_VERSION', 1536);
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
Loading…
Reference in a new issue