2020-10-13 00:23:17 -04:00
< ? php
2022-01-02 10:49:50 +01:00
/**
2024-01-02 20:57:26 +00:00
* @ copyright Copyright ( C ) 2010 - 2024 , 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 00:23:17 -04:00
namespace Friendica\Module\Conversation ;
2023-09-09 09:14:36 +00:00
use Friendica\App ;
use Friendica\App\Mode ;
2020-10-13 00:23:17 -04:00
use Friendica\Content\BoundariesPager ;
2023-01-12 06:25:55 +00:00
use Friendica\Content\Conversation ;
2024-01-26 13:51:20 +00:00
use Friendica\Content\Conversation\Entity\Channel ;
2023-10-05 05:36:12 +00:00
use Friendica\Content\Conversation\Entity\Network as NetworkEntity ;
2023-09-09 09:14:36 +00:00
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory ;
2023-10-07 05:44:24 -04:00
use Friendica\Content\Conversation\Repository\UserDefinedChannel ;
2023-10-05 05:36:12 +00:00
use Friendica\Content\Conversation\Factory\Channel as ChannelFactory ;
2023-10-05 19:10:20 +00:00
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory ;
2023-10-05 05:36:12 +00:00
use Friendica\Content\Conversation\Factory\Community as CommunityFactory ;
use Friendica\Content\Conversation\Factory\Network as NetworkFactory ;
2023-09-09 09:14:36 +00:00
use Friendica\Content\Feature ;
2023-05-30 09:15:17 -04:00
use Friendica\Content\GroupManager ;
2020-10-13 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04:00
use Friendica\Core\Hook ;
2023-09-09 09:14:36 +00:00
use Friendica\Core\L10n ;
2022-11-02 20:37:14 -04:00
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues ;
2020-10-13 00:23:17 -04:00
use Friendica\Core\Renderer ;
2022-11-02 20:37:14 -04:00
use Friendica\Core\Session\Capability\IHandleUserSessions ;
2020-10-13 00:23:17 -04:00
use Friendica\Database\DBA ;
2023-09-09 09:14:36 +00:00
use Friendica\Database\Database ;
2020-10-13 00:23:17 -04:00
use Friendica\Model\Contact ;
2023-05-13 19:54:35 -04:00
use Friendica\Model\Circle ;
2020-10-13 00:23:17 -04:00
use Friendica\Model\Profile ;
2023-09-09 09:14:36 +00:00
use Friendica\Module\Response ;
2020-10-13 00:23:17 -04: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 00:23:17 -04:00
use Friendica\Util\DateTimeFormat ;
2023-09-09 09:14:36 +00:00
use Friendica\Util\Profiler ;
use Psr\Log\LoggerInterface ;
2020-10-13 00:23:17 -04:00
2023-09-09 09:14:36 +00:00
class Network extends Timeline
2020-10-13 00:23:17 -04:00
{
/** @var int */
2023-09-09 14:24:24 +00:00
protected $circleId ;
2020-10-13 00:23:17 -04:00
/** @var string */
2023-09-09 14:24:24 +00:00
protected $dateFrom ;
2020-10-13 00:23:17 -04:00
/** @var string */
2023-09-09 14:24:24 +00:00
protected $dateTo ;
2020-10-13 00:23:17 -04:00
/** @var int */
2023-09-09 14:24:24 +00:00
protected $star ;
2020-10-13 00:23:17 -04:00
/** @var int */
2023-09-09 14:24:24 +00:00
protected $mention ;
2020-10-13 00:23:17 -04: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-10-05 05:36:12 +00:00
/** @var ChannelFactory */
2023-10-06 11:38:29 +00:00
protected $channel ;
2023-10-05 19:10:20 +00:00
/** @var UserDefinedChannelFactory */
protected $userDefinedChannel ;
2023-10-05 05:36:12 +00:00
/** @var CommunityFactory */
protected $community ;
/** @var NetworkFactory */
protected $networkFactory ;
2023-10-07 05:44:24 -04:00
public function __construct ( UserDefinedChannelFactory $userDefinedChannel , NetworkFactory $network , CommunityFactory $community , ChannelFactory $channelFactory , UserDefinedChannel $channel , 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
{
2023-09-19 09:05:28 +00:00
parent :: __construct ( $channel , $mode , $session , $database , $pConfig , $config , $cache , $l10n , $baseUrl , $args , $logger , $profiler , $response , $server , $parameters );
2023-09-09 09:14:36 +00:00
2023-10-05 19:10:20 +00:00
$this -> app = $app ;
$this -> timeline = $timeline ;
$this -> systemMessages = $systemMessages ;
$this -> conversation = $conversation ;
$this -> page = $page ;
2023-10-06 11:38:29 +00:00
$this -> channel = $channelFactory ;
2023-10-05 19:10:20 +00:00
$this -> community = $community ;
$this -> networkFactory = $network ;
$this -> userDefinedChannel = $userDefinedChannel ;
2023-09-09 09:14:36 +00:00
}
2021-11-20 15:38:03 +01:00
protected function content ( array $request = []) : string
2020-10-13 00:23:17 -04:00
{
2023-09-09 09:14:36 +00:00
if ( ! $this -> session -> getLocalUserId ()) {
2020-10-13 00:23:17 -04:00
return Login :: form ();
}
2023-09-09 09:14:36 +00:00
$this -> parseRequest ( $request );
2020-10-13 00:23:17 -04:00
$module = 'network' ;
2023-09-09 09:14:36 +00:00
$arr = [ 'query' => $this -> args -> getQueryString ()];
2020-10-13 00:23:17 -04:00
Hook :: callAll ( 'network_content_init' , $arr );
$o = '' ;
2024-03-24 20:00:19 +00:00
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: CIRCLES )) {
$this -> page [ 'aside' ] .= Circle :: sidebarWidget ( $module , $module . '/circle' , 'standard' , $this -> circleId );
}
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: GROUPS )) {
$this -> page [ 'aside' ] .= GroupManager :: widget ( $this -> session -> getLocalUserId ());
}
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: ARCHIVE )) {
$this -> page [ 'aside' ] .= Widget :: postedByYear ( $module . '/archive' , $this -> session -> getLocalUserId (), false );
}
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: NETWORKS )) {
$this -> page [ 'aside' ] .= Widget :: networks ( $module , $this -> network );
}
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: ACCOUNTS )) {
$this -> page [ 'aside' ] .= Widget :: accountTypes ( $module , $this -> accountTypeString );
}
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: CHANNELS )) {
$this -> page [ 'aside' ] .= Widget :: channels ( $module , $this -> selectedTab , $this -> session -> getLocalUserId ());
}
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: SEARCHES )) {
$this -> page [ 'aside' ] .= Widget\SavedSearches :: getHTML ( $this -> args -> getQueryString ());
}
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: FOLDERS )) {
$this -> page [ 'aside' ] .= Widget :: fileAs ( 'filed' , '' );
}
2024-01-26 13:51:20 +00:00
if (( $this -> channel -> isTimeline ( $this -> selectedTab ) || $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ())) &&
2024-03-24 20:00:19 +00:00
! in_array ( $this -> selectedTab , [ Channel :: FOLLOWERS , Channel :: FORYOU , Channel :: DISCOVER ]) && Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: NOSHARER )) {
2024-01-26 13:51:20 +00:00
$this -> page [ 'aside' ] .= $this -> getNoSharerWidget ( 'network' );
}
2024-03-24 13:42:48 +00:00
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), Feature :: TRENDING_TAGS )) {
2023-09-17 10:09:07 +00:00
$this -> page [ 'aside' ] .= TrendingTags :: getHTML ( $this -> selectedTab );
}
2023-09-09 09:14:36 +00:00
if ( $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'infinite_scroll' ) && ( $_GET [ 'mode' ] ? ? '' ) != 'minimal' ) {
2020-10-13 00:23:17 -04: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 00:23:17 -04:00
}
2023-11-28 15:21:20 +00:00
if ( ! $this -> raw ) {
2023-09-09 09:14:36 +00:00
$o .= $this -> getTabsHTML ();
2020-10-13 00:23:17 -04:00
2023-09-09 09:14:36 +00:00
Nav :: setSelected ( $this -> args -> get ( 0 ));
2020-10-13 00:23:17 -04:00
$default_permissions = [];
2023-09-09 14:24:24 +00:00
if ( $this -> circleId ) {
$default_permissions [ 'allow_gid' ] = [ $this -> circleId ];
2020-10-13 00:23:17 -04:00
}
$allowedCids = [];
2024-01-02 20:45:02 +00:00
if ( $this -> network ) {
2020-10-13 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04:00
$allowedCids [] = ( int ) $contact [ 'id' ];
}
2023-09-09 14:31:12 +00:00
$this -> database -> close ( $contactStmt );
2020-10-13 00:23:17 -04:00
}
if ( count ( $allowedCids )) {
$default_permissions [ 'allow_cid' ] = $allowedCids ;
}
$x = [
2024-01-02 20:45:02 +00:00
'lockstate' => $this -> circleId || $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 ),
2024-01-02 20:45:02 +00:00
'bang' => (( $this -> circleId || $this -> network ) ? '!' : '' ),
2024-01-31 19:09:57 +01:00
'content' => '' ,
2020-10-13 00:23:17 -04:00
];
2023-09-09 09:14:36 +00:00
$o .= $this -> conversation -> statusEditor ( $x );
2020-10-13 00:23:17 -04:00
2023-11-28 15:21:20 +00:00
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' ));
}
2020-10-13 00:23:17 -04:00
2023-11-28 15:21:20 +00:00
$o = Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'section_title.tpl' ), [
'$title' => $this -> l10n -> t ( 'Circle: %s' , $circle [ 'name' ])
2020-10-13 00:23:17 -04:00
]) . $o ;
2023-11-28 15:21:20 +00:00
} elseif ( Profile :: shouldDisplayEventList ( $this -> session -> getLocalUserId (), $this -> mode )) {
$o .= Profile :: getBirthdays ( $this -> session -> getLocalUserId ());
$o .= Profile :: getEventsReminderHTML ( $this -> session -> getLocalUserId (), $this -> session -> getPublicContactId ());
2020-10-13 00:23:17 -04:00
}
}
2023-10-14 18:39:35 +00:00
try {
if ( $this -> channel -> isTimeline ( $this -> selectedTab ) || $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ())) {
2024-04-19 21:09:23 +00:00
$items = $this -> getChannelItems ( $request , $this -> session -> getLocalUserId ());
2023-10-14 18:39:35 +00:00
} elseif ( $this -> community -> isTimeline ( $this -> selectedTab )) {
$items = $this -> getCommunityItems ();
} else {
$items = $this -> getItems ();
}
$o .= $this -> conversation -> render ( $items , Conversation :: MODE_NETWORK , false , false , $this -> getOrder (), $this -> session -> getLocalUserId ());
} catch ( \Exception $e ) {
$o .= $this -> l10n -> t ( 'Error %d (%s) while fetching the timeline.' , $e -> getCode (), $e -> getMessage ());
}
2020-10-13 00:23:17 -04:00
2023-09-09 09:14:36 +00:00
if ( $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'infinite_scroll' )) {
2020-10-13 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04:00
{
2023-10-05 05:36:12 +00:00
$tabs = $this -> getTabArray ( $this -> networkFactory -> getTimelines ( $this -> args -> getCommand ()), 'network' );
2020-10-13 00:23:17 -04:00
2023-09-09 17:38:09 +00:00
$network_timelines = $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'network_timelines' , []);
if ( ! empty ( $network_timelines )) {
2023-10-06 11:38:29 +00:00
$tabs = array_merge ( $tabs , $this -> getTabArray ( $this -> channel -> getTimelines ( $this -> session -> getLocalUserId ()), 'network' , 'channel' ));
2023-10-07 05:44:24 -04:00
$tabs = array_merge ( $tabs , $this -> getTabArray ( $this -> channelRepository -> selectByUid ( $this -> session -> getLocalUserId ()), 'network' , 'channel' ));
2023-10-05 05:36:12 +00:00
$tabs = array_merge ( $tabs , $this -> getTabArray ( $this -> community -> getTimelines ( true ), 'network' , 'channel' ));
2023-09-09 17:38:09 +00:00
}
2020-10-13 00:23:17 -04: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-19 09:23:27 +00:00
foreach ( $arr [ 'tabs' ] as $tab ) {
if ( in_array ( $tab [ 'code' ], $network_timelines )) {
$tabs [] = $tab ;
2023-09-09 17:38:09 +00:00
}
}
} else {
$tabs = $arr [ 'tabs' ];
}
2020-10-13 00:23:17 -04:00
$tpl = Renderer :: getMarkupTemplate ( 'common_tabs.tpl' );
2023-09-09 17:38:09 +00:00
return Renderer :: replaceMacros ( $tpl , [ '$tabs' => $tabs ]);
2020-10-13 00:23:17 -04:00
}
2023-09-09 09:14:36 +00:00
protected function parseRequest ( array $request )
2020-10-13 00:23:17 -04: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 00:23:17 -04:00
2023-09-09 12:48:51 +00:00
if ( ! $this -> selectedTab ) {
2024-03-25 07:20:41 +00:00
$this -> selectedTab = $this -> getTimelineOrderBySession ();
2023-10-06 11:38:29 +00:00
} elseif ( ! $this -> networkFactory -> isTimeline ( $this -> selectedTab ) && ! $this -> channel -> isTimeline ( $this -> selectedTab ) && ! $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ()) && ! $this -> community -> isTimeline ( $this -> selectedTab )) {
2023-09-09 09:14:36 +00:00
throw new HTTPException\BadRequestException ( $this -> l10n -> t ( 'Network feed not available.' ));
}
2024-01-02 20:45:02 +00:00
if (( $this -> network || $this -> circleId ) && ( $this -> channel -> isTimeline ( $this -> selectedTab ) || $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ()) || $this -> community -> isTimeline ( $this -> selectedTab ))) {
2023-10-05 05:36:12 +00:00
$this -> selectedTab = NetworkEntity :: RECEIVED ;
2023-09-17 11:01:04 +00:00
}
2023-09-09 09:14:36 +00:00
if ( ! empty ( $request [ 'star' ])) {
2023-10-05 05:36:12 +00:00
$this -> selectedTab = NetworkEntity :: STAR ;
2023-09-09 14:24:24 +00:00
$this -> star = true ;
2020-12-19 16:48:12 +00:00
} else {
2023-10-05 05:36:12 +00:00
$this -> star = $this -> selectedTab == NetworkEntity :: STAR ;
2020-10-13 00:23:17 -04:00
}
2023-09-09 09:14:36 +00:00
if ( ! empty ( $request [ 'mention' ])) {
2023-10-05 05:36:12 +00:00
$this -> selectedTab = NetworkEntity :: MENTION ;
2023-09-09 14:24:24 +00:00
$this -> mention = true ;
2020-12-19 16:48:12 +00:00
} else {
2023-10-05 05:36:12 +00:00
$this -> mention = $this -> selectedTab == NetworkEntity :: MENTION ;
2020-10-13 00:23:17 -04: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-10-05 05:36:12 +00:00
} elseif ( in_array ( $this -> selectedTab , [ NetworkEntity :: RECEIVED , NetworkEntity :: STAR ]) || $this -> community -> isTimeline ( $this -> selectedTab )) {
2023-09-09 14:24:24 +00:00
$this -> order = 'received' ;
2023-10-06 11:38:29 +00:00
} elseif (( $this -> selectedTab == NetworkEntity :: CREATED ) || $this -> channel -> isTimeline ( $this -> selectedTab ) || $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ())) {
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 00:23:17 -04:00
}
2023-09-20 06:36:47 +00:00
$this -> selectedTab = $this -> selectedTab ? ? $this -> order ;
2023-09-17 17:44:33 +00:00
// Upon updates in the background and order by last comment we order by received date,
2023-09-16 04:21:59 +00:00
// since otherwise the feed will optically jump, when some already visible thread has been updated.
2023-10-05 05:36:12 +00:00
if ( $this -> update && ( $this -> selectedTab == NetworkEntity :: COMMENTED )) {
2023-09-16 04:21:59 +00:00
$this -> order = 'received' ;
2023-09-20 06:36:47 +00:00
$request [ 'last_received' ] = $request [ 'last_commented' ] ? ? null ;
$request [ 'first_received' ] = $request [ 'first_commented' ] ? ? null ;
2023-09-16 04:21:59 +00:00
}
2021-02-21 12:18:50 +00:00
// Prohibit combined usage of "star" and "mention"
2023-10-05 05:36:12 +00:00
if ( $this -> selectedTab == NetworkEntity :: STAR ) {
2023-09-09 14:24:24 +00:00
$this -> mention = false ;
2023-10-05 05:36:12 +00:00
} elseif ( $this -> selectedTab == NetworkEntity :: 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 00:23:17 -04:00
2023-09-09 14:24:24 +00:00
$this -> network = $request [ 'nets' ] ? ? '' ;
2020-10-13 00:23:17 -04:00
2023-09-09 14:24:24 +00:00
$this -> dateFrom = $this -> parameters [ 'from' ] ? ? '' ;
$this -> dateTo = $this -> parameters [ 'to' ] ? ? '' ;
2020-10-13 00:23:17 -04:00
2024-02-04 07:14:57 +00:00
$this -> setMaxMinByOrder ( $request );
2024-03-25 07:20:41 +00:00
if ( is_null ( $this -> maxId ) && ! is_null ( $this -> minId )) {
$this -> session -> set ( 'network-request' , $request );
$this -> pConfig -> set ( $this -> session -> getLocalUserId (), 'network.view' , 'request' , $request );
}
2020-10-13 00:23:17 -04:00
}
2024-04-02 21:30:07 +00:00
protected function setPing ( bool $ping )
{
$this -> ping = $ping ;
}
2023-09-09 13:26:20 +00:00
protected function getItems ()
2020-10-13 00:23:17 -04:00
{
2023-09-09 13:26:20 +00:00
$conditionFields = [ 'uid' => $this -> session -> getLocalUserId ()];
2020-10-13 00:23:17 -04:00
$conditionStrings = [];
2023-09-09 12:48:51 +00:00
if ( ! is_null ( $this -> accountType )) {
$conditionFields [ 'contact-type' ] = $this -> accountType ;
2020-10-13 00:23:17 -04:00
}
2023-09-09 14:24:24 +00:00
if ( $this -> star ) {
2020-10-13 00:23:17 -04:00
$conditionFields [ 'starred' ] = true ;
}
2023-09-09 14:24:24 +00:00
if ( $this -> mention ) {
2020-10-13 00:23:17 -04:00
$conditionFields [ 'mention' ] = true ;
}
2023-09-09 14:24:24 +00:00
if ( $this -> network ) {
$conditionFields [ 'network' ] = $this -> network ;
2020-10-13 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04: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 ]);
2020-10-13 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04: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 00:23:17 -04:00
} else {
2023-09-09 14:24:24 +00:00
$params [ 'order' ] = [ $this -> order => true ];
2020-10-13 00:23:17 -04:00
}
2024-05-26 16:00:27 +00:00
$items = $this -> database -> selectToArray ( $this -> circleId ? 'network-thread-circle-view' : 'network-thread-view' , [], DBA :: mergeConditions ( $conditionFields , $conditionStrings ), $params );
2020-10-13 00:23:17 -04:00
// min_id quirk, continued
2023-09-09 13:02:20 +00:00
if ( isset ( $this -> minId ) && ! isset ( $this -> maxId )) {
2020-10-13 00:23:17 -04: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 00:23:17 -04:00
}
2023-05-13 19:54:35 -04:00
// We aren't going to try and figure out at the item, circle, and page
2020-10-13 00:23:17 -04: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.
2024-01-02 20:45:02 +00:00
if ( ! $this -> circleId && ! $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 00:23:17 -04:00
}
return $items ;
}
2022-11-02 20:37:14 -04:00
/**
* Returns the selected network tab of the currently logged - in user
*
* @ return string
*/
2024-03-25 07:20:41 +00:00
private function getTimelineOrderBySession () : string
2022-11-02 20:37:14 -04:00
{
2024-03-25 07:20:41 +00:00
return $this -> session -> get ( 'network-tab' )
? ? $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'network.view' , 'selected_tab' )
2022-11-02 20:37:14 -04:00
? ? '' ;
}
2024-03-25 07:20:41 +00:00
/**
* Returns the lst request parameters of the currently logged - in user
*
* @ return array
*/
protected function getTimelineRequestBySession () : array
{
return $this -> session -> get ( 'network-request' )
? ? $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'network.view' , 'request' )
? ? [];
}
2020-10-13 00:23:17 -04:00
}