X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FConversation%2FTimeline.php;h=725634eb0920ffd68e5ab27ba6962aa8979af1ca;hb=3f2b0b9422915529a0ea585aa4325b6d2f2f65cd;hp=2ee98527b26f6932674d1d483d612a7109a1e7ae;hpb=34521c228bd69609fa4f475bb2e2e826723fcc16;p=friendica.git diff --git a/src/Module/Conversation/Timeline.php b/src/Module/Conversation/Timeline.php index 2ee98527b2..725634eb09 100644 --- a/src/Module/Conversation/Timeline.php +++ b/src/Module/Conversation/Timeline.php @@ -25,8 +25,8 @@ use Friendica\App; 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\Content\Conversation\Entity\Channel as ChannelEntity; +use Friendica\Content\Conversation\Repository\UserDefinedChannel; use Friendica\Core\Cache\Capability\ICanCache; use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Config\Capability\IManageConfigValues; @@ -80,20 +80,20 @@ class Timeline extends BaseModule protected $config; /** @var ICanCache */ protected $cache; - /** @var Channel */ - protected $channel; + /** @var UserDefinedChannel */ + protected $channelRepository; - 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 = []) + public function __construct(UserDefinedChannel $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; - $this->pConfig = $pConfig; - $this->config = $config; - $this->cache = $cache; + $this->channelRepository = $channel; + $this->mode = $mode; + $this->session = $session; + $this->database = $database; + $this->pConfig = $pConfig; + $this->config = $config; + $this->cache = $cache; } /** @@ -269,13 +269,13 @@ class Timeline extends BaseModule { $uid = $this->session->getLocalUserId(); - if ($this->selectedTab == TimelineEntity::WHATSHOT) { + if ($this->selectedTab == ChannelEntity::WHATSHOT) { if (!is_null($this->accountType)) { $condition = ["(`comments` > ? OR `activities` > ?) AND `contact-type` = ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $this->accountType]; } else { $condition = ["(`comments` > ? OR `activities` > ?) AND `contact-type` != ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), Contact::TYPE_COMMUNITY]; } - } elseif ($this->selectedTab == TimelineEntity::FORYOU) { + } elseif ($this->selectedTab == ChannelEntity::FORYOU) { $cid = Contact::getPublicIdByUserId($uid); $condition = [ @@ -285,9 +285,9 @@ class Timeline extends BaseModule $cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid, $uid, Contact\User::FREQUENCY_ALWAYS ]; - } elseif ($this->selectedTab == TimelineEntity::FOLLOWERS) { + } elseif ($this->selectedTab == ChannelEntity::FOLLOWERS) { $condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER]; - } elseif ($this->selectedTab == TimelineEntity::SHARERSOFSHARERS) { + } elseif ($this->selectedTab == ChannelEntity::SHARERSOFSHARERS) { $cid = Contact::getPublicIdByUserId($uid); // @todo Suggest posts from contacts that are followed most by our followers @@ -297,19 +297,19 @@ class Timeline extends BaseModule AND NOT `cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?))", DateTimeFormat::utc('now - ' . $this->config->get('channel', 'sharer_interaction_days') . ' day'), $cid, $this->getMedianRelationThreadScore($cid, 4), $cid ]; - } elseif ($this->selectedTab == TimelineEntity::IMAGE) { + } elseif ($this->selectedTab == ChannelEntity::IMAGE) { $condition = ["`media-type` & ?", 1]; - } elseif ($this->selectedTab == TimelineEntity::VIDEO) { + } elseif ($this->selectedTab == ChannelEntity::VIDEO) { $condition = ["`media-type` & ?", 2]; - } elseif ($this->selectedTab == TimelineEntity::AUDIO) { + } elseif ($this->selectedTab == ChannelEntity::AUDIO) { $condition = ["`media-type` & ?", 4]; - } elseif ($this->selectedTab == TimelineEntity::LANGUAGE) { - $condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", $this->l10n->convertCodeForLanguageDetection(User::getLanguageCode($uid))]; + } elseif ($this->selectedTab == ChannelEntity::LANGUAGE) { + $condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", User::getLanguageCode($uid)]; } elseif (is_numeric($this->selectedTab)) { $condition = $this->getUserChannelConditions($this->selectedTab, $this->session->getLocalUserId()); } - if ($this->selectedTab != TimelineEntity::LANGUAGE) { + if ($this->selectedTab != ChannelEntity::LANGUAGE) { $condition = $this->addLanguageCondition($uid, $condition); } @@ -317,7 +317,7 @@ class Timeline extends BaseModule $condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed` OR `is-blocked` OR `channel-frequency` = ?))", $uid, Contact\User::FREQUENCY_NEVER]); - if (($this->selectedTab != TimelineEntity::WHATSHOT) && !is_null($this->accountType)) { + if (($this->selectedTab != ChannelEntity::WHATSHOT) && !is_null($this->accountType)) { $condition = DBA::mergeConditions($condition, ['contact-type' => $this->accountType]); } @@ -346,6 +346,10 @@ class Timeline extends BaseModule $items = []; $result = $this->database->select('post-engagement', ['uri-id', 'created', 'owner-id', 'comments', 'activities'], $condition, $params); + if ($this->database->errorNo()) { + throw new \Exception($this->database->errorMessage(), $this->database->errorNo()); + } + while ($item = $this->database->fetch($result)) { $items[$item['uri-id']] = $item; } @@ -368,7 +372,7 @@ class Timeline extends BaseModule private function getUserChannelConditions(int $id, int $uid): array { - $channel = $this->channel->selectById($id, $uid); + $channel = $this->channelRepository->selectById($id, $uid); if (empty($channel)) { return []; } @@ -417,7 +421,6 @@ class Timeline extends BaseModule { $conditions = []; $languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]); - $languages = $this->l10n->convertForLanguageDetection($languages); foreach ($languages as $language) { $conditions[] = "JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?"; $condition[] = $language;