mirror of
https://github.com/friendica/friendica
synced 2025-04-25 20:30:11 +00:00
Refactor Conversation Timeline
This commit is contained in:
parent
c79f3cde22
commit
ec0c3bf96e
2 changed files with 60 additions and 49 deletions
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
namespace Friendica\Module\Conversation;
|
namespace Friendica\Module\Conversation;
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App\Arguments;
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\App\Mode;
|
use Friendica\App\Mode;
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Content\Conversation\Collection\Timelines;
|
use Friendica\Content\Conversation\Collection\Timelines;
|
||||||
|
@ -31,6 +32,8 @@ use Friendica\Model\Post;
|
||||||
use Friendica\Model\Post\Engagement;
|
use Friendica\Model\Post\Engagement;
|
||||||
use Friendica\Model\Post\SearchIndex;
|
use Friendica\Model\Post\SearchIndex;
|
||||||
use Friendica\Module\Response;
|
use Friendica\Module\Response;
|
||||||
|
use Friendica\Network\HTTPException\BadRequestException;
|
||||||
|
use Friendica\Network\HTTPException\ForbiddenException;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
@ -67,7 +70,7 @@ class Timeline extends BaseModule
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $network;
|
protected $network;
|
||||||
|
|
||||||
/** @var App\Mode $mode */
|
/** @var Mode $mode */
|
||||||
protected $mode;
|
protected $mode;
|
||||||
/** @var IHandleUserSessions */
|
/** @var IHandleUserSessions */
|
||||||
protected $session;
|
protected $session;
|
||||||
|
@ -82,7 +85,7 @@ class Timeline extends BaseModule
|
||||||
/** @var UserDefinedChannel */
|
/** @var UserDefinedChannel */
|
||||||
protected $channelRepository;
|
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);
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
|
@ -98,8 +101,8 @@ class Timeline extends BaseModule
|
||||||
/**
|
/**
|
||||||
* Computes module parameters from the request and local configuration
|
* Computes module parameters from the request and local configuration
|
||||||
*
|
*
|
||||||
* @throws HTTPException\BadRequestException
|
* @throws BadRequestException
|
||||||
* @throws HTTPException\ForbiddenException
|
* @throws ForbiddenException
|
||||||
*/
|
*/
|
||||||
protected function parseRequest(array $request)
|
protected function parseRequest(array $request)
|
||||||
{
|
{
|
||||||
|
@ -308,6 +311,8 @@ class Timeline extends BaseModule
|
||||||
{
|
{
|
||||||
$table = 'post-engagement';
|
$table = 'post-engagement';
|
||||||
|
|
||||||
|
$condition = [];
|
||||||
|
|
||||||
if ($this->selectedTab == ChannelEntity::WHATSHOT) {
|
if ($this->selectedTab == ChannelEntity::WHATSHOT) {
|
||||||
if (!is_null($this->accountType)) {
|
if (!is_null($this->accountType)) {
|
||||||
$condition = ["(`comments` > ? OR `activities` > ?) AND `contact-type` = ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $this->accountType];
|
$condition = ["(`comments` > ? OR `activities` > ?) AND `contact-type` = ?", $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $this->accountType];
|
||||||
|
@ -684,6 +689,7 @@ class Timeline extends BaseModule
|
||||||
protected function getCommunityItems()
|
protected function getCommunityItems()
|
||||||
{
|
{
|
||||||
$items = $this->selectItems();
|
$items = $this->selectItems();
|
||||||
|
$key = '';
|
||||||
|
|
||||||
if ($this->selectedTab == Community::LOCAL) {
|
if ($this->selectedTab == Community::LOCAL) {
|
||||||
$maxpostperauthor = (int)$this->config->get('system', 'max_author_posts_community_page');
|
$maxpostperauthor = (int)$this->config->get('system', 'max_author_posts_community_page');
|
||||||
|
@ -692,49 +698,52 @@ class Timeline extends BaseModule
|
||||||
$maxpostperauthor = (int)$this->config->get('system', 'max_server_posts_community_page');
|
$maxpostperauthor = (int)$this->config->get('system', 'max_server_posts_community_page');
|
||||||
$key = 'author-gsid';
|
$key = 'author-gsid';
|
||||||
} else {
|
} 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) {
|
$count = 1;
|
||||||
$maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
|
$author_posts = [];
|
||||||
$minId = $items[array_key_first($items)]['received'];
|
$selected_items = [];
|
||||||
$maxId = $items[array_key_last($items)]['received'];
|
|
||||||
|
|
||||||
foreach ($items as $item) {
|
while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
|
||||||
$author_posts[$item[$key]][$item['uri-id']] = $item['received'];
|
$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) {
|
asort($posts);
|
||||||
if (count($posts) <= $maxposts) {
|
while (count($posts) > $maxposts) {
|
||||||
continue;
|
$uri_id = array_key_first($posts);
|
||||||
}
|
unset($posts[$uri_id]);
|
||||||
asort($posts);
|
unset($items[$uri_id]);
|
||||||
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);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
$selected_items = array_merge($selected_items, $items);
|
||||||
$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 (count($selected_items) < $this->itemsPerPage) {
|
||||||
|
$items = $this->selectItems();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
|
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
|
||||||
|
|
|
@ -565,6 +565,8 @@ class Probe
|
||||||
$nick = '';
|
$nick = '';
|
||||||
$addr = '';
|
$addr = '';
|
||||||
|
|
||||||
|
$path_parts = [];
|
||||||
|
|
||||||
if (array_key_exists('path', $parts) && trim(strval($parts['path']), '/') !== '') {
|
if (array_key_exists('path', $parts) && trim(strval($parts['path']), '/') !== '') {
|
||||||
$path_parts = explode('/', trim($parts['path'], '/'));
|
$path_parts = explode('/', trim($parts['path'], '/'));
|
||||||
|
|
||||||
|
@ -578,7 +580,7 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($webfinger) && empty($lrdd)) {
|
if (empty($webfinger) && empty($lrdd)) {
|
||||||
while (empty($lrdd) && empty($webfinger) && (sizeof($path_parts) > 1)) {
|
while (empty($lrdd) && empty($webfinger) && (count($path_parts) > 1)) {
|
||||||
$host .= '/' . array_shift($path_parts);
|
$host .= '/' . array_shift($path_parts);
|
||||||
$baseurl = $parts['scheme'] . '://' . $host;
|
$baseurl = $parts['scheme'] . '://' . $host;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue