]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Settings/Display.php
Merge branch 'friendica:2023.09-rc' into Leftovers-from-PR-#13339
[friendica.git] / src / Module / Settings / Display.php
index bbae7d599069e47fb4a97af9ab64685f78038dd7..b5dbf01eb810161a3e9022c8eca2cdaf369a22be 100644 (file)
 namespace Friendica\Module\Settings;
 
 use Friendica\App;
+use Friendica\Content\Conversation\Collection\Timelines;
 use Friendica\Content\Text\BBCode;
+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\Repository;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
@@ -52,18 +57,30 @@ class Display extends BaseSettings
        private $app;
        /** @var SystemMessages */
        private $systemMessages;
+       /** @var ChannelFactory */
+       protected $channel;
+       /** @var Repository\UserDefinedChannel */
+       protected $userDefinedChannel;
+       /** @var CommunityFactory */
+       protected $community;
+       /** @var NetworkFactory */
+       protected $network;
        /** @var TimelineFactory */
        protected $timeline;
 
-       public function __construct(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(Repository\UserDefinedChannel $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->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 = [])
@@ -240,19 +257,18 @@ class Display extends BaseSettings
                        BBCode::PREVIEW_LARGE    => $this->t('Large Image'),
                ];
 
-               $bookmarked_timelines = $this->pConfig->get($uid, 'system', 'network_timelines', array_keys($this->getAvailableTimelines($uid, true)));
-               $enabled_timelines    = $this->pConfig->get($uid, 'system', 'enabled_timelines', array_keys($this->getAvailableTimelines($uid, false)));
-
+               $bookmarked_timelines = $this->pConfig->get($uid, 'system', 'network_timelines', $this->getAvailableTimelines($uid, true)->column('code'));
+               $enabled_timelines    = $this->pConfig->get($uid, 'system', 'enabled_timelines', $this->getAvailableTimelines($uid, false)->column('code'));
                $channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
                $languages         = $this->l10n->getAvailableLanguages(true);
 
                $timelines = [];
-               foreach ($this->getAvailableTimelines($uid) as $code => $timeline) {
+               foreach ($this->getAvailableTimelines($uid) as $timeline) {
                        $timelines[] = [
-                               'label'        => $timeline['label'],
-                               'description'  => $timeline['description'],
-                               'enable'       => ["enable[$code]", '', in_array($code, $enabled_timelines)],
-                               'bookmark'     => ["bookmark[$code]", '', in_array($code, $bookmarked_timelines)],
+                               'label'        => $timeline->label,
+                               'description'  => $timeline->description,
+                               'enable'       => ["enable[{$timeline->code}]", '', in_array($timeline->code, $enabled_timelines)],
+                               'bookmark'     => ["bookmark[{$timeline->code}]", '', in_array($timeline->code, $bookmarked_timelines)],
                        ];
                }
 
@@ -325,26 +341,30 @@ class Display extends BaseSettings
                ]);
        }
 
-       private function getAvailableTimelines(int $uid, bool $only_network = false): array
+       private function getAvailableTimelines(int $uid, bool $only_network = false): Timelines
        {
                $timelines = [];
 
-               foreach ($this->timeline->getNetworkFeeds('') as $channel) {
-                       $timelines[$channel->code] = ['label' => $channel->label, 'description' => $channel->description];
+               foreach ($this->network->getTimelines('') as $channel) {
+                       $timelines[] = $channel;
                }
 
                if ($only_network) {
-                       return $timelines;
+                       return new Timelines($timelines);
+               }
+
+               foreach ($this->channel->getTimelines($uid) as $channel) {
+                       $timelines[] = $channel;
                }
 
-               foreach ($this->timeline->getChannelsForUser($uid) as $channel) {
-                       $timelines[$channel->code] = ['label' => $channel->label, 'description' => $channel->description];
+               foreach ($this->userDefinedChannel->selectByUid($uid) as $channel) {
+                       $timelines[] = $channel;
                }
 
-               foreach ($this->timeline->getCommunities(true) as $community) {
-                       $timelines[$community->code] = ['label' => $community->label, 'description' => $community->description];
+               foreach ($this->community->getTimelines(true) as $community) {
+                       $timelines[] = $community;
                }
 
-               return $timelines;
+               return new Timelines($timelines);
        }
 }