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