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-10-05 07:36:12 +02:00
use Friendica\Content\Conversation\Entity\Network as NetworkEntity ;
2023-09-09 11:14:36 +02:00
use Friendica\Content\Conversation\Factory\Timeline as TimelineFactory ;
2023-10-07 11:44:24 +02:00
use Friendica\Content\Conversation\Repository\UserDefinedChannel ;
2023-10-05 07:36:12 +02:00
use Friendica\Content\Conversation\Factory\Channel as ChannelFactory ;
2023-10-05 21:10:20 +02:00
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory ;
2023-10-05 07:36:12 +02:00
use Friendica\Content\Conversation\Factory\Community as CommunityFactory ;
use Friendica\Content\Conversation\Factory\Network as NetworkFactory ;
2023-09-09 11:14:36 +02:00
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\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 ;
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-09-09 16:24:24 +02:00
protected $circleId ;
2020-10-13 06:23:17 +02:00
/** @var int */
2023-09-09 16:24:24 +02:00
protected $groupContactId ;
2020-10-13 06:23:17 +02:00
/** @var string */
2023-09-09 16:24:24 +02:00
protected $network ;
2020-10-13 06:23:17 +02:00
/** @var string */
2023-09-09 16:24:24 +02:00
protected $dateFrom ;
2020-10-13 06:23:17 +02:00
/** @var string */
2023-09-09 16:24:24 +02:00
protected $dateTo ;
2020-10-13 06:23:17 +02:00
/** @var int */
2023-09-09 16:24:24 +02:00
protected $star ;
2020-10-13 06:23:17 +02:00
/** @var int */
2023-09-09 16:24:24 +02:00
protected $mention ;
2020-10-13 06:23:17 +02:00
/** @var string */
2023-09-09 16:24:24 +02:00
protected $order ;
2020-10-13 06:23:17 +02:00
2023-09-09 16:13:58 +02:00
/** @var App */
protected $app ;
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 ;
2023-10-05 07:36:12 +02:00
/** @var ChannelFactory */
2023-10-06 13:38:29 +02:00
protected $channel ;
2023-10-05 21:10:20 +02:00
/** @var UserDefinedChannelFactory */
protected $userDefinedChannel ;
2023-10-05 07:36:12 +02:00
/** @var CommunityFactory */
protected $community ;
/** @var NetworkFactory */
protected $networkFactory ;
2023-10-07 11:44:24 +02: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 11:14:36 +02:00
{
2023-09-19 11:05:28 +02:00
parent :: __construct ( $channel , $mode , $session , $database , $pConfig , $config , $cache , $l10n , $baseUrl , $args , $logger , $profiler , $response , $server , $parameters );
2023-09-09 11:14:36 +02:00
2023-10-05 21:10:20 +02:00
$this -> app = $app ;
$this -> timeline = $timeline ;
$this -> systemMessages = $systemMessages ;
$this -> conversation = $conversation ;
$this -> page = $page ;
2023-10-06 13:38:29 +02:00
$this -> channel = $channelFactory ;
2023-10-05 21:10:20 +02:00
$this -> community = $community ;
$this -> networkFactory = $network ;
$this -> userDefinedChannel = $userDefinedChannel ;
2023-09-09 11:14:36 +02:00
}
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
$arr = [ 'query' => $this -> args -> getQueryString ()];
2020-10-13 06:23:17 +02:00
Hook :: callAll ( 'network_content_init' , $arr );
$o = '' ;
2023-09-17 12:09:07 +02:00
$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 : '' );
2023-09-21 22:43:14 +02:00
$this -> page [ 'aside' ] .= Widget :: accountTypes ( $module , $this -> accountTypeString );
$this -> page [ 'aside' ] .= Widget :: channels ( $module , $this -> selectedTab , $this -> session -> getLocalUserId ());
2023-09-17 12:09:07 +02:00
$this -> page [ 'aside' ] .= Widget\SavedSearches :: getHTML ( $this -> args -> getQueryString ());
$this -> page [ 'aside' ] .= Widget :: fileAs ( 'filed' , '' );
if ( Feature :: isEnabled ( $this -> session -> getLocalUserId (), 'trending_tags' )) {
$this -> page [ 'aside' ] .= TrendingTags :: getHTML ( $this -> selectedTab );
}
2023-09-09 11:14:36 +02:00
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-11-28 16:21:20 +01:00
if ( ! $this -> raw ) {
2023-09-09 11:14:36 +02:00
$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-09-09 16:24:24 +02: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 16:31:12 +02:00
$contact = $this -> database -> selectFirst ( 'contact' , [ 'addr' ], $condition );
2020-10-13 06:23:17 +02:00
if ( ! empty ( $contact [ 'addr' ])) {
$content = '!' . $contact [ 'addr' ];
}
}
$default_permissions = [];
2023-09-09 16:24:24 +02:00
if ( $this -> circleId ) {
$default_permissions [ 'allow_gid' ] = [ $this -> circleId ];
2020-10-13 06:23:17 +02:00
}
$allowedCids = [];
2023-09-09 16:24:24 +02:00
if ( $this -> groupContactId ) {
$allowedCids [] = ( int ) $this -> groupContactId ;
} elseif ( $this -> network ) {
2020-10-13 06:23:17 +02:00
$condition = [
2023-09-09 11:14:36 +02:00
'uid' => $this -> session -> getLocalUserId (),
2023-09-09 16:24:24 +02:00
'network' => $this -> network ,
2020-10-13 06:23:17 +02:00
'self' => false ,
'blocked' => false ,
'pending' => false ,
'archive' => false ,
'rel' => [ Contact :: SHARING , Contact :: FRIEND ],
];
2023-09-09 16:31:12 +02:00
$contactStmt = $this -> database -> select ( 'contact' , [ 'id' ], $condition );
while ( $contact = $this -> database -> fetch ( $contactStmt )) {
2020-10-13 06:23:17 +02:00
$allowedCids [] = ( int ) $contact [ 'id' ];
}
2023-09-09 16:31:12 +02:00
$this -> database -> close ( $contactStmt );
2020-10-13 06:23:17 +02:00
}
if ( count ( $allowedCids )) {
$default_permissions [ 'allow_cid' ] = $allowedCids ;
}
$x = [
2023-09-09 16:24:24 +02:00
'lockstate' => $this -> circleId || $this -> groupContactId || $this -> network || ACL :: getLockstateForUserId ( $this -> session -> getLocalUserId ()) ? 'lock' : 'unlock' ,
2023-09-09 11:14:36 +02:00
'acl' => ACL :: getFullSelectorHTML ( $this -> page , $this -> session -> getLocalUserId (), true , $default_permissions ),
2023-09-09 16:24:24 +02:00
'bang' => (( $this -> circleId || $this -> groupContactId || $this -> 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-11-28 16:21:20 +01: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 06:23:17 +02:00
2023-11-28 16:21:20 +01:00
$o = Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'section_title.tpl' ), [
'$title' => $this -> l10n -> t ( 'Circle: %s' , $circle [ 'name' ])
2020-10-13 06:23:17 +02:00
]) . $o ;
2023-11-28 16:21:20 +01:00
} 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' => $this -> args -> get ( 0 ),
]) . $o ;
} else {
$this -> systemMessages -> addNotice ( $this -> l10n -> t ( 'Invalid contact.' ));
}
} 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 06:23:17 +02:00
}
}
2023-10-14 20:39:35 +02:00
try {
if ( $this -> channel -> isTimeline ( $this -> selectedTab ) || $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ())) {
$items = $this -> getChannelItems ();
} 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 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 (),
2023-09-09 16:24:24 +02:00
$items [ 0 ][ $this -> order ] ? ? null ,
$items [ count ( $items ) - 1 ][ $this -> order ] ? ? null ,
2023-09-09 14:48:51 +02:00
$this -> itemsPerPage
2020-10-13 06:23:17 +02:00
);
$o .= $pager -> renderMinimal ( count ( $items ));
}
return $o ;
}
2023-09-09 15:48:41 +02:00
protected function getOrder () : string
{
2023-09-09 16:24:24 +02:00
if ( $this -> order === 'received' ) {
2023-09-09 15:48:41 +02:00
return '`received`' ;
2023-09-09 16:24:24 +02:00
} elseif ( $this -> order === 'created' ) {
2023-09-09 15:48:41 +02:00
return '`created`' ;
} else {
return '`commented`' ;
}
}
2020-10-13 06:23:17 +02:00
/**
* 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-10-05 07:36:12 +02:00
$tabs = $this -> getTabArray ( $this -> networkFactory -> getTimelines ( $this -> args -> getCommand ()), 'network' );
2020-10-13 06:23:17 +02:00
2023-09-09 19:38:09 +02:00
$network_timelines = $this -> pConfig -> get ( $this -> session -> getLocalUserId (), 'system' , 'network_timelines' , []);
if ( ! empty ( $network_timelines )) {
2023-10-06 13:38:29 +02:00
$tabs = array_merge ( $tabs , $this -> getTabArray ( $this -> channel -> getTimelines ( $this -> session -> getLocalUserId ()), 'network' , 'channel' ));
2023-10-07 11:44:24 +02:00
$tabs = array_merge ( $tabs , $this -> getTabArray ( $this -> channelRepository -> selectByUid ( $this -> session -> getLocalUserId ()), 'network' , 'channel' ));
2023-10-05 07:36:12 +02:00
$tabs = array_merge ( $tabs , $this -> getTabArray ( $this -> community -> getTimelines ( true ), 'network' , 'channel' ));
2023-09-09 19:38:09 +02:00
}
2020-10-13 06:23:17 +02:00
$arr = [ 'tabs' => $tabs ];
Hook :: callAll ( 'network_tabs' , $arr );
2023-09-09 19:38:09 +02:00
if ( ! empty ( $network_timelines )) {
$tabs = [];
2023-09-16 06:21:59 +02:00
2023-09-19 11:23:27 +02:00
foreach ( $arr [ 'tabs' ] as $tab ) {
if ( in_array ( $tab [ 'code' ], $network_timelines )) {
$tabs [] = $tab ;
2023-09-09 19:38:09 +02:00
}
}
} else {
$tabs = $arr [ 'tabs' ];
}
2020-10-13 06:23:17 +02:00
$tpl = Renderer :: getMarkupTemplate ( 'common_tabs.tpl' );
2023-09-09 19:38:09 +02:00
return Renderer :: replaceMacros ( $tpl , [ '$tabs' => $tabs ]);
2020-10-13 06:23:17 +02:00
}
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-09-09 16:24:24 +02:00
$this -> circleId = ( int )( $this -> parameters [ 'circle_id' ] ? ? 0 );
2020-10-13 06:23:17 +02:00
2023-09-09 16:24:24 +02:00
$this -> groupContactId = ( int )( $this -> parameters [ 'contact_id' ] ? ? 0 );
2020-10-13 06:23:17 +02:00
2023-09-09 14:48:51 +02:00
if ( ! $this -> selectedTab ) {
2023-09-09 16:13:58 +02:00
$this -> selectedTab = self :: getTimelineOrderBySession ( $this -> session , $this -> pConfig );
2023-10-06 13:38:29 +02: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 11:14:36 +02:00
throw new HTTPException\BadRequestException ( $this -> l10n -> t ( 'Network feed not available.' ));
}
2023-10-06 13:38:29 +02:00
if (( $this -> network || $this -> circleId || $this -> groupContactId ) && ( $this -> channel -> isTimeline ( $this -> selectedTab ) || $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ()) || $this -> community -> isTimeline ( $this -> selectedTab ))) {
2023-10-05 07:36:12 +02:00
$this -> selectedTab = NetworkEntity :: RECEIVED ;
2023-09-17 13:01:04 +02:00
}
2023-09-09 11:14:36 +02:00
if ( ! empty ( $request [ 'star' ])) {
2023-10-05 07:36:12 +02:00
$this -> selectedTab = NetworkEntity :: STAR ;
2023-09-09 16:24:24 +02:00
$this -> star = true ;
2020-12-19 17:48:12 +01:00
} else {
2023-10-05 07:36:12 +02:00
$this -> star = $this -> selectedTab == NetworkEntity :: STAR ;
2020-10-13 06:23:17 +02:00
}
2023-09-09 11:14:36 +02:00
if ( ! empty ( $request [ 'mention' ])) {
2023-10-05 07:36:12 +02:00
$this -> selectedTab = NetworkEntity :: MENTION ;
2023-09-09 16:24:24 +02:00
$this -> mention = true ;
2020-12-19 17:48:12 +01:00
} else {
2023-10-05 07:36:12 +02:00
$this -> mention = $this -> selectedTab == NetworkEntity :: MENTION ;
2020-10-13 06:23:17 +02:00
}
2023-09-09 11:14:36 +02:00
if ( ! empty ( $request [ 'order' ])) {
2023-09-09 14:48:51 +02:00
$this -> selectedTab = $request [ 'order' ];
2023-09-09 16:24:24 +02:00
$this -> order = $request [ 'order' ];
$this -> star = false ;
$this -> mention = false ;
2023-10-05 07:36:12 +02:00
} elseif ( in_array ( $this -> selectedTab , [ NetworkEntity :: RECEIVED , NetworkEntity :: STAR ]) || $this -> community -> isTimeline ( $this -> selectedTab )) {
2023-09-09 16:24:24 +02:00
$this -> order = 'received' ;
2023-10-06 13:38:29 +02:00
} elseif (( $this -> selectedTab == NetworkEntity :: CREATED ) || $this -> channel -> isTimeline ( $this -> selectedTab ) || $this -> userDefinedChannel -> isTimeline ( $this -> selectedTab , $this -> session -> getLocalUserId ())) {
2023-09-09 16:24:24 +02:00
$this -> order = 'created' ;
2022-04-21 07:52:08 +02:00
} else {
2023-09-09 16:24:24 +02:00
$this -> order = 'commented' ;
2020-10-13 06:23:17 +02:00
}
2023-09-20 08:36:47 +02:00
$this -> selectedTab = $this -> selectedTab ? ? $this -> order ;
2023-09-17 19:44:33 +02:00
// Upon updates in the background and order by last comment we order by received date,
2023-09-16 06:21:59 +02:00
// since otherwise the feed will optically jump, when some already visible thread has been updated.
2023-10-05 07:36:12 +02:00
if ( $this -> update && ( $this -> selectedTab == NetworkEntity :: COMMENTED )) {
2023-09-16 06:21:59 +02:00
$this -> order = 'received' ;
2023-09-20 08:36:47 +02:00
$request [ 'last_received' ] = $request [ 'last_commented' ] ? ? null ;
$request [ 'first_received' ] = $request [ 'first_commented' ] ? ? null ;
2023-09-16 06:21:59 +02:00
}
2021-02-21 13:18:50 +01:00
// Prohibit combined usage of "star" and "mention"
2023-10-05 07:36:12 +02:00
if ( $this -> selectedTab == NetworkEntity :: STAR ) {
2023-09-09 16:24:24 +02:00
$this -> mention = false ;
2023-10-05 07:36:12 +02:00
} elseif ( $this -> selectedTab == NetworkEntity :: MENTION ) {
2023-09-09 16:24:24 +02:00
$this -> star = false ;
2021-02-21 13:18:50 +01:00
}
2023-09-09 14:48:51 +02:00
$this -> session -> set ( 'network-tab' , $this -> selectedTab );
$this -> pConfig -> set ( $this -> session -> getLocalUserId (), 'network.view' , 'selected_tab' , $this -> selectedTab );
2020-10-13 06:23:17 +02:00
2023-09-09 16:24:24 +02:00
$this -> network = $request [ 'nets' ] ? ? '' ;
2020-10-13 06:23:17 +02:00
2023-09-09 16:24:24 +02:00
$this -> dateFrom = $this -> parameters [ 'from' ] ? ? '' ;
$this -> dateTo = $this -> parameters [ 'to' ] ? ? '' ;
2020-10-13 06:23:17 +02:00
2023-09-09 16:24:24 +02:00
switch ( $this -> order ) {
2020-10-13 06:23:17 +02:00
case 'received' :
2023-09-09 15:02:20 +02:00
$this -> maxId = $request [ 'last_received' ] ? ? $this -> maxId ;
2023-09-16 06:21:59 +02:00
$this -> minId = $request [ 'first_received' ] ? ? $this -> minId ;
2020-10-13 06:23:17 +02:00
break ;
case 'created' :
2023-09-09 15:02:20 +02:00
$this -> maxId = $request [ 'last_created' ] ? ? $this -> maxId ;
2023-09-16 06:21:59 +02:00
$this -> minId = $request [ 'first_created' ] ? ? $this -> minId ;
2020-10-13 06:23:17 +02:00
break ;
case 'uriid' :
2023-09-09 15:02:20 +02:00
$this -> maxId = $request [ 'last_uriid' ] ? ? $this -> maxId ;
2023-09-16 06:21:59 +02:00
$this -> minId = $request [ 'first_uriid' ] ? ? $this -> minId ;
2020-10-13 06:23:17 +02:00
break ;
2020-10-24 15:11:44 +02:00
default :
2023-09-09 16:24:24 +02:00
$this -> order = 'commented' ;
2023-09-09 15:02:20 +02:00
$this -> maxId = $request [ 'last_commented' ] ? ? $this -> maxId ;
2023-09-16 06:21:59 +02:00
$this -> minId = $request [ 'first_commented' ] ? ? $this -> minId ;
2020-10-13 06:23:17 +02:00
}
}
2023-09-09 15:26:20 +02:00
protected function getItems ()
2020-10-13 06:23:17 +02:00
{
2023-09-09 15:26:20 +02:00
$conditionFields = [ 'uid' => $this -> session -> getLocalUserId ()];
2020-10-13 06:23:17 +02:00
$conditionStrings = [];
2023-09-09 14:48:51 +02:00
if ( ! is_null ( $this -> accountType )) {
$conditionFields [ 'contact-type' ] = $this -> accountType ;
2020-10-13 06:23:17 +02:00
}
2023-09-09 16:24:24 +02:00
if ( $this -> star ) {
2020-10-13 06:23:17 +02:00
$conditionFields [ 'starred' ] = true ;
}
2023-09-09 16:24:24 +02:00
if ( $this -> mention ) {
2020-10-13 06:23:17 +02:00
$conditionFields [ 'mention' ] = true ;
}
2023-09-09 16:24:24 +02:00
if ( $this -> network ) {
$conditionFields [ 'network' ] = $this -> network ;
2020-10-13 06:23:17 +02:00
}
2023-09-09 16:24:24 +02:00
if ( $this -> dateFrom ) {
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `received` <= ? " , DateTimeFormat :: convert ( $this -> dateFrom , 'UTC' , $this -> app -> getTimeZone ())]);
2020-10-13 06:23:17 +02:00
}
2023-09-09 16:24:24 +02:00
if ( $this -> dateTo ) {
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `received` >= ? " , DateTimeFormat :: convert ( $this -> dateTo , 'UTC' , $this -> app -> getTimeZone ())]);
2020-10-13 06:23:17 +02:00
}
2023-09-09 16:24:24 +02: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 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 16:24:24 +02:00
$this -> groupContactId , $this -> 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:48:51 +02:00
if ( ! empty ( $this -> itemUriId )) {
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ 'uri-id' => $this -> itemUriId ]);
2023-09-09 14:00:22 +02:00
} else {
2023-09-09 15:02:20 +02:00
if ( isset ( $this -> maxId )) {
2023-09-09 16:24:24 +02:00
switch ( $this -> order ) {
2023-09-09 14:00:22 +02:00
case 'received' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `received` < ? " , $this -> maxId ]);
2023-09-09 14:00:22 +02:00
break ;
case 'commented' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `commented` < ? " , $this -> maxId ]);
2023-09-09 14:00:22 +02:00
break ;
case 'created' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `created` < ? " , $this -> maxId ]);
2023-09-09 14:00:22 +02:00
break ;
case 'uriid' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `uri-id` < ? " , $this -> maxId ]);
2023-09-09 14:00:22 +02:00
break ;
}
2020-10-13 06:23:17 +02:00
}
2023-09-09 15:02:20 +02:00
if ( isset ( $this -> minId )) {
2023-09-09 16:24:24 +02:00
switch ( $this -> order ) {
2023-09-09 14:00:22 +02:00
case 'received' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `received` > ? " , $this -> minId ]);
2023-09-09 14:00:22 +02:00
break ;
case 'commented' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `commented` > ? " , $this -> minId ]);
2023-09-09 14:00:22 +02:00
break ;
case 'created' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `created` > ? " , $this -> minId ]);
2023-09-09 14:00:22 +02:00
break ;
case 'uriid' :
2023-09-09 15:02:20 +02:00
$conditionStrings = DBA :: mergeConditions ( $conditionStrings , [ " `uri-id` > ? " , $this -> minId ]);
2023-09-09 14:00:22 +02:00
break ;
}
2020-10-13 06:23:17 +02:00
}
}
2023-09-09 15:26:20 +02:00
$params = [ 'limit' => $this -> itemsPerPage ];
2023-09-09 15:02:20 +02:00
if ( isset ( $this -> minId ) && ! isset ( $this -> maxId )) {
2020-10-13 06:23:17 +02: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 16:24:24 +02:00
$params [ 'order' ] = [ $this -> order => false ];
2020-10-13 06:23:17 +02:00
} else {
2023-09-09 16:24:24 +02:00
$params [ 'order' ] = [ $this -> order => true ];
2020-10-13 06:23:17 +02:00
}
2023-09-09 16:31:12 +02:00
$items = $this -> database -> selectToArray ( 'network-thread-view' , [], DBA :: mergeConditions ( $conditionFields , $conditionStrings ), $params );
2020-10-13 06:23:17 +02:00
// min_id quirk, continued
2023-09-09 15:02:20 +02:00
if ( isset ( $this -> minId ) && ! isset ( $this -> maxId )) {
2020-10-13 06:23:17 +02:00
$items = array_reverse ( $items );
}
2023-09-09 16:31:12 +02:00
if ( $this -> database -> 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-09-09 16:24:24 +02:00
if ( ! $this -> circleId && ! $this -> groupContactId && ! $this -> star && ! $this -> mention ) {
2023-09-09 11:14:36 +02:00
$condition = [ 'unseen' => true , 'uid' => $this -> session -> getLocalUserId ()];
2023-09-09 16:13:58 +02:00
$this -> 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 ];
2023-09-09 16:13:58 +02:00
$this -> setItemsSeenByCondition ( $condition );
2020-10-13 06:23:17 +02:00
}
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
}