Merge pull request #13417 from annando/timelines

Network, Channels and Community are children of timeline
This commit is contained in:
Hypolite Petovan 2023-09-09 18:06:31 -04:00 committed by GitHub
commit 8452d3fdf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 1451 additions and 1241 deletions

View File

@ -495,7 +495,9 @@ class Conversation
. (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '')
. (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '')
. (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '')
. (!empty($_GET['channel']) ? '&channel=' . rawurlencode($_GET['channel']) : '')
. (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
. (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
. "'; </script>\r\n";
}
} elseif ($mode === self::MODE_PROFILE) {
@ -536,7 +538,7 @@ class Conversation
if (!$update) {
$live_update_div = '<div id="live-channel"></div>' . "\r\n"
. "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 10)
. "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 8)
. '?f='
. (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
. (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
@ -930,7 +932,8 @@ class Conversation
continue;
}
if (in_array($row['author-gsid'], $ignoredGsids)
if (
in_array($row['author-gsid'], $ignoredGsids)
|| in_array($row['owner-gsid'], $ignoredGsids)
|| in_array($row['causer-gsid'], $ignoredGsids)
) {

View File

@ -23,6 +23,6 @@ namespace Friendica\Content\Conversation\Collection;
use Friendica\BaseCollection;
class Channels extends BaseCollection
class Timelines extends BaseCollection
{
}

View File

@ -26,8 +26,9 @@ namespace Friendica\Content\Conversation\Entity;
* @property-read string $label Channel label
* @property-read string $description Channel description
* @property-read string $accessKey Access key
* @property-read string $path Path
*/
final class Channel extends \Friendica\BaseEntity
final class Timeline extends \Friendica\BaseEntity
{
const WHATSHOT = 'whatshot';
const FORYOU = 'foryou';
@ -37,6 +38,13 @@ final class Channel extends \Friendica\BaseEntity
const VIDEO = 'video';
const AUDIO = 'audio';
const LANGUAGE = 'language';
const LOCAL = 'local';
const GLOBAL = 'global';
const STAR = 'star';
const MENTION = 'mention';
const RECEIVED = 'received';
const COMMENTED = 'commented';
const CREATED = 'created';
/** @var string */
protected $code;
@ -46,12 +54,15 @@ final class Channel extends \Friendica\BaseEntity
protected $description;
/** @var string */
protected $accessKey;
/** @var string */
protected $path;
public function __construct(string $code, string $label, string $description, string $accessKey)
public function __construct(string $code, string $label, string $description, string $accessKey, string $path = null)
{
$this->code = $code;
$this->label = $label;
$this->description = $description;
$this->accessKey = $accessKey;
$this->path = $path;
}
}

View File

@ -1,65 +0,0 @@
<?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\Channels;
use Friendica\Model\User;
use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
use Friendica\Core\L10n;
use Psr\Log\LoggerInterface;
final class Channel extends \Friendica\BaseFactory
{
/** @var L10n */
protected $l10n;
public function __construct(L10n $l10n, LoggerInterface $logger)
{
parent::__construct($logger);
$this->l10n = $l10n;
}
/**
* List of available channels
*
* @param integer $uid
* @return array
*/
public function getForUser(int $uid): Channels
{
$language = User::getLanguageCode($uid);
$languages = $this->l10n->getAvailableLanguages(true);
$tabs = [
new ChannelEntity(ChannelEntity::FORYOU, $this->l10n->t('For you'), $this->l10n->t('Posts from contacts you interact with and who interact with you'), 'y'),
new ChannelEntity(ChannelEntity::WHATSHOT, $this->l10n->t('What\'s Hot'), $this->l10n->t('Posts with a lot of interactions'), 'h'),
new ChannelEntity(ChannelEntity::LANGUAGE, $languages[$language], $this->l10n->t('Posts in %s', $languages[$language]), 'g'),
new ChannelEntity(ChannelEntity::FOLLOWERS, $this->l10n->t('Followers'), $this->l10n->t('Posts from your followers that you don\'t follow'), 'f'),
new ChannelEntity(ChannelEntity::SHARERSOFSHARERS, $this->l10n->t('Sharers of sharers'), $this->l10n->t('Posts from accounts that are followed by accounts that you follow'), 'r'),
new ChannelEntity(ChannelEntity::IMAGE, $this->l10n->t('Images'), $this->l10n->t('Posts with images'), 'i'),
new ChannelEntity(ChannelEntity::AUDIO, $this->l10n->t('Audio'), $this->l10n->t('Posts with audio'), 'd'),
new ChannelEntity(ChannelEntity::VIDEO, $this->l10n->t('Videos'), $this->l10n->t('Posts with videos'), 'v'),
];
return new Channels($tabs);
}
}

View File

@ -0,0 +1,120 @@
<?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\Model\User;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Module\Conversation\Community;
use Psr\Log\LoggerInterface;
final class Timeline extends \Friendica\BaseFactory
{
/** @var L10n */
protected $l10n;
/** @var IManageConfigValues The config */
protected $config;
public function __construct(L10n $l10n, LoggerInterface $logger, IManageConfigValues $config)
{
parent::__construct($logger);
$this->l10n = $l10n;
$this->config = $config;
}
/**
* List of available channels
*
* @param integer $uid
* @return Timelines
*/
public function getChannelsForUser(int $uid): Timelines
{
$language = User::getLanguageCode($uid);
$languages = $this->l10n->getAvailableLanguages(true);
$tabs = [
new TimelineEntity(TimelineEntity::FORYOU, $this->l10n->t('For you'), $this->l10n->t('Posts from contacts you interact with and who interact with you'), 'y'),
new TimelineEntity(TimelineEntity::WHATSHOT, $this->l10n->t('What\'s Hot'), $this->l10n->t('Posts with a lot of interactions'), 'h'),
new TimelineEntity(TimelineEntity::LANGUAGE, $languages[$language], $this->l10n->t('Posts in %s', $languages[$language]), 'g'),
new TimelineEntity(TimelineEntity::FOLLOWERS, $this->l10n->t('Followers'), $this->l10n->t('Posts from your followers that you don\'t follow'), 'f'),
new TimelineEntity(TimelineEntity::SHARERSOFSHARERS, $this->l10n->t('Sharers of sharers'), $this->l10n->t('Posts from accounts that are followed by accounts that you follow'), 'r'),
new TimelineEntity(TimelineEntity::IMAGE, $this->l10n->t('Images'), $this->l10n->t('Posts with images'), 'i'),
new TimelineEntity(TimelineEntity::AUDIO, $this->l10n->t('Audio'), $this->l10n->t('Posts with audio'), 'd'),
new TimelineEntity(TimelineEntity::VIDEO, $this->l10n->t('Videos'), $this->l10n->t('Posts with videos'), 'v'),
];
return new Timelines($tabs);
}
/**
* List of available communities
*
* @param boolean $authenticated
* @return Timelines
*/
public function getCommunities(bool $authenticated): Timelines
{
$page_style = $this->config->get('system', 'community_page_style');
$tabs = [];
if (($authenticated || in_array($page_style, [Community::LOCAL_AND_GLOBAL, Community::LOCAL])) && empty($this->config->get('system', 'singleuser'))) {
$tabs[] = new TimelineEntity(TimelineEntity::LOCAL, $this->l10n->t('Local Community'), $this->l10n->t('Posts from local users on this server'), 'l');
}
if ($authenticated || in_array($page_style, [Community::LOCAL_AND_GLOBAL, Community::GLOBAL])) {
$tabs[] = new TimelineEntity(TimelineEntity::GLOBAL, $this->l10n->t('Global Community'), $this->l10n->t('Posts from users of the whole federated network'), 'g');
}
return new Timelines($tabs);
}
/**
* List of available network feeds
*
* @param string $command
* @return Timelines
*/
public function getNetworkFeeds(string $command): Timelines
{
$tabs = [
new TimelineEntity(TimelineEntity::COMMENTED, $this->l10n->t('Latest Activity'), $this->l10n->t('Sort by latest activity'), 'e', $command . '?' . http_build_query(['order' => 'commented'])),
new TimelineEntity(TimelineEntity::RECEIVED, $this->l10n->t('Latest Posts'), $this->l10n->t('Sort by post received date'), 't', $command . '?' . http_build_query(['order' => 'received'])),
new TimelineEntity(TimelineEntity::CREATED, $this->l10n->t('Latest Creation'), $this->l10n->t('Sort by post creation date'), 'q', $command . '?' . http_build_query(['order' => 'created'])),
new TimelineEntity(TimelineEntity::MENTION, $this->l10n->t('Personal'), $this->l10n->t('Posts that mention or involve you'), 'r', $command . '?' . http_build_query(['mention' => true])),
new TimelineEntity(TimelineEntity::STAR, $this->l10n->t('Starred'), $this->l10n->t('Favourite Posts'), 'm', $command . '?' . http_build_query(['star' => true])),
];
return new Timelines($tabs);
}
public function isCommunity(string $selectedTab): bool
{
return in_array($selectedTab, [TimelineEntity::LOCAL, TimelineEntity::GLOBAL]);
}
public function isChannel(string $selectedTab): bool
{
return in_array($selectedTab, [TimelineEntity::WHATSHOT, TimelineEntity::FORYOU, TimelineEntity::FOLLOWERS, TimelineEntity::SHARERSOFSHARERS, TimelineEntity::IMAGE, TimelineEntity::VIDEO, TimelineEntity::AUDIO, TimelineEntity::LANGUAGE]);
}
}

View File

@ -40,21 +40,21 @@ use Friendica\Network\HTTPException;
class Nav
{
private static $selected = [
'global' => null,
'community' => null,
'channel' => null,
'network' => null,
'home' => null,
'profiles' => null,
'global' => null,
'community' => null,
'channel' => null,
'network' => null,
'home' => null,
'profiles' => null,
'introductions' => null,
'notifications' => null,
'messages' => null,
'directory' => null,
'settings' => null,
'contacts' => null,
'delegation'=> null,
'calendar' => null,
'register' => null
'messages' => null,
'directory' => null,
'settings' => null,
'contacts' => null,
'delegation' => null,
'calendar' => null,
'register' => null
];
/**
@ -289,8 +289,6 @@ class Nav
$nav['community'] = ['community', $this->l10n->t('Community'), '', $this->l10n->t('Conversations on this and other servers')];
}
$nav['channel'] = ['channel', $this->l10n->t('Channels'), '', $this->l10n->t('Current posts, filtered by several rules')];
if ($this->session->getLocalUserId()) {
$nav['calendar'] = ['calendar', $this->l10n->t('Calendar'), '', $this->l10n->t('Calendar')];
}

View File

@ -547,4 +547,35 @@ class Widget
$accounttype
);
}
/**
* Get a list of all channels
*
* @param string $base
* @param string $channelname
* @param integer $uid
* @return string
*/
public static function channels(string $base, string $channelname, int $uid): string
{
$channels = [];
foreach (DI::TimelineFactory()->getChannelsForUser($uid) as $channel) {
$channels[] = ['ref' => $channel->code, 'name' => $channel->label];
}
foreach (DI::TimelineFactory()->getCommunities(true) as $community) {
$channels[] = ['ref' => $community->code, 'name' => $community->label];
}
return self::filter(
'channel',
DI::l10n()->t('Channels'),
'',
'',
$base,
$channels,
$channelname
);
}
}

View File

@ -547,6 +547,14 @@ abstract class DI
return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
}
/**
* @return Content\Conversation\Factory\Timeline
*/
public static function TimelineFactory()
{
return self::$dice->create(Content\Conversation\Factory\Timeline::class);
}
/**
* @return Contact\Introduction\Repository\Introduction
*/

View File

@ -28,8 +28,6 @@ use Friendica\Content\Nav;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;

View File

@ -23,83 +23,48 @@ namespace Friendica\Module\Conversation;
use Friendica\App;
use Friendica\App\Mode;
use Friendica\BaseModule;
use Friendica\Content\BoundariesPager;
use Friendica\Content\Conversation;
use Friendica\Content\Conversation\Entity\Channel as ChannelEntity;
use Friendica\Content\Conversation\Factory\Channel as ChannelFactory;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
use Friendica\Content\Widget\TrendingTags;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Model\Contact;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException;
use Friendica\Core\Session\Model\UserSession;
use Friendica\Database\Database;
use Friendica\Model\Item;
use Friendica\Module\Response;
use Friendica\Navigation\SystemMessages;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
class Channel extends BaseModule
class Channel extends Timeline
{
protected static $content;
protected static $accountTypeString;
protected static $accountType;
protected static $itemsPerPage;
protected static $min_id;
protected static $max_id;
protected static $item_id;
/** @var UserSession */
protected $session;
/** @var ICanCache */
protected $cache;
/** @var IManageConfigValues The config */
protected $config;
/** @var SystemMessages */
protected $systemMessages;
/** @var App\Page */
protected $page;
/** @var TimelineFactory */
protected $timeline;
/** @var Conversation */
protected $conversation;
/** @var App\Mode $mode */
protected $mode;
/** @var IManagePersonalConfigValues */
protected $pConfig;
/** @var Database */
protected $database;
/** @var ChannelFactory */
protected $channel;
/** @var App\Page */
protected $page;
/** @var SystemMessages */
protected $systemMessages;
public function __construct(ChannelFactory $channel, SystemMessages $systemMessages, Database $database, IManagePersonalConfigValues $pConfig, Mode $mode, Conversation $conversation, App\Page $page, IManageConfigValues $config, ICanCache $cache, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
public function __construct(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($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($mode, $session, $database, $pConfig, $config, $cache, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->channel = $channel;
$this->systemMessages = $systemMessages;
$this->database = $database;
$this->pConfig = $pConfig;
$this->mode = $mode;
$this->timeline = $timeline;
$this->conversation = $conversation;
$this->page = $page;
$this->config = $config;
$this->cache = $cache;
$this->session = $session;
$this->systemMessages = $systemMessages;
}
protected function content(array $request = []): string
@ -122,79 +87,49 @@ class Channel extends BaseModule
}
if (empty($request['mode']) || ($request['mode'] != 'raw')) {
$tabs = [];
foreach ($this->channel->getForUser($this->session->getLocalUserId()) as $tab) {
$tabs[] = [
'label' => $tab->label,
'url' => 'channel/' . $tab->code,
'sel' => self::$content == $tab->code ? 'active' : '',
'title' => $tab->description,
'id' => 'channel-' . $tab->code . '-tab',
'accesskey' => $tab->accessKey,
];
}
$tabs = $this->getTabArray($this->timeline->getChannelsForUser($this->session->getLocalUserId()), 'channel');
$tabs = array_merge($tabs, $this->getTabArray($this->timeline->getCommunities(true), 'channel'));
$tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
$o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
Nav::setSelected('channel');
$this->page['aside'] .= Widget::accountTypes('channel/' . self::$content, self::$accountTypeString);
$this->page['aside'] .= Widget::accountTypes('channel/' . $this->selectedTab, $this->accountTypeString);
if (!in_array(self::$content, [ChannelEntity::FOLLOWERS, ChannelEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
$path = self::$content;
if (!empty($this->parameters['accounttype'])) {
$path .= '/' . $this->parameters['accounttype'];
}
$query_parameters = [];
if (!empty($request['min_id'])) {
$query_parameters['min_id'] = $request['min_id'];
}
if (!empty($request['max_id'])) {
$query_parameters['max_id'] = $request['max_id'];
}
if (!empty($request['last_created'])) {
$query_parameters['max_id'] = $request['last_created'];
}
$path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
$path_no_sharer = $path . '?' . http_build_query(array_merge($query_parameters, ['no_sharer' => true]));
$this->page['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_sharer.tpl'), [
'$title' => $this->l10n->t('Own Contacts'),
'$path_all' => $path_all,
'$path_no_sharer' => $path_no_sharer,
'$no_sharer' => !empty($request['no_sharer']),
'$all' => $this->l10n->t('Include'),
'$no_sharer_label' => $this->l10n->t('Hide'),
'$base' => 'channel',
]);
if (!in_array($this->selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget('channel');
}
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML(self::$content);
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
}
// We need the editor here to be able to reshare an item.
$o .= $this->conversation->statusEditor([], 0, true);
}
$items = $this->getItems($request);
if ($this->timeline->isChannel($this->selectedTab)) {
$items = $this->getChannelItems();
$order = 'created';
} else {
$items = $this->getCommunityItems();
$order = 'commented';
}
if (!$this->database->isResult($items)) {
$this->systemMessages->addNotice($this->l10n->t('No results.'));
return $o;
}
$o .= $this->conversation->render($items, Conversation::MODE_CHANNEL, false, false, 'created', $this->session->getLocalUserId());
$o .= $this->conversation->render($items, Conversation::MODE_CHANNEL, false, false, $order, $this->session->getLocalUserId());
$pager = new BoundariesPager(
$this->l10n,
$this->args->getQueryString(),
$items[0]['created'],
$items[count($items) - 1]['created'],
self::$itemsPerPage
$items[0][$order],
$items[count($items) - 1][$order],
$this->itemsPerPage
);
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
@ -214,226 +149,16 @@ class Channel extends BaseModule
*/
protected function parseRequest(array $request)
{
self::$accountTypeString = $request['accounttype'] ?? $this->parameters['accounttype'] ?? '';
self::$accountType = User::getAccountTypeByString(self::$accountTypeString);
parent::parseRequest($request);
self::$content = $this->parameters['content'] ?? '';
if (!self::$content) {
self::$content = ChannelEntity::FORYOU;
if (!$this->selectedTab) {
$this->selectedTab = TimelineEntity::FORYOU;
}
if (!in_array(self::$content, [ChannelEntity::WHATSHOT, ChannelEntity::FORYOU, ChannelEntity::FOLLOWERS, ChannelEntity::SHARERSOFSHARERS, ChannelEntity::IMAGE, ChannelEntity::VIDEO, ChannelEntity::AUDIO, ChannelEntity::LANGUAGE])) {
if (!$this->timeline->isChannel($this->selectedTab) && !$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
}
if ($this->mode->isMobile()) {
self::$itemsPerPage = $this->pConfig->get(
$this->session->getLocalUserId(),
'system',
'itemspage_mobile_network',
$this->config->get('system', 'itemspage_network_mobile')
);
} else {
self::$itemsPerPage = $this->pConfig->get(
$this->session->getLocalUserId(),
'system',
'itemspage_network',
$this->config->get('system', 'itemspage_network')
);
}
if (!empty($request['item'])) {
$item = Post::selectFirst(['parent-uri-id'], ['id' => $request['item']]);
self::$item_id = $item['parent-uri-id'] ?? 0;
} else {
self::$item_id = 0;
}
self::$min_id = $request['min_id'] ?? null;
self::$max_id = $request['last_created'] ?? $request['max_id'] ?? null;
}
/**
* Database query for the channel page
*
* @return array
* @throws \Exception
*/
protected function getItems(array $request)
{
if (self::$content == ChannelEntity::WHATSHOT) {
if (!is_null(self::$accountType)) {
$condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` = ?", $this->getMedianComments(4), $this->getMedianActivities(4), self::$accountType];
} else {
$condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` != ?", $this->getMedianComments(4), $this->getMedianActivities(4), Contact::TYPE_COMMUNITY];
}
} elseif (self::$content == ChannelEntity::FORYOU) {
$cid = Contact::getPublicIdByUserId($this->session->getLocalUserId());
$condition = [
"(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `relation-thread-score` > ?) OR
((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?)) OR
(`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))",
$cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments(4), $this->getMedianActivities(4), $cid,
$this->session->getLocalUserId(), Contact::FRIEND, Contact::SHARING
];
} elseif (self::$content == ChannelEntity::FOLLOWERS) {
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $this->session->getLocalUserId(), Contact::FOLLOWER];
} elseif (self::$content == ChannelEntity::SHARERSOFSHARERS) {
$cid = Contact::getPublicIdByUserId($this->session->getLocalUserId());
// @todo Suggest posts from contacts that are followed most by our followers
$condition = [
"`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `last-interaction` > ?
AND `relation-cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ? AND `relation-thread-score` >= ?)
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 (self::$content == ChannelEntity::IMAGE) {
$condition = ["`media-type` & ?", 1];
} elseif (self::$content == ChannelEntity::VIDEO) {
$condition = ["`media-type` & ?", 2];
} elseif (self::$content == ChannelEntity::AUDIO) {
$condition = ["`media-type` & ?", 4];
} elseif (self::$content == ChannelEntity::LANGUAGE) {
$condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", $this->l10n->convertCodeForLanguageDetection(User::getLanguageCode($this->session->getLocalUserId()))];
}
if (self::$content != ChannelEntity::LANGUAGE) {
$condition = $this->addLanguageCondition($condition);
}
$condition[0] .= " AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed`))";
$condition[] = $this->session->getLocalUserId();
if ((self::$content != ChannelEntity::WHATSHOT) && !is_null(self::$accountType)) {
$condition[0] .= " AND `contact-type` = ?";
$condition[] = self::$accountType;
}
$params = ['order' => ['created' => true], 'limit' => self::$itemsPerPage];
if (!empty(self::$item_id)) {
$condition[0] .= " AND `uri-id` = ?";
$condition[] = self::$item_id;
} else {
if (!empty($request['no_sharer'])) {
$condition[0] .= " AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)";
$condition[] = $this->session->getLocalUserId();
}
if (isset(self::$max_id)) {
$condition[0] .= " AND `created` < ?";
$condition[] = self::$max_id;
}
if (isset(self::$min_id)) {
$condition[0] .= " AND `created` > ?";
$condition[] = self::$min_id;
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset(self::$max_id)) {
$params['order']['created'] = false;
}
}
}
$items = $this->database->selectToArray('post-engagement', ['uri-id', 'created'], $condition, $params);
if (empty($items)) {
return [];
}
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty(self::$item_id) && isset(self::$min_id) && !isset(self::$max_id)) {
$items = array_reverse($items);
}
Item::update(['unseen' => false], ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'uri-id' => array_column($items, 'uri-id')]);
return $items;
}
private function addLanguageCondition(array $condition): array
{
$conditions = [];
$languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId())]);
$languages = $this->l10n->convertForLanguageDetection($languages);
foreach ($languages as $language) {
$conditions[] = "JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?";
$condition[] = $language;
}
if (!empty($conditions)) {
$condition[0] .= " AND (`language` IS NULL OR " . implode(' OR ', $conditions) . ")";
}
return $condition;
}
private function getMedianComments(int $divider): int
{
$languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId())]);
$cache_key = 'Channel:getMedianComments:' . $divider . ':' . implode(':', $languages);
$comments = $this->cache->get($cache_key);
if (!empty($comments)) {
return $comments;
}
$condition = ["`contact-type` != ? AND `comments` > ?", Contact::TYPE_COMMUNITY, 0];
$condition = $this->addLanguageCondition($condition);
$limit = $this->database->count('post-engagement', $condition) / $divider;
$post = $this->database->selectToArray('post-engagement', ['comments'], $condition, ['order' => ['comments' => true], 'limit' => [$limit, 1]]);
$comments = $post[0]['comments'] ?? 0;
if (empty($comments)) {
return 0;
}
$this->cache->set($cache_key, $comments, Duration::HALF_HOUR);
$this->logger->debug('Calculated median comments', ['divider' => $divider, 'languages' => $languages, 'median' => $comments]);
return $comments;
}
private function getMedianActivities(int $divider): int
{
$languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId())]);
$cache_key = 'Channel:getMedianActivities:' . $divider . ':' . implode(':', $languages);
$activities = $this->cache->get($cache_key);
if (!empty($activities)) {
return $activities;
}
$condition = ["`contact-type` != ? AND `activities` > ?", Contact::TYPE_COMMUNITY, 0];
$condition = $this->addLanguageCondition($condition);
$limit = $this->database->count('post-engagement', $condition) / $divider;
$post = $this->database->selectToArray('post-engagement', ['activities'], $condition, ['order' => ['activities' => true], 'limit' => [$limit, 1]]);
$activities = $post[0]['activities'] ?? 0;
if (empty($activities)) {
return 0;
}
$this->cache->set($cache_key, $activities, Duration::HALF_HOUR);
$this->logger->debug('Calculated median activities', ['divider' => $divider, 'languages' => $languages, 'median' => $activities]);
return $activities;
}
private function getMedianRelationThreadScore(int $cid, int $divider): int
{
$cache_key = 'Channel:getThreadScore:' . $cid . ':' . $divider;
$score = $this->cache->get($cache_key);
if (!empty($score)) {
return $score;
}
$condition = ["`relation-cid` = ? AND `relation-thread-score` > ?", $cid, 0];
$limit = $this->database->count('contact-relation', $condition) / $divider;
$relation = $this->database->selectToArray('contact-relation', ['relation-thread-score'], $condition, ['order' => ['relation-thread-score' => true], 'limit' => [$limit, 1]]);
$score = $relation[0]['relation-thread-score'] ?? 0;
if (empty($score)) {
return 0;
}
$this->cache->set($cache_key, $score, Duration::HALF_HOUR);
$this->logger->debug('Calculated median score', ['cid' => $cid, 'divider' => $divider, 'median' => $score]);
return $score;
$this->maxId = $request['last_created'] ?? $this->maxId;
}
}

View File

@ -22,23 +22,31 @@
namespace Friendica\Module\Conversation;
use Friendica\BaseModule;
use Friendica\App;
use Friendica\App\Mode;
use Friendica\Content\BoundariesPager;
use Friendica\Content\Conversation;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
use Friendica\Content\Widget\TrendingTags;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Network\HTTPException;
use Friendica\Database\Database;
use Friendica\Module\Response;
use Friendica\Navigation\SystemMessages;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
class Community extends BaseModule
class Community extends Timeline
{
/**
* Type of the community page
@ -49,126 +57,86 @@ class Community extends BaseModule
const LOCAL = 0;
const GLOBAL = 1;
const LOCAL_AND_GLOBAL = 2;
/**
* @}
*/
protected static $page_style;
protected static $content;
protected static $accountTypeString;
protected static $accountType;
protected static $itemsPerPage;
protected static $min_id;
protected static $max_id;
protected static $item_id;
protected $pageStyle;
/** @var TimelineFactory */
protected $timeline;
/** @var Conversation */
protected $conversation;
/** @var App\Page */
protected $page;
/** @var SystemMessages */
protected $systemMessages;
public function __construct(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($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;
}
protected function content(array $request = []): string
{
$this->parseRequest();
$this->parseRequest($request);
$t = Renderer::getMarkupTemplate("community.tpl");
$o = Renderer::replaceMacros($t, [
'$content' => '',
'$header' => '',
'$show_global_community_hint' => (self::$content == 'global') && DI::config()->get('system', 'show_global_community_hint'),
'$global_community_hint' => DI::l10n()->t("This community stream shows all public posts received by this node. They may not reflect the opinions of this nodes users.")
'$show_global_community_hint' => ($this->selectedTab == TimelineEntity::GLOBAL) && $this->config->get('system', 'show_global_community_hint'),
'$global_community_hint' => $this->l10n->t("This community stream shows all public posts received by this node. They may not reflect the opinions of this nodes users.")
]);
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
}
if (empty($_GET['mode']) || ($_GET['mode'] != 'raw')) {
$tabs = [];
if ((DI::userSession()->isAuthenticated() || in_array(self::$page_style, [self::LOCAL_AND_GLOBAL, self::LOCAL])) && empty(DI::config()->get('system', 'singleuser'))) {
$tabs[] = [
'label' => DI::l10n()->t('Local Community'),
'url' => 'community/local',
'sel' => self::$content == 'local' ? 'active' : '',
'title' => DI::l10n()->t('Posts from local users on this server'),
'id' => 'community-local-tab',
'accesskey' => 'l'
];
}
if (DI::userSession()->isAuthenticated() || in_array(self::$page_style, [self::LOCAL_AND_GLOBAL, self::GLOBAL])) {
$tabs[] = [
'label' => DI::l10n()->t('Global Community'),
'url' => 'community/global',
'sel' => self::$content == 'global' ? 'active' : '',
'title' => DI::l10n()->t('Posts from users of the whole federated network'),
'id' => 'community-global-tab',
'accesskey' => 'g'
];
}
if (empty($request['mode']) || ($request['mode'] != 'raw')) {
$tabs = $this->getTabArray($this->timeline->getCommunities($this->session->isAuthenticated()), 'community');
$tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
$o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
Nav::setSelected('community');
DI::page()['aside'] .= Widget::accountTypes('community/' . self::$content, self::$accountTypeString);
$this->page['aside'] .= Widget::accountTypes('community/' . $this->selectedTab, $this->accountTypeString);
if (DI::userSession()->getLocalUserId() && DI::config()->get('system', 'community_no_sharer')) {
$path = self::$content;
if (!empty($this->parameters['accounttype'])) {
$path .= '/' . $this->parameters['accounttype'];
}
$query_parameters = [];
if (!empty($_GET['min_id'])) {
$query_parameters['min_id'] = $_GET['min_id'];
}
if (!empty($_GET['max_id'])) {
$query_parameters['max_id'] = $_GET['max_id'];
}
if (!empty($_GET['last_commented'])) {
$query_parameters['max_id'] = $_GET['last_commented'];
}
$path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
$path_no_sharer = $path . '?' . http_build_query(array_merge($query_parameters, ['no_sharer' => true]));
DI::page()['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_sharer.tpl'), [
'$title' => DI::l10n()->t('Own Contacts'),
'$path_all' => $path_all,
'$path_no_sharer' => $path_no_sharer,
'$no_sharer' => !empty($_REQUEST['no_sharer']),
'$all' => DI::l10n()->t('Include'),
'$no_sharer_label' => DI::l10n()->t('Hide'),
'$base' => 'community',
]);
if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget('community');
}
if (Feature::isEnabled(DI::userSession()->getLocalUserId(), 'trending_tags')) {
DI::page()['aside'] .= TrendingTags::getHTML(self::$content);
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
}
// We need the editor here to be able to reshare an item.
if (DI::userSession()->isAuthenticated()) {
$o .= DI::conversation()->statusEditor([], 0, true);
if ($this->session->isAuthenticated()) {
$o .= $this->conversation->statusEditor([], 0, true);
}
}
$items = self::getItems();
$items = $this->getCommunityItems();
if (!DBA::isResult($items)) {
DI::sysmsg()->addNotice(DI::l10n()->t('No results.'));
if (!$this->database->isResult($items)) {
$this->systemMessages->addNotice($this->l10n->t('No results.'));
return $o;
}
$o .= DI::conversation()->render($items, Conversation::MODE_COMMUNITY, false, false, 'commented', DI::userSession()->getLocalUserId());
$o .= $this->conversation->render($items, Conversation::MODE_COMMUNITY, false, false, 'commented', $this->session->getLocalUserId());
$pager = new BoundariesPager(
DI::l10n(),
DI::args()->getQueryString(),
$this->l10n,
$this->args->getQueryString(),
$items[0]['commented'],
$items[count($items) - 1]['commented'],
self::$itemsPerPage
$this->itemsPerPage
);
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal(count($items));
@ -183,191 +151,51 @@ class Community extends BaseModule
* @throws HTTPException\BadRequestException
* @throws HTTPException\ForbiddenException
*/
protected function parseRequest()
protected function parseRequest($request)
{
if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Public access denied.'));
parent::parseRequest($request);
if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
throw new HTTPException\ForbiddenException($this->l10n->t('Public access denied.'));
}
self::$page_style = DI::config()->get('system', 'community_page_style');
$this->pageStyle = $this->config->get('system', 'community_page_style');
if (self::$page_style == self::DISABLED) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
if ($this->pageStyle == self::DISABLED) {
throw new HTTPException\ForbiddenException($this->l10n->t('Access denied.'));
}
self::$accountTypeString = $_GET['accounttype'] ?? $this->parameters['accounttype'] ?? '';
self::$accountType = User::getAccountTypeByString(self::$accountTypeString);
self::$content = $this->parameters['content'] ?? '';
if (!self::$content) {
if (!empty(DI::config()->get('system', 'singleuser'))) {
if (!$this->selectedTab) {
if (!empty($this->config->get('system', 'singleuser'))) {
// On single user systems only the global page does make sense
self::$content = 'global';
$this->selectedTab = TimelineEntity::GLOBAL;
} else {
// When only the global community is allowed, we use this as default
self::$content = self::$page_style == self::GLOBAL ? 'global' : 'local';
$this->selectedTab = $this->pageStyle == self::GLOBAL ? TimelineEntity::GLOBAL : TimelineEntity::LOCAL;
}
}
if (!in_array(self::$content, ['local', 'global'])) {
throw new HTTPException\BadRequestException(DI::l10n()->t('Community option not available.'));
if (!$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Community option not available.'));
}
// Check if we are allowed to display the content to visitors
if (!DI::userSession()->isAuthenticated()) {
$available = self::$page_style == self::LOCAL_AND_GLOBAL;
if (!$this->session->isAuthenticated()) {
$available = $this->pageStyle == self::LOCAL_AND_GLOBAL;
if (!$available) {
$available = (self::$page_style == self::LOCAL) && (self::$content == 'local');
$available = ($this->pageStyle == self::LOCAL) && ($this->selectedTab == TimelineEntity::LOCAL);
}
if (!$available) {
$available = (self::$page_style == self::GLOBAL) && (self::$content == 'global');
$available = ($this->pageStyle == self::GLOBAL) && ($this->selectedTab == TimelineEntity::GLOBAL);
}
if (!$available) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Not available.'));
throw new HTTPException\ForbiddenException($this->l10n->t('Not available.'));
}
}
if (DI::mode()->isMobile()) {
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
if (!empty($_GET['item'])) {
$item = Post::selectFirst(['parent'], ['id' => $_GET['item']]);
self::$item_id = $item['parent'] ?? 0;
} else {
self::$item_id = 0;
}
self::$min_id = $_GET['min_id'] ?? null;
self::$max_id = $_GET['last_commented'] ?? $_GET['max_id'] ?? null;
}
/**
* Computes the displayed items.
*
* Community pages have a restriction on how many successive posts by the same author can show on any given page,
* so we may have to retrieve more content beyond the first query
*
* @return array
* @throws \Exception
*/
protected static function getItems()
{
$items = self::selectItems(self::$min_id, self::$max_id, self::$item_id, self::$itemsPerPage);
$maxpostperauthor = (int) DI::config()->get('system', 'max_author_posts_community_page');
if ($maxpostperauthor != 0 && self::$content == 'local') {
$count = 1;
$previousauthor = '';
$numposts = 0;
$selected_items = [];
while (count($selected_items) < self::$itemsPerPage && ++$count < 50 && count($items) > 0) {
foreach ($items as $item) {
if ($previousauthor == $item["author-link"]) {
++$numposts;
} else {
$numposts = 0;
}
$previousauthor = $item["author-link"];
if (($numposts < $maxpostperauthor) && (count($selected_items) < self::$itemsPerPage)) {
$selected_items[] = $item;
}
}
// If we're looking at a "previous page", the lookup continues forward in time because the list is
// sorted in chronologically decreasing order
if (isset(self::$min_id)) {
self::$min_id = $items[0]['commented'];
} else {
// In any other case, the lookup continues backwards in time
self::$max_id = $items[count($items) - 1]['commented'];
}
$items = self::selectItems(self::$min_id, self::$max_id, self::$item_id, self::$itemsPerPage);
}
} else {
$selected_items = $items;
}
return $selected_items;
}
/**
* Database query for the community page
*
* @param $min_id
* @param $max_id
* @param $itemspage
* @return array
* @throws \Exception
* @TODO Move to repository/factory
*/
private static function selectItems($min_id, $max_id, $item_id, $itemspage)
{
if (self::$content == 'local') {
if (!is_null(self::$accountType)) {
$condition = ["`wall` AND `origin` AND `private` = ? AND `owner-contact-type` = ?", Item::PUBLIC, self::$accountType];
} else {
$condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
}
} elseif (self::$content == 'global') {
if (!is_null(self::$accountType)) {
$condition = ["`uid` = ? AND `private` = ? AND `owner-contact-type` = ?", 0, Item::PUBLIC, self::$accountType];
} else {
$condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
}
} else {
return [];
}
$params = ['order' => ['commented' => true], 'limit' => $itemspage];
if (!empty($item_id)) {
$condition[0] .= " AND `id` = ?";
$condition[] = $item_id;
} else {
if (DI::userSession()->getLocalUserId() && !empty($_REQUEST['no_sharer'])) {
$condition[0] .= " AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)";
$condition[] = DI::userSession()->getLocalUserId();
}
if (isset($max_id)) {
$condition[0] .= " AND `commented` < ?";
$condition[] = $max_id;
}
if (isset($min_id)) {
$condition[0] .= " AND `commented` > ?";
$condition[] = $min_id;
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset($max_id)) {
$params['order']['commented'] = false;
}
}
}
$r = Post::selectThreadForUser(DI::userSession()->getLocalUserId() ?: 0, ['uri-id', 'commented', 'author-link'], $condition, $params);
$items = Post::toArray($r);
if (empty($items)) {
return [];
}
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty($item_id) && isset($min_id) && !isset($max_id)) {
$items = array_reverse($items);
}
return $items;
$this->maxId = $request['last_commented'] ?? $this->maxId;
}
}

View File

@ -21,138 +21,185 @@
namespace Friendica\Module\Conversation;
use Friendica\BaseModule;
use Friendica\App;
use Friendica\App\Mode;
use Friendica\Content\BoundariesPager;
use Friendica\Content\Conversation;
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
use Friendica\Content\Feature;
use Friendica\Content\GroupManager;
use Friendica\Content\Nav;
use Friendica\Content\Widget;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget\TrendingTags;
use Friendica\Core\ACL;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Database\Database;
use Friendica\Model\Contact;
use Friendica\Model\Circle;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Model\Verb;
use Friendica\Module\Contact as ModuleContact;
use Friendica\Module\Response;
use Friendica\Module\Security\Login;
use Friendica\Protocol\Activity;
use Friendica\Network\HTTPException;
use Friendica\Navigation\SystemMessages;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
use Friendica\Protocol\Activity;
use Psr\Log\LoggerInterface;
class Network extends BaseModule
class Network extends Timeline
{
/** @var int */
private static $circleId;
protected $circleId;
/** @var int */
private static $groupContactId;
protected $groupContactId;
/** @var string */
private static $selectedTab;
/** @var mixed */
private static $min_id;
/** @var mixed */
private static $max_id;
protected $network;
/** @var string */
private static $accountTypeString;
protected $dateFrom;
/** @var string */
protected $dateTo;
/** @var int */
private static $accountType;
/** @var string */
private static $network;
protected $star;
/** @var int */
private static $itemsPerPage;
protected $mention;
/** @var string */
private static $dateFrom;
/** @var string */
private static $dateTo;
/** @var int */
private static $star;
/** @var int */
private static $mention;
/** @var string */
protected static $order;
protected $order;
/** @var App */
protected $app;
/** @var ICanCache */
protected $cache;
/** @var IManageConfigValues The config */
protected $config;
/** @var SystemMessages */
protected $systemMessages;
/** @var App\Page */
protected $page;
/** @var Conversation */
protected $conversation;
/** @var IManagePersonalConfigValues */
protected $pConfig;
/** @var Database */
protected $database;
/** @var TimelineFactory */
protected $timeline;
public function __construct(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($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;
}
protected function content(array $request = []): string
{
if (!DI::userSession()->getLocalUserId()) {
if (!$this->session->getLocalUserId()) {
return Login::form();
}
$this->parseRequest($_GET);
$this->parseRequest($request);
$module = 'network';
DI::page()['aside'] .= Widget::accountTypes($module, self::$accountTypeString);
DI::page()['aside'] .= Circle::sidebarWidget($module, $module . '/circle', 'standard', self::$circleId);
DI::page()['aside'] .= GroupManager::widget($module . '/group', DI::userSession()->getLocalUserId(), self::$groupContactId);
DI::page()['aside'] .= Widget::postedByYear($module . '/archive', DI::userSession()->getLocalUserId(), false);
DI::page()['aside'] .= Widget::networks($module, !self::$groupContactId ? self::$network : '');
DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
DI::page()['aside'] .= Widget::fileAs('filed', '');
$this->page['aside'] .= Widget::channels($module, $this->selectedTab, $this->session->getLocalUserId());
$this->page['aside'] .= Widget::accountTypes($module, $this->accountTypeString);
$arr = ['query' => DI::args()->getQueryString()];
$arr = ['query' => $this->args->getQueryString()];
Hook::callAll('network_content_init', $arr);
$o = '';
// Fetch a page full of parent items for this page
$params = ['limit' => self::$itemsPerPage];
$table = 'network-thread-view';
if ($this->timeline->isChannel($this->selectedTab)) {
if (!in_array($this->selectedTab, [TimelineEntity::FOLLOWERS, TimelineEntity::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget($module);
}
$items = self::getItems($table, $params);
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
}
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
$items = $this->getChannelItems();
} elseif ($this->timeline->isCommunity($this->selectedTab)) {
if ($this->session->getLocalUserId() && $this->config->get('system', 'community_no_sharer')) {
$this->page['aside'] .= $this->getNoSharerWidget($module);
}
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
$this->page['aside'] .= TrendingTags::getHTML($this->selectedTab);
}
$items = $this->getCommunityItems();
} else {
$this->page['aside'] .= Circle::sidebarWidget($module, $module . '/circle', 'standard', $this->circleId);
$this->page['aside'] .= GroupManager::widget($module . '/group', $this->session->getLocalUserId(), $this->groupContactId);
$this->page['aside'] .= Widget::postedByYear($module . '/archive', $this->session->getLocalUserId(), false);
$this->page['aside'] .= Widget::networks($module, !$this->groupContactId ? $this->network : '');
$this->page['aside'] .= Widget\SavedSearches::getHTML($this->args->getQueryString());
$this->page['aside'] .= Widget::fileAs('filed', '');
$items = $this->getItems();
}
if (!(isset($_GET['mode']) AND ($_GET['mode'] == 'raw'))) {
$o .= self::getTabsHTML(self::$selectedTab);
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
}
Nav::setSelected(DI::args()->get(0));
if (!(isset($_GET['mode']) and ($_GET['mode'] == 'raw'))) {
$o .= $this->getTabsHTML();
Nav::setSelected($this->args->get(0));
$content = '';
if (self::$groupContactId) {
// If self::$groupContactId belongs to a community group or a private group, add a mention to the status editor
$condition = ["`id` = ? AND `contact-type` = ?", self::$groupContactId, Contact::TYPE_COMMUNITY];
$contact = DBA::selectFirst('contact', ['addr'], $condition);
if ($this->groupContactId) {
// If $this->groupContactId belongs to a community group or a private group, add a mention to the status editor
$condition = ["`id` = ? AND `contact-type` = ?", $this->groupContactId, Contact::TYPE_COMMUNITY];
$contact = $this->database->selectFirst('contact', ['addr'], $condition);
if (!empty($contact['addr'])) {
$content = '!' . $contact['addr'];
}
}
$a = DI::app();
$default_permissions = [];
if (self::$circleId) {
$default_permissions['allow_gid'] = [self::$circleId];
if ($this->circleId) {
$default_permissions['allow_gid'] = [$this->circleId];
}
$allowedCids = [];
if (self::$groupContactId) {
$allowedCids[] = (int) self::$groupContactId;
} elseif (self::$network) {
if ($this->groupContactId) {
$allowedCids[] = (int) $this->groupContactId;
} elseif ($this->network) {
$condition = [
'uid' => DI::userSession()->getLocalUserId(),
'network' => self::$network,
'uid' => $this->session->getLocalUserId(),
'network' => $this->network,
'self' => false,
'blocked' => false,
'pending' => false,
'archive' => false,
'rel' => [Contact::SHARING, Contact::FRIEND],
];
$contactStmt = DBA::select('contact', ['id'], $condition);
while ($contact = DBA::fetch($contactStmt)) {
$contactStmt = $this->database->select('contact', ['id'], $condition);
while ($contact = $this->database->fetch($contactStmt)) {
$allowedCids[] = (int) $contact['id'];
}
DBA::close($contactStmt);
$this->database->close($contactStmt);
}
if (count($allowedCids)) {
@ -160,58 +207,50 @@ class Network extends BaseModule
}
$x = [
'lockstate' => self::$circleId || self::$groupContactId || self::$network || ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
'acl' => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), true, $default_permissions),
'bang' => ((self::$circleId || self::$groupContactId || self::$network) ? '!' : ''),
'lockstate' => $this->circleId || $this->groupContactId || $this->network || ACL::getLockstateForUserId($this->session->getLocalUserId()) ? 'lock' : 'unlock',
'acl' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), true, $default_permissions),
'bang' => (($this->circleId || $this->groupContactId || $this->network) ? '!' : ''),
'content' => $content,
];
$o .= DI::conversation()->statusEditor($x);
$o .= $this->conversation->statusEditor($x);
}
if (self::$circleId) {
$circle = DBA::selectFirst('group', ['name'], ['id' => self::$circleId, 'uid' => DI::userSession()->getLocalUserId()]);
if (!DBA::isResult($circle)) {
DI::sysmsg()->addNotice(DI::l10n()->t('No such circle'));
if ($this->circleId) {
$circle = $this->database->selectFirst('group', ['name'], ['id' => $this->circleId, 'uid' => $this->session->getLocalUserId()]);
if (!$this->database->isResult($circle)) {
$this->systemMessages->addNotice($this->l10n->t('No such circle'));
}
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
'$title' => DI::l10n()->t('Circle: %s', $circle['name'])
'$title' => $this->l10n->t('Circle: %s', $circle['name'])
]) . $o;
} elseif (self::$groupContactId) {
$contact = Contact::getById(self::$groupContactId);
if (DBA::isResult($contact)) {
} elseif ($this->groupContactId) {
$contact = Contact::getById($this->groupContactId);
if ($this->database->isResult($contact)) {
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('contact/list.tpl'), [
'contacts' => [ModuleContact::getContactTemplateVars($contact)],
'id' => DI::args()->get(0),
'id' => $this->args->get(0),
]) . $o;
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('Invalid contact.'));
$this->systemMessages->addNotice($this->l10n->t('Invalid contact.'));
}
} elseif (!DI::config()->get('theme', 'hide_eventlist')) {
} elseif (!$this->config->get('theme', 'hide_eventlist')) {
$o .= Profile::getBirthdays();
$o .= Profile::getEventsReminderHTML();
}
if (self::$order === 'received') {
$ordering = '`received`';
} elseif (self::$order === 'created') {
$ordering = '`created`';
} else {
$ordering = '`commented`';
}
$o .= $this->conversation->render($items, Conversation::MODE_NETWORK, false, false, $this->getOrder(), $this->session->getLocalUserId());
$o .= DI::conversation()->render($items, Conversation::MODE_NETWORK, false, false, $ordering, DI::userSession()->getLocalUserId());
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$pager = new BoundariesPager(
DI::l10n(),
DI::args()->getQueryString(),
$items[0][self::$order] ?? null,
$items[count($items) - 1][self::$order] ?? null,
self::$itemsPerPage
$this->l10n,
$this->args->getQueryString(),
$items[0][$this->order] ?? null,
$items[count($items) - 1][$this->order] ?? null,
$this->itemsPerPage
);
$o .= $pager->renderMinimal(count($items));
@ -220,257 +259,220 @@ class Network extends BaseModule
return $o;
}
/**
* Sets items as seen
*
* @param array $condition The array with the SQL condition
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function setItemsSeenByCondition(array $condition)
protected function getOrder(): string
{
if (empty($condition)) {
return;
}
$unseen = Post::exists($condition);
if ($unseen) {
/// @todo handle huge "unseen" updates in the background to avoid timeout errors
Item::update(['unseen' => false], $condition);
if ($this->order === 'received') {
return '`received`';
} elseif ($this->order === 'created') {
return '`created`';
} else {
return '`commented`';
}
}
/**
* Get the network tabs menu
*
* @param string $selectedTab
* @return string Html of the network tabs
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function getTabsHTML(string $selectedTab)
private function getTabsHTML()
{
$cmd = DI::args()->getCommand();
// @todo user confgurable selection of tabs
$tabs = $this->getTabArray($this->timeline->getNetworkFeeds($this->args->getCommand()), 'network');
// tabs
$tabs = [
[
'label' => DI::l10n()->t('Latest Activity'),
'url' => $cmd . '?' . http_build_query(['order' => 'commented']),
'sel' => !$selectedTab || $selectedTab == 'commented' ? 'active' : '',
'title' => DI::l10n()->t('Sort by latest activity'),
'id' => 'activity-order-tab',
'accesskey' => 'e',
],
[
'label' => DI::l10n()->t('Latest Posts'),
'url' => $cmd . '?' . http_build_query(['order' => 'received']),
'sel' => $selectedTab == 'received' ? 'active' : '',
'title' => DI::l10n()->t('Sort by post received date'),
'id' => 'post-order-tab',
'accesskey' => 't',
],
[
'label' => DI::l10n()->t('Latest Creation'),
'url' => $cmd . '?' . http_build_query(['order' => 'created']),
'sel' => $selectedTab == 'created' ? 'active' : '',
'title' => DI::l10n()->t('Sort by post creation date'),
'id' => 'creation-order-tab',
'accesskey' => 'q',
],
[
'label' => DI::l10n()->t('Personal'),
'url' => $cmd . '?' . http_build_query(['mention' => true]),
'sel' => $selectedTab == 'mention' ? 'active' : '',
'title' => DI::l10n()->t('Posts that mention or involve you'),
'id' => 'personal-tab',
'accesskey' => 'r',
],
[
'label' => DI::l10n()->t('Starred'),
'url' => $cmd . '?' . http_build_query(['star' => true]),
'sel' => $selectedTab == 'star' ? 'active' : '',
'title' => DI::l10n()->t('Favourite Posts'),
'id' => 'starred-posts-tab',
'accesskey' => 'm',
],
];
$network_timelines = $this->pConfig->get($this->session->getLocalUserId(), 'system', 'network_timelines', []);
if (!empty($network_timelines)) {
$tabs = array_merge($tabs, $this->getTabArray($this->timeline->getChannelsForUser($this->session->getLocalUserId()), 'network', 'channel'));
$tabs = array_merge($tabs, $this->getTabArray($this->timeline->getCommunities(true), 'network', 'channel'));
}
$arr = ['tabs' => $tabs];
Hook::callAll('network_tabs', $arr);
if (!empty($network_timelines)) {
$tabs = [];
foreach (array_keys($arr['tabs']) as $tab) {
if (in_array($tab, $network_timelines)) {
$tabs[] = $arr['tabs'][$tab];
}
}
} else {
$tabs = $arr['tabs'];
}
$tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
return Renderer::replaceMacros($tpl, ['$tabs' => $tabs]);
}
protected function parseRequest(array $get)
protected function parseRequest(array $request)
{
self::$circleId = (int)($this->parameters['circle_id'] ?? 0);
parent::parseRequest($request);
self::$groupContactId = (int)($this->parameters['contact_id'] ?? 0);
$this->circleId = (int)($this->parameters['circle_id'] ?? 0);
self::$selectedTab = self::getTimelineOrderBySession(DI::userSession(), DI::pConfig());
$this->groupContactId = (int)($this->parameters['contact_id'] ?? 0);
if (!empty($get['star'])) {
self::$selectedTab = 'star';
self::$star = true;
} else {
self::$star = self::$selectedTab == 'star';
if (!$this->selectedTab) {
$this->selectedTab = self::getTimelineOrderBySession($this->session, $this->pConfig);
} elseif (!$this->timeline->isChannel($this->selectedTab) && !$this->timeline->isCommunity($this->selectedTab)) {
throw new HTTPException\BadRequestException($this->l10n->t('Network feed not available.'));
}
if (!empty($get['mention'])) {
self::$selectedTab = 'mention';
self::$mention = true;
if (!empty($request['star'])) {
$this->selectedTab = TimelineEntity::STAR;
$this->star = true;
} else {
self::$mention = self::$selectedTab == 'mention';
$this->star = $this->selectedTab == TimelineEntity::STAR;
}
if (!empty($get['order'])) {
self::$selectedTab = $get['order'];
self::$order = $get['order'];
self::$star = false;
self::$mention = false;
} elseif (in_array(self::$selectedTab, ['received', 'star'])) {
self::$order = 'received';
} elseif (self::$selectedTab == 'created') {
self::$order = 'created';
if (!empty($request['mention'])) {
$this->selectedTab = TimelineEntity::MENTION;
$this->mention = true;
} else {
self::$order = 'commented';
$this->mention = $this->selectedTab == TimelineEntity::MENTION;
}
self::$selectedTab = self::$selectedTab ?? self::$order;
if (!empty($request['order'])) {
$this->selectedTab = $request['order'];
$this->order = $request['order'];
$this->star = false;
$this->mention = false;
} elseif (in_array($this->selectedTab, [TimelineEntity::RECEIVED, TimelineEntity::STAR])) {
$this->order = 'received';
} elseif (($this->selectedTab == TimelineEntity::CREATED) || $this->timeline->isChannel($this->selectedTab)) {
$this->order = 'created';
} else {
$this->order = 'commented';
}
$this->selectedTab = $this->selectedTab ?? $this->order;
// Prohibit combined usage of "star" and "mention"
if (self::$selectedTab == 'star') {
self::$mention = false;
} elseif (self::$selectedTab == 'mention') {
self::$star = false;
if ($this->selectedTab == TimelineEntity::STAR) {
$this->mention = false;
} elseif ($this->selectedTab == TimelineEntity::MENTION) {
$this->star = false;
}
DI::session()->set('network-tab', self::$selectedTab);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'network.view', 'selected_tab', self::$selectedTab);
$this->session->set('network-tab', $this->selectedTab);
$this->pConfig->set($this->session->getLocalUserId(), 'network.view', 'selected_tab', $this->selectedTab);
self::$accountTypeString = $get['accounttype'] ?? $this->parameters['accounttype'] ?? '';
self::$accountType = User::getAccountTypeByString(self::$accountTypeString);
$this->network = $request['nets'] ?? '';
self::$network = $get['nets'] ?? '';
$this->dateFrom = $this->parameters['from'] ?? '';
$this->dateTo = $this->parameters['to'] ?? '';
self::$dateFrom = $this->parameters['from'] ?? '';
self::$dateTo = $this->parameters['to'] ?? '';
if (DI::mode()->isMobile()) {
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
self::$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
self::$min_id = $get['min_id'] ?? null;
self::$max_id = $get['max_id'] ?? null;
switch (self::$order) {
switch ($this->order) {
case 'received':
self::$max_id = $get['last_received'] ?? self::$max_id;
$this->maxId = $request['last_received'] ?? $this->maxId;
break;
case 'created':
self::$max_id = $get['last_created'] ?? self::$max_id;
$this->maxId = $request['last_created'] ?? $this->maxId;
break;
case 'uriid':
self::$max_id = $get['last_uriid'] ?? self::$max_id;
$this->maxId = $request['last_uriid'] ?? $this->maxId;
break;
default:
self::$order = 'commented';
self::$max_id = $get['last_commented'] ?? self::$max_id;
$this->order = 'commented';
$this->maxId = $request['last_commented'] ?? $this->maxId;
}
}
protected static function getItems(string $table, array $params, array $conditionFields = [])
protected function getItems()
{
$conditionFields['uid'] = DI::userSession()->getLocalUserId();
$conditionFields = ['uid' => $this->session->getLocalUserId()];
$conditionStrings = [];
if (!is_null(self::$accountType)) {
$conditionFields['contact-type'] = self::$accountType;
if (!is_null($this->accountType)) {
$conditionFields['contact-type'] = $this->accountType;
}
if (self::$star) {
if ($this->star) {
$conditionFields['starred'] = true;
}
if (self::$mention) {
if ($this->mention) {
$conditionFields['mention'] = true;
}
if (self::$network) {
$conditionFields['network'] = self::$network;
if ($this->network) {
$conditionFields['network'] = $this->network;
}
if (self::$dateFrom) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` <= ? ", DateTimeFormat::convert(self::$dateFrom, 'UTC', DI::app()->getTimeZone())]);
if ($this->dateFrom) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` <= ? ", DateTimeFormat::convert($this->dateFrom, 'UTC', $this->app->getTimeZone())]);
}
if (self::$dateTo) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert(self::$dateTo, 'UTC', DI::app()->getTimeZone())]);
if ($this->dateTo) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert($this->dateTo, 'UTC', $this->app->getTimeZone())]);
}
if (self::$circleId) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", self::$circleId]);
} elseif (self::$groupContactId) {
if ($this->circleId) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $this->circleId]);
} elseif ($this->groupContactId) {
$conditionStrings = DBA::mergeConditions($conditionStrings,
["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
self::$groupContactId, self::$groupContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), DI::userSession()->getLocalUserId()]);
$this->groupContactId, $this->groupContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), $this->session->getLocalUserId()]);
}
// Currently only the order modes "received" and "commented" are in use
if (isset(self::$max_id)) {
switch (self::$order) {
case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", self::$max_id]);
break;
case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", self::$max_id]);
break;
case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", self::$max_id]);
break;
case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", self::$max_id]);
break;
if (!empty($this->itemUriId)) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ['uri-id' => $this->itemUriId]);
} else {
if (isset($this->maxId)) {
switch ($this->order) {
case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $this->maxId]);
break;
case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $this->maxId]);
break;
case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $this->maxId]);
break;
case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $this->maxId]);
break;
}
}
if (isset($this->minId)) {
switch ($this->order) {
case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", $this->minId]);
break;
case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", $this->minId]);
break;
case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", $this->minId]);
break;
case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", $this->minId]);
break;
}
}
}
if (isset(self::$min_id)) {
switch (self::$order) {
case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", self::$min_id]);
break;
case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", self::$min_id]);
break;
case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", self::$min_id]);
break;
case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", self::$min_id]);
break;
}
}
$params = ['limit' => $this->itemsPerPage];
if (isset(self::$min_id) && !isset(self::$max_id)) {
if (isset($this->minId) && !isset($this->maxId)) {
// min_id quirk: querying in reverse order with min_id gets the most recent rows, regardless of how close
// they are to min_id. We change the query ordering to get the expected data, and we need to reverse the
// order of the results.
$params['order'] = [self::$order => false];
$params['order'] = [$this->order => false];
} else {
$params['order'] = [self::$order => true];
$params['order'] = [$this->order => true];
}
$items = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
$items = $this->database->selectToArray('network-thread-view', [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
// min_id quirk, continued
if (isset(self::$min_id) && !isset(self::$max_id)) {
if (isset($this->minId) && !isset($this->maxId)) {
$items = array_reverse($items);
}
if (DBA::isResult($items)) {
if ($this->database->isResult($items)) {
$parents = array_column($items, 'uri-id');
} else {
$parents = [];
@ -479,12 +481,12 @@ class Network extends BaseModule
// We aren't going to try and figure out at the item, circle, and page
// level which items you've seen and which you haven't. If you're looking
// at the top level network page just mark everything seen.
if (!self::$circleId && !self::$groupContactId && !self::$star && !self::$mention) {
$condition = ['unseen' => true, 'uid' => DI::userSession()->getLocalUserId()];
self::setItemsSeenByCondition($condition);
if (!$this->circleId && !$this->groupContactId && !$this->star && !$this->mention) {
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId()];
$this->setItemsSeenByCondition($condition);
} elseif (!empty($parents)) {
$condition = ['unseen' => true, 'uid' => DI::userSession()->getLocalUserId(), 'parent-uri-id' => $parents];
self::setItemsSeenByCondition($condition);
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => $parents];
$this->setItemsSeenByCondition($condition);
}
return $items;

View File

@ -0,0 +1,503 @@
<?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\Module\Conversation;
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\Core\Cache\Capability\ICanCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Module\Response;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
class Timeline extends BaseModule
{
/** @var string */
protected $selectedTab;
/** @var mixed */
protected $minId;
/** @var mixed */
protected $maxId;
/** @var string */
protected $accountTypeString;
/** @var int */
protected $accountType;
/** @var int */
protected $itemUriId;
/** @var int */
protected $itemsPerPage;
/** @var bool */
protected $noSharer;
/** @var App\Mode $mode */
protected $mode;
/** @var IHandleUserSessions */
protected $session;
/** @var Database */
protected $database;
/** @var IManagePersonalConfigValues */
protected $pConfig;
/** @var IManageConfigValues The config */
protected $config;
/** @var ICanCache */
protected $cache;
public function __construct(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->mode = $mode;
$this->session = $session;
$this->database = $database;
$this->pConfig = $pConfig;
$this->config = $config;
$this->cache = $cache;
}
/**
* Computes module parameters from the request and local configuration
*
* @throws HTTPException\BadRequestException
* @throws HTTPException\ForbiddenException
*/
protected function parseRequest(array $request)
{
$this->logger->debug('Got request', $request);
$this->selectedTab = $this->parameters['content'] ?? $request['channel'] ?? '';
$this->accountTypeString = $request['accounttype'] ?? $this->parameters['accounttype'] ?? '';
$this->accountType = User::getAccountTypeByString($this->accountTypeString);
if ($this->mode->isMobile()) {
$this->itemsPerPage = $this->pConfig->get(
$this->session->getLocalUserId(),
'system',
'itemspage_mobile_network',
$this->config->get('system', 'itemspage_network_mobile')
);
} else {
$this->itemsPerPage = $this->pConfig->get(
$this->session->getLocalUserId(),
'system',
'itemspage_network',
$this->config->get('system', 'itemspage_network')
);
}
if (!empty($request['item'])) {
$item = Post::selectFirst(['parent', 'parent-uri-id'], ['id' => $request['item']]);
$this->itemUriId = $item['parent-uri-id'] ?? 0;
} else {
$this->itemUriId = 0;
}
$this->minId = $request['min_id'] ?? null;
$this->maxId = $request['max_id'] ?? null;
$this->noSharer = !empty($request['no_sharer']);
}
protected function getNoSharerWidget(string $base): string
{
$path = $this->selectedTab;
if (!empty($this->accountTypeString)) {
$path .= '/' . $this->accountTypeString;
}
$query_parameters = [];
if (!empty($this->minId)) {
$query_parameters['min_id'] = $this->minId;
}
if (!empty($this->maxId)) {
$query_parameters['max_id'] = $this->maxId;
}
$path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
$path_no_sharer = $path . '?' . http_build_query(array_merge($query_parameters, ['no_sharer' => true]));
return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_sharer.tpl'), [
'$title' => $this->l10n->t('Own Contacts'),
'$path_all' => $path_all,
'$path_no_sharer' => $path_no_sharer,
'$no_sharer' => $this->noSharer,
'$all' => $this->l10n->t('Include'),
'$no_sharer_label' => $this->l10n->t('Hide'),
'$base' => $base,
]);
}
protected function getTabArray(Timelines $timelines, string $prefix, string $parameter = ''): array
{
$tabs = [];
foreach ($timelines as $tab) {
if (is_null($tab->path) && !empty($parameter)) {
$path = $prefix . '?' . http_build_query([$parameter => $tab->code]);
} else {
$path = $tab->path ?? $prefix . '/' . $tab->code;
}
$tabs[$tab->code] = [
'label' => $tab->label,
'url' => $path,
'sel' => $this->selectedTab == $tab->code ? 'active' : '',
'title' => $tab->description,
'id' => $prefix . '-' . $tab->code . '-tab',
'accesskey' => $tab->accessKey,
];
}
return $tabs;
}
/**
* Database query for the channel page
*
* @return array
* @throws \Exception
*/
protected function getChannelItems()
{
$uid = $this->session->getLocalUserId();
if ($this->selectedTab == TimelineEntity::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) {
$cid = Contact::getPublicIdByUserId($uid);
$condition = [
"(`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `relation-thread-score` > ?) OR
((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ?)) OR
(`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))",
$cid, $this->getMedianRelationThreadScore($cid, 4), $this->getMedianComments($uid, 4), $this->getMedianActivities($uid, 4), $cid,
$uid, Contact::FRIEND, Contact::SHARING
];
} elseif ($this->selectedTab == TimelineEntity::FOLLOWERS) {
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $uid, Contact::FOLLOWER];
} elseif ($this->selectedTab == TimelineEntity::SHARERSOFSHARERS) {
$cid = Contact::getPublicIdByUserId($uid);
// @todo Suggest posts from contacts that are followed most by our followers
$condition = [
"`owner-id` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `last-interaction` > ?
AND `relation-cid` IN (SELECT `cid` FROM `contact-relation` WHERE `follows` AND `relation-cid` = ? AND `relation-thread-score` >= ?)
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) {
$condition = ["`media-type` & ?", 1];
} elseif ($this->selectedTab == TimelineEntity::VIDEO) {
$condition = ["`media-type` & ?", 2];
} elseif ($this->selectedTab == TimelineEntity::AUDIO) {
$condition = ["`media-type` & ?", 4];
} elseif ($this->selectedTab == TimelineEntity::LANGUAGE) {
$condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", $this->l10n->convertCodeForLanguageDetection(User::getLanguageCode($uid))];
}
if ($this->selectedTab != TimelineEntity::LANGUAGE) {
$condition = $this->addLanguageCondition($uid, $condition);
}
$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`))", $uid]);
if (($this->selectedTab != TimelineEntity::WHATSHOT) && !is_null($this->accountType)) {
$condition = DBA::mergeConditions($condition, ['contact-type' => $this->accountType]);
}
$params = ['order' => ['created' => true], 'limit' => $this->itemsPerPage];
if (!empty($this->itemUriId)) {
$condition = DBA::mergeConditions($condition, ['uri-id' => $this->itemUriId]);
} else {
if ($this->noSharer) {
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)", $this->session->getLocalUserId()]);
}
if (isset($this->maxId)) {
$condition = DBA::mergeConditions($condition, ["`created` < ?", $this->maxId]);
}
if (isset($this->minId)) {
$condition = DBA::mergeConditions($condition, ["`created` > ?", $this->minId]);
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset($this->maxId)) {
$params['order']['created'] = false;
}
}
}
$items = $this->database->selectToArray('post-engagement', ['uri-id', 'created'], $condition, $params);
if (empty($items)) {
return [];
}
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty($this->itemUriId) && isset($this->minId) && !isset($this->maxId)) {
$items = array_reverse($items);
}
$condition = ['unseen' => true, 'uid' => $uid, 'parent-uri-id' => array_column($items, 'uri-id')];
$this->setItemsSeenByCondition($condition);
return $items;
}
private function addLanguageCondition(int $uid, array $condition): array
{
$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;
}
if (!empty($conditions)) {
$condition[0] .= " AND (`language` IS NULL OR " . implode(' OR ', $conditions) . ")";
}
return $condition;
}
private function getMedianComments(int $uid, int $divider): int
{
$languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
$cache_key = 'Channel:getMedianComments:' . $divider . ':' . implode(':', $languages);
$comments = $this->cache->get($cache_key);
if (!empty($comments)) {
return $comments;
}
$condition = ["`contact-type` != ? AND `comments` > ?", Contact::TYPE_COMMUNITY, 0];
$condition = $this->addLanguageCondition($uid, $condition);
$limit = $this->database->count('post-engagement', $condition) / $divider;
$post = $this->database->selectToArray('post-engagement', ['comments'], $condition, ['order' => ['comments' => true], 'limit' => [$limit, 1]]);
$comments = $post[0]['comments'] ?? 0;
if (empty($comments)) {
return 0;
}
$this->cache->set($cache_key, $comments, Duration::HALF_HOUR);
$this->logger->debug('Calculated median comments', ['divider' => $divider, 'languages' => $languages, 'median' => $comments]);
return $comments;
}
private function getMedianActivities(int $uid, int $divider): int
{
$languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
$cache_key = 'Channel:getMedianActivities:' . $divider . ':' . implode(':', $languages);
$activities = $this->cache->get($cache_key);
if (!empty($activities)) {
return $activities;
}
$condition = ["`contact-type` != ? AND `activities` > ?", Contact::TYPE_COMMUNITY, 0];
$condition = $this->addLanguageCondition($uid, $condition);
$limit = $this->database->count('post-engagement', $condition) / $divider;
$post = $this->database->selectToArray('post-engagement', ['activities'], $condition, ['order' => ['activities' => true], 'limit' => [$limit, 1]]);
$activities = $post[0]['activities'] ?? 0;
if (empty($activities)) {
return 0;
}
$this->cache->set($cache_key, $activities, Duration::HALF_HOUR);
$this->logger->debug('Calculated median activities', ['divider' => $divider, 'languages' => $languages, 'median' => $activities]);
return $activities;
}
private function getMedianRelationThreadScore(int $cid, int $divider): int
{
$cache_key = 'Channel:getThreadScore:' . $cid . ':' . $divider;
$score = $this->cache->get($cache_key);
if (!empty($score)) {
return $score;
}
$condition = ["`relation-cid` = ? AND `relation-thread-score` > ?", $cid, 0];
$limit = $this->database->count('contact-relation', $condition) / $divider;
$relation = $this->database->selectToArray('contact-relation', ['relation-thread-score'], $condition, ['order' => ['relation-thread-score' => true], 'limit' => [$limit, 1]]);
$score = $relation[0]['relation-thread-score'] ?? 0;
if (empty($score)) {
return 0;
}
$this->cache->set($cache_key, $score, Duration::HALF_HOUR);
$this->logger->debug('Calculated median score', ['cid' => $cid, 'divider' => $divider, 'median' => $score]);
return $score;
}
/**
* Computes the displayed items.
*
* Community pages have a restriction on how many successive posts by the same author can show on any given page,
* so we may have to retrieve more content beyond the first query
*
* @return array
* @throws \Exception
*/
protected function getCommunityItems()
{
$items = $this->selectItems();
$maxpostperauthor = (int) $this->config->get('system', 'max_author_posts_community_page');
if ($maxpostperauthor != 0 && $this->selectedTab == 'local') {
$count = 1;
$previousauthor = '';
$numposts = 0;
$selected_items = [];
while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
foreach ($items as $item) {
if ($previousauthor == $item["author-link"]) {
++$numposts;
} else {
$numposts = 0;
}
$previousauthor = $item["author-link"];
if (($numposts < $maxpostperauthor) && (count($selected_items) < $this->itemsPerPage)) {
$selected_items[] = $item;
}
}
// If we're looking at a "previous page", the lookup continues forward in time because the list is
// sorted in chronologically decreasing order
if (isset($this->minId)) {
$this->minId = $items[0]['commented'];
} else {
// In any other case, the lookup continues backwards in time
$this->maxId = $items[count($items) - 1]['commented'];
}
$items = $this->selectItems();
}
} else {
$selected_items = $items;
}
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
$this->setItemsSeenByCondition($condition);
return $selected_items;
}
/**
* Database query for the community page
*
* @return array
* @throws \Exception
* @TODO Move to repository/factory
*/
private function selectItems()
{
if ($this->selectedTab == 'local') {
if (!is_null($this->accountType)) {
$condition = ["`wall` AND `origin` AND `private` = ? AND `owner-contact-type` = ?", Item::PUBLIC, $this->accountType];
} else {
$condition = ["`wall` AND `origin` AND `private` = ?", Item::PUBLIC];
}
} elseif ($this->selectedTab == 'global') {
if (!is_null($this->accountType)) {
$condition = ["`uid` = ? AND `private` = ? AND `owner-contact-type` = ?", 0, Item::PUBLIC, $this->accountType];
} else {
$condition = ["`uid` = ? AND `private` = ?", 0, Item::PUBLIC];
}
} else {
return [];
}
$params = ['order' => ['commented' => true], 'limit' => $this->itemsPerPage];
if (!empty($this->itemUriId)) {
$condition = DBA::mergeConditions($condition, ['uri-id' => $this->itemUriId]);
} else {
if ($this->session->getLocalUserId() && $this->noSharer) {
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)", $this->session->getLocalUserId()]);
}
if (isset($this->maxId)) {
$condition = DBA::mergeConditions($condition, ["`commented` < ?", $this->maxId]);
}
if (isset($this->minId)) {
$condition = DBA::mergeConditions($condition, ["`commented` > ?", $this->minId]);
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset($this->maxId)) {
$params['order']['commented'] = false;
}
}
}
$r = Post::selectThreadForUser($this->session->getLocalUserId() ?: 0, ['uri-id', 'commented', 'author-link'], $condition, $params);
$items = Post::toArray($r);
if (empty($items)) {
return [];
}
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty($this->itemUriId) && isset($this->minId) && !isset($this->maxId)) {
$items = array_reverse($items);
}
return $items;
}
/**
* Sets items as seen
*
* @param array $condition The array with the SQL condition
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
protected function setItemsSeenByCondition(array $condition)
{
if (empty($condition)) {
return;
}
$unseen = Post::exists($condition);
if ($unseen) {
/// @todo handle huge "unseen" updates in the background to avoid timeout errors
Item::update(['unseen' => false], $condition);
}
}
}

View File

@ -23,6 +23,7 @@ namespace Friendica\Module\Settings;
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
@ -51,8 +52,10 @@ class Display extends BaseSettings
private $app;
/** @var SystemMessages */
private $systemMessages;
/** @var TimelineFactory */
protected $timeline;
public function __construct(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(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);
@ -60,6 +63,7 @@ class Display extends BaseSettings
$this->pConfig = $pConfig;
$this->app = $app;
$this->systemMessages = $systemMessages;
$this->timeline = $timeline;
}
protected function post(array $request = [])
@ -76,6 +80,7 @@ class Display extends BaseSettings
$theme = !empty($request['theme']) ? trim($request['theme']) : $user['theme'];
$mobile_theme = !empty($request['mobile_theme']) ? trim($request['mobile_theme']) : '';
$enable_smile = !empty($request['enable_smile']) ? intval($request['enable_smile']) : 0;
$network_timelines = !empty($request['network_timelines']) ? $request['network_timelines'] : [];
$channel_languages = !empty($request['channel_languages']) ? $request['channel_languages'] : [];
$first_day_of_week = !empty($request['first_day_of_week']) ? intval($request['first_day_of_week']) : 0;
$calendar_default_view = !empty($request['calendar_default_view']) ? trim($request['calendar_default_view']) : 'month';
@ -121,6 +126,7 @@ class Display extends BaseSettings
$this->pConfig->set($uid, 'system', 'stay_local' , $stay_local);
$this->pConfig->set($uid, 'system', 'preview_mode' , $preview_mode);
$this->pConfig->set($uid, 'system', 'network_timelines' , $network_timelines);
$this->pConfig->set($uid, 'channel', 'languages' , $channel_languages);
$this->pConfig->set($uid, 'calendar', 'first_day_of_week' , $first_day_of_week);
@ -218,8 +224,10 @@ class Display extends BaseSettings
BBCode::PREVIEW_LARGE => $this->t('Large Image'),
];
$network_timelines = $this->pConfig->get($uid, 'system', 'network_timelines', array_keys($this->getAvailableTimelines($uid, true)));
$channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]);
$languages = $this->l10n->getAvailableLanguages(true);
$timelines = $this->getAvailableTimelines($uid);
$first_day_of_week = $this->pConfig->get($uid, 'calendar', 'first_day_of_week', 0);
$weekdays = [
@ -254,6 +262,7 @@ class Display extends BaseSettings
'$d_ctset' => $this->t('Custom Theme Settings'),
'$d_cset' => $this->t('Content Settings'),
'$stitle' => $this->t('Theme settings'),
'$timeline_title' => $this->t('Timelines'),
'$channel_title' => $this->t('Channels'),
'$calendar_title' => $this->t('Calendar'),
@ -275,10 +284,34 @@ class Display extends BaseSettings
'$stay_local' => ['stay_local' , $this->t('Stay local'), $stay_local, $this->t("Don't go to a remote system when following a contact link.")],
'$preview_mode' => ['preview_mode' , $this->t('Link preview mode'), $preview_mode, $this->t('Appearance of the link preview that is added to each post with a link.'), $preview_modes, false],
'$network_timelines' => ['network_timelines[]', $this->t('Timelines for the network page:'), $network_timelines, $this->t('Select all the timelines that you want to see on your network page.'), $timelines, 'multiple'],
'$channel_languages' => ['channel_languages[]', $this->t('Channel languages:'), $channel_languages, $this->t('Select all languages that you want to see in your channels.'), $languages, 'multiple'],
'$first_day_of_week' => ['first_day_of_week' , $this->t('Beginning of week:') , $first_day_of_week , '', $weekdays , false],
'$calendar_default_view' => ['calendar_default_view', $this->t('Default calendar view:'), $calendar_default_view, '', $calendarViews, false],
]);
}
private function getAvailableTimelines(int $uid, bool $only_network = false): array
{
$timelines = [];
foreach ($this->timeline->getNetworkFeeds('') as $channel) {
$timelines[$channel->code] = $this->t('%s: %s', $channel->label, $channel->description);
}
if ($only_network) {
return $timelines;
}
foreach ($this->timeline->getChannelsForUser($uid) as $channel) {
$timelines[$channel->code] = $this->t('%s: %s', $channel->label, $channel->description);
}
foreach ($this->timeline->getCommunities(true) as $community) {
$timelines[$community->code] = $this->t('%s: %s', $community->label, $community->description);
}
return $timelines;
}
}

View File

@ -38,7 +38,13 @@ class Channel extends ChannelModule
$o = '';
if (!empty($request['force'])) {
$o = $this->conversation->render($this->getItems($request), Conversation::MODE_CHANNEL, true, false, 'created', $this->session->getLocalUserId());
if ($this->timeline->isChannel($this->selectedTab)) {
$items = $this->getChannelItems();
} else {
$items = $this->getCommunityItems();
}
$o = $this->conversation->render($items, Conversation::MODE_CHANNEL, true, false, 'created', $this->session->getLocalUserId());
}
System::htmlUpdateExit($o);

View File

@ -36,11 +36,11 @@ class Community extends CommunityModule
{
protected function rawContent(array $request = [])
{
$this->parseRequest();
$this->parseRequest($request);
$o = '';
if (!empty($request['force'])) {
$o = DI::conversation()->render(self::getItems(), Conversation::MODE_COMMUNITY, true, false, 'commented', DI::userSession()->getLocalUserId());
$o = DI::conversation()->render($this->getCommunityItems(), Conversation::MODE_COMMUNITY, true, false, 'commented', DI::userSession()->getLocalUserId());
}
System::htmlUpdateExit($o);

View File

@ -23,9 +23,6 @@ namespace Friendica\Module\Update;
use Friendica\Content\Conversation;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Module\Conversation\Network as NetworkModule;
class Network extends NetworkModule
@ -46,40 +43,15 @@ class Network extends NetworkModule
System::htmlUpdateExit($o);
}
if (!empty($request['item'])) {
$item = Post::selectFirst(['parent'], ['id' => $request['item']]);
$parent = $item['parent'] ?? 0;
if ($this->timeline->isChannel($this->selectedTab)) {
$items = $this->getChannelItems();
} elseif ($this->timeline->isCommunity($this->selectedTab)) {
$items = $this->getCommunityItems();
} else {
$parent = 0;
$items = $this->getItems();
}
$conditionFields = [];
if (!empty($parent)) {
// Load only a single thread
$conditionFields['parent'] = $parent;
} elseif (self::$order === 'received') {
// Only load new toplevel posts
$conditionFields['unseen'] = true;
$conditionFields['gravity'] = Item::GRAVITY_PARENT;
} else {
// Load all unseen items
$conditionFields['unseen'] = true;
}
$params = ['limit' => 100];
$table = 'network-item-view';
$items = self::getItems($table, $params, $conditionFields);
if (self::$order === 'received') {
$ordering = '`received`';
} elseif (self::$order === 'created') {
$ordering = '`created`';
} else {
$ordering = '`commented`';
}
$o = DI::conversation()->render($items, Conversation::MODE_NETWORK, $profile_uid, false, $ordering, DI::userSession()->getLocalUserId());
$o = $this->conversation->render($items, Conversation::MODE_NETWORK, $profile_uid, false, $this->getOrder(), $this->session->getLocalUserId());
System::htmlUpdateExit($o);
}

View File

@ -672,7 +672,7 @@ return [
],
'/network' => [
'[/]' => [Module\Conversation\Network::class, [R::GET]],
'[/{content}]' => [Module\Conversation\Network::class, [R::GET]],
'/archive/{from:\d\d\d\d-\d\d-\d\d}[/{to:\d\d\d\d-\d\d-\d\d}]' => [Module\Conversation\Network::class, [R::GET]],
'/group/{contact_id:\d+}' => [Module\Conversation\Network::class, [R::GET]],
'/circle/{circle_id:\d+}' => [Module\Conversation\Network::class, [R::GET]],

View File

@ -53,30 +53,18 @@ class UserTest extends MockedTest
'uid' => 1,
'username' => 'maxmuster',
'nickname' => 'Max Muster',
'verified' => true,
'blocked' => false,
'account_removed' => false,
'account_expired' => false,
];
$this->child = [
'uid' => 2,
'username' => 'johndoe',
'nickname' => 'John Doe',
'verified' => true,
'blocked' => false,
'account_removed' => false,
'account_expired' => false,
];
$this->manage = [
'uid' => 3,
'username' => 'janesmith',
'nickname' => 'Jane Smith',
'verified' => true,
'blocked' => false,
'account_removed' => false,
'account_expired' => false,
];
}
@ -106,7 +94,10 @@ class UserTest extends MockedTest
['uid', 'username', 'nickname'],
[
'parent-uid' => $this->parent['uid'],
'account_removed' => false
'verified' => true,
'blocked' => false,
'account_removed' => false,
'account_expired' => false
], [])->andReturn('objectReturn')->once();
$this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
$this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child])->once();
@ -122,7 +113,7 @@ class UserTest extends MockedTest
$this->parent,
$this->child,
$this->manage
], $record);
], $record, 'testIdentitiesAsParent: ' . print_r($record, true));
}
public function testIdentitiesAsChild()
@ -139,8 +130,11 @@ class UserTest extends MockedTest
$this->dbMock->shouldReceive('select')->with('user',
['uid', 'username', 'nickname'],
[
'uid' => $this->parent['uid'],
'account_removed' => false
'uid' => $this->parent['uid'],
'verified' => true,
'blocked' => false,
'account_removed' => false,
'account_expired' => false
], [])->andReturn('objectReturn')->once();
$this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
$this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->parent])->once();
@ -150,7 +144,10 @@ class UserTest extends MockedTest
['uid', 'username', 'nickname'],
[
'parent-uid' => $this->parent['uid'],
'account_removed' => false
'verified' => true,
'blocked' => false,
'account_removed' => false,
'account_expired' => false
], [])->andReturn('objectReturn')->once();
$this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
$this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child, $this->manage])->once();

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,9 @@
{{include file="field_checkbox.tpl" field=$stay_local}}
{{include file="field_select.tpl" field=$preview_mode}}
<h2>{{$timeline_title}}</h2>
{{include file="field_select.tpl" field=$network_timelines}}
<h2>{{$channel_title}}</h2>
{{include file="field_select.tpl" field=$channel_languages}}

View File

@ -7,7 +7,9 @@
</span>
<div id="{{$type}}-desc">{{$desc nofilter}}</div>
<ul role="menu" class="{{$type}}-ul">
{{if $all_label}}
<li role="menuitem" {{if !is_null($selected) && !$selected}}class="selected"{{/if}}><a href="{{$base}}" class="{{$type}}-link{{if !$selected}} {{$type}}-selected{{/if}} {{$type}}-all">{{$all_label}}</a></li>
{{/if}}
{{foreach $options as $option}}
<li role="menuitem" {{if $selected == $option.ref}}class="selected"{{/if}}><a href="{{$base}}{{$type}}={{$option.ref}}" class="{{$type}}-link{{if $selected == $option.ref}} {{$type}}-selected{{/if}}">{{$option.name}}</a></li>
{{/foreach}}

View File

@ -74,6 +74,24 @@
</div>
</div>
<div class="panel">
<div class="section-subtitle-wrapper panel-heading" role="tab" id="timeline-settings-title">
<h2>
<button class="btn-link accordion-toggle collapsed" data-toggle="collapse" data-parent="#settings" href="#timeline-settings-content" aria-expanded="false" aria-controls="timeline-settings-content">
{{$timeline_title}}
</button>
</h2>
</div>
<div id="timeline-settings-content" class="panel-collapse collapse{{if !$theme && !$mobile_theme && !$theme_config}} in{{/if}}" role="tabpanel" aria-labelledby="timeline-settings">
<div class="panel-body">
{{include file="field_select.tpl" field=$network_timelines}}
</div>
<div class="panel-footer">
<button type="submit" name="submit" class="btn btn-primary" value="{{$submit}}">{{$submit}}</button>
</div>
</div>
</div>
<div class="panel">
<div class="section-subtitle-wrapper panel-heading" role="tab" id="channel-settings-title">
<h2>

View File

@ -5,7 +5,9 @@
{{/if}}
<ul class="{{$type}}-ul">
{{if $all_label}}
<li class="tool {{if !$selected}}selected{{/if}}"><a href="{{$base}}" class="{{$type}}-link {{$type}}-all">{{$all_label}}</a>
{{/if}}
{{foreach $options as $option}}
<li class="tool {{if $selected == $option.ref}}selected{{/if}}"><a href="{{$base}}{{$type}}={{$option.ref}}" class="{{$type}}-link">{{$option.name}}</a></li>
{{/foreach}}