2020-10-13 06:23:17 +02:00
< ? php
2022-01-02 10:49:50 +01:00
/**
2023-01-01 15:36:24 +01:00
* @ copyright Copyright ( C ) 2010 - 2023 , the Friendica project
2022-01-02 10:49:50 +01:00
*
* @ 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 />.
*
*/
2020-10-13 06:23:17 +02:00
namespace Friendica\Module\Conversation ;
2023-09-09 11:14:36 +02:00
use Friendica\App ;
use Friendica\App\Mode ;
2020-10-13 06:23:17 +02:00
use Friendica\Content\BoundariesPager ;
2023-01-12 07:25:55 +01:00
use Friendica\Content\Conversation ;
2023-09-09 11:14:36 +02:00
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity ;
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory ;
use Friendica\Content\Feature ;
2023-05-30 15:15:17 +02:00
use Friendica\Content\GroupManager ;
2020-10-13 06:23:17 +02:00
use Friendica\Content\Nav ;
use Friendica\Content\Widget ;
use Friendica\Content\Text\HTML ;
2023-09-09 11:14:36 +02:00
use Friendica\Content\Widget\TrendingTags ;
2020-10-13 06:23:17 +02:00
use Friendica\Core\ACL ;
2023-09-09 11:14:36 +02:00
use Friendica\Core\Cache\Capability\ICanCache ;
use Friendica\Core\Config\Capability\IManageConfigValues ;
2020-10-13 06:23:17 +02:00
use Friendica\Core\Hook ;
2023-09-09 11:14:36 +02:00
use Friendica\Core\L10n ;
2022-11-03 01:37:14 +01:00
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues ;
2020-10-13 06:23:17 +02:00
use Friendica\Core\Renderer ;
2022-11-03 01:37:14 +01:00
use Friendica\Core\Session\Capability\IHandleUserSessions ;
2020-10-13 06:23:17 +02:00
use Friendica\Database\DBA ;
2023-09-09 11:14:36 +02:00
use Friendica\Database\Database ;
2020-10-13 06:23:17 +02:00
use Friendica\DI ;
use Friendica\Model\Contact ;
2023-05-14 01:54:35 +02:00
use Friendica\Model\Circle ;
2020-10-13 06:23:17 +02:00
use Friendica\Model\Item ;
2021-01-16 05:16:09 +01:00
use Friendica\Model\Post ;
2020-10-13 06:23:17 +02:00
use Friendica\Model\Profile ;
2021-06-05 22:29:19 +02:00
use Friendica\Model\Verb ;
2020-10-13 06:23:17 +02:00
use Friendica\Module\Contact as ModuleContact ;
2023-09-09 11:14:36 +02:00
use Friendica\Module\Response ;
2020-10-13 06:23:17 +02:00
use Friendica\Module\Security\Login ;
2023-09-09 11:14:36 +02:00
use Friendica\Network\HTTPException ;
use Friendica\Navigation\SystemMessages ;
2020-10-13 06:23:17 +02:00
use Friendica\Util\DateTimeFormat ;
2023-09-09 11:14:36 +02:00
use Friendica\Util\Profiler ;
use Friendica\Protocol\Activity ;
use Psr\Log\LoggerInterface ;
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
class Network extends Timeline
2020-10-13 06:23:17 +02:00
{
/** @var int */
2023-05-14 01:54:35 +02:00
private static $circleId ;
2020-10-13 06:23:17 +02:00
/** @var int */
2023-05-30 15:15:17 +02:00
private static $groupContactId ;
2020-10-13 06:23:17 +02:00
/** @var string */
private static $network ;
/** @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 ;
2023-09-09 11:14:36 +02:00
/** @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 ( 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 -> timeline = $timeline ;
$this -> systemMessages = $systemMessages ;
$this -> conversation = $conversation ;
$this -> page = $page ;
}
2021-11-20 15:38:03 +01:00
protected function content ( array $request = []) : string
2020-10-13 06:23:17 +02:00
{
2023-09-09 11:14:36 +02:00
if ( ! $this -> session -> getLocalUserId ()) {
2020-10-13 06:23:17 +02:00
return Login :: form ();
}
2023-09-09 11:14:36 +02:00
$this -> parseRequest ( $request );
2020-10-13 06:23:17 +02:00
$module = 'network' ;
2023-09-09 11:14:36 +02:00
$this -> page [ 'aside' ] .= Widget :: accountTypes ( $module , self :: $accountTypeString );
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
$arr = [ 'query' => $this -> args -> getQueryString ()];
2020-10-13 06:23:17 +02:00
Hook :: callAll ( 'network_content_init' , $arr );
$o = '' ;
2023-09-09 11:14:36 +02:00
if ( $this -> timeline -> isChannel ( self :: $selectedTab )) {
if ( ! in_array ( self :: $selectedTab , [ TimelineEntity :: FOLLOWERS , TimelineEntity :: FORYOU ]) && $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 ( self :: $selectedTab );
}
$items = $this -> getChannelItems ();
} elseif ( $this -> timeline -> isCommunity ( self :: $selectedTab )) {
if ( $this -> session -> getLocalUserId () && $this -> config -> get ( 'system' , 'community_no_sharer' )) {
$this -> page [ 'aside' ] .= $this -> getNoSharerWidget ( $module );
}
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), 'trending_tags' )) {
$this -> page [ 'aside' ] .= TrendingTags :: getHTML ( self :: $selectedTab );
}
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
$items = $this -> getCommunityItems ();
} else {
$this -> page [ 'aside' ] .= Circle :: sidebarWidget ( $module , $module . '/circle' , 'standard' , self :: $circleId );
$this -> page [ 'aside' ] .= GroupManager :: widget ( $module . '/group' , $this -> session -> getLocalUserId (), self :: $groupContactId );
$this -> page [ 'aside' ] .= Widget :: postedByYear ( $module . '/archive' , $this -> session -> getLocalUserId (), false );
$this -> page [ 'aside' ] .= Widget :: networks ( $module , ! self :: $groupContactId ? self :: $network : '' );
$this -> page [ 'aside' ] .= Widget\SavedSearches :: getHTML ( $this -> args -> getQueryString ());
$this -> page [ 'aside' ] .= Widget :: fileAs ( 'filed' , '' );
// Fetch a page full of parent items for this page
$params = [ 'limit' => self :: $itemsPerPage ];
$table = 'network-thread-view' ;
$items = $this -> getItems ( $table , $params );
}
if ( $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'infinite_scroll' ) && ( $_GET [ 'mode' ] ? ? '' ) != 'minimal' ) {
2020-10-13 06:23:17 +02:00
$tpl = Renderer :: getMarkupTemplate ( 'infinite_scroll_head.tpl' );
2023-09-09 11:14:36 +02:00
$o .= Renderer :: replaceMacros ( $tpl , [ '$reload_uri' => $this -> args -> getQueryString ()]);
2020-10-13 06:23:17 +02:00
}
2023-09-09 11:14:36 +02:00
if ( ! ( isset ( $_GET [ 'mode' ]) and ( $_GET [ 'mode' ] == 'raw' ))) {
$o .= $this -> getTabsHTML ();
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
Nav :: setSelected ( $this -> args -> get ( 0 ));
2020-10-13 06:23:17 +02:00
$content = '' ;
2023-05-30 15:15:17 +02:00
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 ];
2020-10-13 06:23:17 +02:00
$contact = DBA :: selectFirst ( 'contact' , [ 'addr' ], $condition );
if ( ! empty ( $contact [ 'addr' ])) {
$content = '!' . $contact [ 'addr' ];
}
}
$default_permissions = [];
2023-05-14 01:54:35 +02:00
if ( self :: $circleId ) {
$default_permissions [ 'allow_gid' ] = [ self :: $circleId ];
2020-10-13 06:23:17 +02:00
}
$allowedCids = [];
2023-05-30 15:15:17 +02:00
if ( self :: $groupContactId ) {
$allowedCids [] = ( int ) self :: $groupContactId ;
2020-10-13 06:23:17 +02:00
} elseif ( self :: $network ) {
$condition = [
2023-09-09 11:14:36 +02:00
'uid' => $this -> session -> getLocalUserId (),
2020-10-13 06:23:17 +02:00
'network' => self :: $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 )) {
$allowedCids [] = ( int ) $contact [ 'id' ];
}
DBA :: close ( $contactStmt );
}
if ( count ( $allowedCids )) {
$default_permissions [ 'allow_cid' ] = $allowedCids ;
}
$x = [
2023-09-09 11:14:36 +02:00
'lockstate' => self :: $circleId || self :: $groupContactId || self :: $network || ACL :: getLockstateForUserId ( $this -> session -> getLocalUserId ()) ? 'lock' : 'unlock' ,
'acl' => ACL :: getFullSelectorHTML ( $this -> page , $this -> session -> getLocalUserId (), true , $default_permissions ),
2023-05-30 15:15:17 +02:00
'bang' => (( self :: $circleId || self :: $groupContactId || self :: $network ) ? '!' : '' ),
2020-10-13 06:23:17 +02:00
'content' => $content ,
];
2023-09-09 11:14:36 +02:00
$o .= $this -> conversation -> statusEditor ( $x );
2020-10-13 06:23:17 +02:00
}
2023-05-14 01:54:35 +02:00
if ( self :: $circleId ) {
2023-09-09 11:14:36 +02:00
$circle = DBA :: selectFirst ( 'group' , [ 'name' ], [ 'id' => self :: $circleId , 'uid' => $this -> session -> getLocalUserId ()]);
2023-05-14 01:54:35 +02:00
if ( ! DBA :: isResult ( $circle )) {
2023-09-09 11:14:36 +02:00
$this -> systemMessages -> addNotice ( $this -> l10n -> t ( 'No such circle' ));
2020-10-13 06:23:17 +02:00
}
$o = Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'section_title.tpl' ), [
2023-09-09 11:14:36 +02:00
'$title' => $this -> l10n -> t ( 'Circle: %s' , $circle [ 'name' ])
2020-10-13 06:23:17 +02:00
]) . $o ;
2023-05-30 15:15:17 +02:00
} elseif ( self :: $groupContactId ) {
$contact = Contact :: getById ( self :: $groupContactId );
2020-10-13 06:23:17 +02:00
if ( DBA :: isResult ( $contact )) {
2022-11-04 12:03:55 +01:00
$o = Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'contact/list.tpl' ), [
2020-10-13 06:23:17 +02:00
'contacts' => [ ModuleContact :: getContactTemplateVars ( $contact )],
2023-09-09 11:14:36 +02:00
'id' => $this -> args -> get ( 0 ),
2020-10-13 06:23:17 +02:00
]) . $o ;
} else {
2023-09-09 11:14:36 +02:00
$this -> systemMessages -> addNotice ( $this -> l10n -> t ( 'Invalid contact.' ));
2020-10-13 06:23:17 +02:00
}
2023-09-09 11:14:36 +02:00
} elseif ( ! $this -> config -> get ( 'theme' , 'hide_eventlist' )) {
2020-10-13 06:23:17 +02:00
$o .= Profile :: getBirthdays ();
$o .= Profile :: getEventsReminderHTML ();
}
if ( self :: $order === 'received' ) {
$ordering = '`received`' ;
2022-04-20 23:03:33 +02:00
} elseif ( self :: $order === 'created' ) {
$ordering = '`created`' ;
2020-10-13 06:23:17 +02:00
} else {
$ordering = '`commented`' ;
}
2023-09-09 11:14:36 +02:00
$o .= $this -> conversation -> render ( $items , Conversation :: MODE_NETWORK , false , false , $ordering , $this -> session -> getLocalUserId ());
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
if ( $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'infinite_scroll' )) {
2020-10-13 06:23:17 +02:00
$o .= HTML :: scrollLoader ();
} else {
$pager = new BoundariesPager (
2023-09-09 11:14:36 +02:00
$this -> l10n ,
$this -> args -> getQueryString (),
2020-11-11 09:05:12 +01:00
$items [ 0 ][ self :: $order ] ? ? null ,
$items [ count ( $items ) - 1 ][ self :: $order ] ? ? null ,
2020-10-13 06:23:17 +02:00
self :: $itemsPerPage
);
$o .= $pager -> renderMinimal ( count ( $items ));
}
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 )
{
if ( empty ( $condition )) {
return ;
}
2021-01-16 05:16:09 +01:00
$unseen = Post :: exists ( $condition );
2020-10-13 06:23:17 +02:00
if ( $unseen ) {
2020-12-26 19:51:36 +01:00
/// @todo handle huge "unseen" updates in the background to avoid timeout errors
2020-10-13 06:23:17 +02:00
Item :: update ([ 'unseen' => false ], $condition );
}
}
/**
* Get the network tabs menu
*
* @ return string Html of the network tabs
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
2023-09-09 11:14:36 +02:00
private function getTabsHTML ()
2020-10-13 06:23:17 +02:00
{
2023-09-09 11:14:36 +02:00
// @todo user confgurable selection of tabs
$tabs = $this -> getTabArray ( $this -> timeline -> getNetworkFeeds ( $this -> args -> getCommand ()), 'network' );
2020-10-13 06:23:17 +02:00
$arr = [ 'tabs' => $tabs ];
Hook :: callAll ( 'network_tabs' , $arr );
$tpl = Renderer :: getMarkupTemplate ( 'common_tabs.tpl' );
return Renderer :: replaceMacros ( $tpl , [ '$tabs' => $arr [ 'tabs' ]]);
}
2023-09-09 11:14:36 +02:00
protected function parseRequest ( array $request )
2020-10-13 06:23:17 +02:00
{
2023-09-09 11:14:36 +02:00
parent :: parseRequest ( $request );
2023-06-25 22:37:11 +02:00
self :: $circleId = ( int )( $this -> parameters [ 'circle_id' ] ? ? 0 );
2020-10-13 06:23:17 +02:00
2023-06-25 22:37:11 +02:00
self :: $groupContactId = ( int )( $this -> parameters [ 'contact_id' ] ? ? 0 );
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
if ( ! self :: $selectedTab ) {
self :: $selectedTab = self :: getTimelineOrderBySession ( DI :: userSession (), $this -> pConfig );
} elseif ( ! $this -> timeline -> isChannel ( self :: $selectedTab ) && ! $this -> timeline -> isCommunity ( self :: $selectedTab )) {
throw new HTTPException\BadRequestException ( $this -> l10n -> t ( 'Network feed not available.' ));
}
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
if ( ! empty ( $request [ 'star' ])) {
self :: $selectedTab = TimelineEntity :: STAR ;
2020-12-19 17:48:12 +01:00
self :: $star = true ;
} else {
2023-09-09 11:14:36 +02:00
self :: $star = self :: $selectedTab == TimelineEntity :: STAR ;
2020-10-13 06:23:17 +02:00
}
2023-09-09 11:14:36 +02:00
if ( ! empty ( $request [ 'mention' ])) {
self :: $selectedTab = TimelineEntity :: MENTION ;
2020-12-19 17:48:12 +01:00
self :: $mention = true ;
} else {
2023-09-09 11:14:36 +02:00
self :: $mention = self :: $selectedTab == TimelineEntity :: MENTION ;
2020-10-13 06:23:17 +02:00
}
2023-09-09 11:14:36 +02:00
if ( ! empty ( $request [ 'order' ])) {
self :: $selectedTab = $request [ 'order' ];
self :: $order = $request [ 'order' ];
2021-02-21 12:14:35 +01:00
self :: $star = false ;
self :: $mention = false ;
2023-09-09 11:14:36 +02:00
} elseif ( in_array ( self :: $selectedTab , [ TimelineEntity :: RECEIVED , TimelineEntity :: STAR ])) {
2020-10-30 23:13:14 +01:00
self :: $order = 'received' ;
2023-09-09 11:14:36 +02:00
} elseif (( self :: $selectedTab == TimelineEntity :: CREATED ) || $this -> timeline -> isChannel ( self :: $selectedTab )) {
2022-04-20 23:03:33 +02:00
self :: $order = 'created' ;
2022-04-21 07:52:08 +02:00
} else {
self :: $order = 'commented' ;
2020-10-13 06:23:17 +02:00
}
2020-10-17 20:52:05 +02:00
self :: $selectedTab = self :: $selectedTab ? ? self :: $order ;
2021-02-21 13:18:50 +01:00
// Prohibit combined usage of "star" and "mention"
2023-09-09 11:14:36 +02:00
if ( self :: $selectedTab == TimelineEntity :: STAR ) {
2021-02-21 13:18:50 +01:00
self :: $mention = false ;
2023-09-09 11:14:36 +02:00
} elseif ( self :: $selectedTab == TimelineEntity :: MENTION ) {
2021-02-21 13:18:50 +01:00
self :: $star = false ;
}
2023-09-09 11:14:36 +02:00
$this -> session -> set ( 'network-tab' , self :: $selectedTab );
$this -> pConfig -> set ( $this -> session -> getLocalUserId (), 'network.view' , 'selected_tab' , self :: $selectedTab );
2020-10-13 06:23:17 +02:00
2023-09-09 11:14:36 +02:00
self :: $network = $request [ 'nets' ] ? ? '' ;
2020-10-13 06:23:17 +02:00
2021-11-14 23:19:25 +01:00
self :: $dateFrom = $this -> parameters [ 'from' ] ? ? '' ;
self :: $dateTo = $this -> parameters [ 'to' ] ? ? '' ;
2020-10-13 06:23:17 +02:00
2020-10-17 09:31:03 +02:00
switch ( self :: $order ) {
2020-10-13 06:23:17 +02:00
case 'received' :
2023-09-09 11:14:36 +02:00
self :: $max_id = $request [ 'last_received' ] ? ? self :: $max_id ;
2020-10-13 06:23:17 +02:00
break ;
case 'created' :
2023-09-09 11:14:36 +02:00
self :: $max_id = $request [ 'last_created' ] ? ? self :: $max_id ;
2020-10-13 06:23:17 +02:00
break ;
case 'uriid' :
2023-09-09 11:14:36 +02:00
self :: $max_id = $request [ 'last_uriid' ] ? ? self :: $max_id ;
2020-10-13 06:23:17 +02:00
break ;
2020-10-24 15:11:44 +02:00
default :
self :: $order = 'commented' ;
2023-09-09 11:14:36 +02:00
self :: $max_id = $request [ 'last_commented' ] ? ? self :: $max_id ;
2020-10-13 06:23:17 +02:00
}
}
2023-09-09 11:14:36 +02:00
protected function getItems ( string $table , array $params , array $conditionFields = [])
2020-10-13 06:23:17 +02:00
{
2023-09-09 11:14:36 +02:00
$conditionFields [ 'uid' ] = $this -> session -> getLocalUserId ();
2020-10-13 06:23:17 +02:00
$conditionStrings = [];
2020-10-14 04:30:40 +02:00
if ( ! is_null ( self :: $accountType )) {
2020-10-13 06:23:17 +02:00
$conditionFields [ 'contact-type' ] = self :: $accountType ;
}
if ( self :: $star ) {
$conditionFields [ 'starred' ] = true ;
}
if ( self :: $mention ) {
$conditionFields [ 'mention' ] = true ;
}
if ( self :: $network ) {
$conditionFields [ 'network' ] = self :: $network ;
}
if ( self :: $dateFrom ) {
2021-10-03 18:38:47 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `received` <= ? " , DateTimeFormat :: convert ( self :: $dateFrom , 'UTC' , DI :: app () -> getTimeZone ())]);
2020-10-13 06:23:17 +02:00
}
if ( self :: $dateTo ) {
2021-10-03 18:38:47 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `received` >= ? " , DateTimeFormat :: convert ( self :: $dateTo , 'UTC' , DI :: app () -> getTimeZone ())]);
2020-10-13 06:23:17 +02:00
}
2023-05-14 01:54:35 +02:00
if ( self :: $circleId ) {
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?) " , self :: $circleId ]);
2023-05-30 15:15:17 +02:00
} elseif ( self :: $groupContactId ) {
2023-01-01 15:36:24 +01:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings ,
2022-09-24 19:56:07 +02:00
[ " ((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?))) " ,
2023-09-09 11:14:36 +02:00
self :: $groupContactId , self :: $groupContactId , Item :: GRAVITY_ACTIVITY , Verb :: getID ( Activity :: ANNOUNCE ), $this -> session -> getLocalUserId ()]);
2020-10-13 06:23:17 +02:00
}
// Currently only the order modes "received" and "commented" are in use
2023-09-09 14:00:22 +02:00
if ( ! empty ( self :: $item_uri_id )) {
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ 'uri-id' => self :: $item_uri_id ]);
} else {
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 ;
}
2020-10-13 06:23:17 +02:00
}
2023-09-09 14:00:22 +02:00
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 ;
}
2020-10-13 06:23:17 +02:00
}
}
if ( isset ( self :: $min_id ) && ! isset ( self :: $max_id )) {
// 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 ];
} else {
$params [ 'order' ] = [ self :: $order => true ];
}
$items = DBA :: selectToArray ( $table , [], DBA :: mergeConditions ( $conditionFields , $conditionStrings ), $params );
// min_id quirk, continued
if ( isset ( self :: $min_id ) && ! isset ( self :: $max_id )) {
$items = array_reverse ( $items );
}
if ( DBA :: isResult ( $items )) {
2023-06-25 15:33:01 +02:00
$parents = array_column ( $items , 'uri-id' );
2020-10-17 09:31:03 +02:00
} else {
$parents = [];
2020-10-13 06:23:17 +02:00
}
2023-05-14 01:54:35 +02:00
// We aren't going to try and figure out at the item, circle, and page
2020-10-13 06:23:17 +02:00
// 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.
2023-05-30 15:15:17 +02:00
if ( ! self :: $circleId && ! self :: $groupContactId && ! self :: $star && ! self :: $mention ) {
2023-09-09 11:14:36 +02:00
$condition = [ 'unseen' => true , 'uid' => $this -> session -> getLocalUserId ()];
2020-10-13 06:23:17 +02:00
self :: setItemsSeenByCondition ( $condition );
2020-10-17 09:31:03 +02:00
} elseif ( ! empty ( $parents )) {
2023-09-09 11:14:36 +02:00
$condition = [ 'unseen' => true , 'uid' => $this -> session -> getLocalUserId (), 'parent-uri-id' => $parents ];
2020-10-13 06:23:17 +02:00
self :: setItemsSeenByCondition ( $condition );
}
return $items ;
}
2022-11-03 01:37:14 +01:00
/**
* Returns the selected network tab of the currently logged - in user
*
* @ param IHandleUserSessions $session
* @ param IManagePersonalConfigValues $pconfig
* @ return string
*/
public static function getTimelineOrderBySession ( IHandleUserSessions $session , IManagePersonalConfigValues $pconfig ) : string
{
return $session -> get ( 'network-tab' )
? ? $pconfig -> get ( $session -> getLocalUserId (), 'network.view' , 'selected_tab' )
? ? '' ;
}
2020-10-13 06:23:17 +02:00
}