namespace Friendica\Module\Conversation;
-use Friendica\App;
+use Friendica\App\Arguments;
+use Friendica\App\BaseURL;
use Friendica\App\Mode;
use Friendica\BaseModule;
use Friendica\Content\Conversation\Collection\Timelines;
use Friendica\Model\Post\Engagement;
use Friendica\Model\Post\SearchIndex;
use Friendica\Module\Response;
+use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
/** @var string */
protected $network;
- /** @var App\Mode $mode */
+ /** @var Mode $mode */
protected $mode;
/** @var IHandleUserSessions */
protected $session;
/** @var UserDefinedChannel */
protected $channelRepository;
- 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 = [])
+ public function __construct(UserDefinedChannel $channel, Mode $mode, IHandleUserSessions $session, Database $database, IManagePersonalConfigValues $pConfig, IManageConfigValues $config, ICanCache $cache, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server = [], array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
/**
* Computes module parameters from the request and local configuration
*
- * @throws HTTPException\BadRequestException
- * @throws HTTPException\ForbiddenException
+ * @throws BadRequestException
+ * @throws ForbiddenException
*/
protected function parseRequest(array $request)
{
{
$table = 'post-engagement';
+ $condition = [];
+
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];
"`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND NOT `follows`) AND
(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND NOT `follows` AND `relation-thread-score` > ?) OR
`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `cid` = ? AND `relation-thread-score` > ?) OR
- ((`comments` >= ? OR `activities` >= ?) AND
- (`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `cid` = ? AND `relation-thread-score` > ?)) OR
+ ((`comments` >= ? OR `activities` >= ?) AND
+ (`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `cid` = ? AND `relation-thread-score` > ?)) OR
(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `relation-thread-score` > ?))))",
$cid, $cid, $this->getMedianRelationThreadScore($cid, 4), $cid, $this->getMedianRelationThreadScore($cid, 4),
- $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid, 0, $cid, 0
+ $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid, 0, $cid, 0
];
} elseif ($this->selectedTab == ChannelEntity::FOLLOWERS) {
$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);
if (!empty($channel->mediaType)) {
$condition = DBA::mergeConditions($condition, ["`media-type` & ?", $channel->mediaType]);
}
-
+
// For "addLanguageCondition" to work, the condition must not be empty
$condition = $this->addLanguageCondition($uid, $condition ?: ["true"], $channel->languages);
}
protected function getCommunityItems()
{
$items = $this->selectItems();
+ $key = '';
if ($this->selectedTab == Community::LOCAL) {
$maxpostperauthor = (int)$this->config->get('system', 'max_author_posts_community_page');
$maxpostperauthor = (int)$this->config->get('system', 'max_server_posts_community_page');
$key = 'author-gsid';
} else {
- $maxpostperauthor = 0;
+ $this->setItemsSeenByCondition([
+ 'unseen' => true,
+ 'uid' => $this->session->getLocalUserId(),
+ 'parent-uri-id' => array_column($items, 'uri-id')
+ ]);
+
+ return $items;
}
- if ($maxpostperauthor != 0) {
- $count = 1;
- $author_posts = [];
- $selected_items = [];
- while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
- $maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
- $minId = $items[array_key_first($items)]['received'];
- $maxId = $items[array_key_last($items)]['received'];
+ $count = 1;
+ $author_posts = [];
+ $selected_items = [];
- foreach ($items as $item) {
- $author_posts[$item[$key]][$item['uri-id']] = $item['received'];
+ while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
+ $maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
+ $minId = $items[array_key_first($items)]['received'];
+ $maxId = $items[array_key_last($items)]['received'];
+
+ foreach ($items as $item) {
+ $author_posts[$item[$key]][$item['uri-id']] = $item['received'];
+ }
+ foreach ($author_posts as $posts) {
+ if (count($posts) <= $maxposts) {
+ continue;
}
- foreach ($author_posts as $posts) {
- if (count($posts) <= $maxposts) {
- continue;
- }
- asort($posts);
- while (count($posts) > $maxposts) {
- $uri_id = array_key_first($posts);
- unset($posts[$uri_id]);
- unset($items[$uri_id]);
- }
+ asort($posts);
+ while (count($posts) > $maxposts) {
+ $uri_id = array_key_first($posts);
+ unset($posts[$uri_id]);
+ unset($items[$uri_id]);
}
- $selected_items = array_merge($selected_items, $items);
+ }
+ $selected_items = array_merge($selected_items, $items);
- // If we're looking at a "previous page", the lookup continues forward in time because the list is
- // sorted in chronologically decreasing order
- if (!empty($this->minId)) {
- $this->minId = $minId;
- } else {
- // In any other case, the lookup continues backwards in time
- $this->maxId = $maxId;
- }
+ // If we're looking at a "previous page", the lookup continues forward in time because the list is
+ // sorted in chronologically decreasing order
+ if (!empty($this->minId)) {
+ $this->minId = $minId;
+ } else {
+ // In any other case, the lookup continues backwards in time
+ $this->maxId = $maxId;
+ }
- if (count($selected_items) < $this->itemsPerPage) {
- $items = $this->selectItems();
- }
+ if (count($selected_items) < $this->itemsPerPage) {
+ $items = $this->selectItems();
}
- } else {
- $selected_items = $items;
}
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
}
$uriids = array_keys($items);
-
+
foreach (Post\Counts::get(['parent-uri-id' => $uriids, 'verb' => Activity::POST]) as $count) {
$items[$count['parent-uri-id']]['comments'] += $count['count'];
}