Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -10,25 +10,35 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Search\Mysql\Query;
|
||||
use IPS\core\api\GraphQL\Types\MessengerConversationType;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use UnderflowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_null;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Messenger conversations query for GraphQL API
|
||||
*/
|
||||
class _MessengerConversations
|
||||
class MessengerConversations
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of messenger conversations";
|
||||
public static string $description = "Returns a list of messenger conversations";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -66,7 +76,7 @@ class _MessengerConversations
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => 'core_messengerConversations_orderBy',
|
||||
'description' => 'Fields on which conversations can be sorted',
|
||||
'values' => \IPS\core\api\GraphQL\Types\MessengerConversationType::getOrderByOptions()
|
||||
'values' => MessengerConversationType::getOrderByOptions()
|
||||
]),
|
||||
'defaultValue' => 'last_post_time'
|
||||
],
|
||||
@@ -83,8 +93,10 @@ class _MessengerConversations
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return ListOfType<MessengerConversationType>
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\core\api\GraphQL\TypeRegistry::messengerConversation() );
|
||||
}
|
||||
@@ -92,22 +104,23 @@ class _MessengerConversations
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\core\Messenger\Conversation
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return ActiveRecordIterator|array
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : ActiveRecordIterator|array
|
||||
{
|
||||
// Start to build the query to fetch messages
|
||||
$where = array( array( 'core_message_topic_user_map.map_user_id=? AND core_message_topic_user_map.map_user_active=1', \IPS\Member::loggedIn()->member_id ) );
|
||||
$where = array( array( 'core_message_topic_user_map.map_user_id=? AND core_message_topic_user_map.map_user_active=1', Member::loggedIn()->member_id ) );
|
||||
$orderBy = 'mt_' . $args['orderBy'];
|
||||
$offset = max( $args['offset'], 0 );
|
||||
$limit = min( $args['limit'], 50 );
|
||||
$iterator = NULL;
|
||||
|
||||
// Filters
|
||||
if( !\is_null( $args['filter'] ) )
|
||||
if( !is_null( $args['filter'] ) )
|
||||
{
|
||||
switch ($args['filter'] ) {
|
||||
case "MINE":
|
||||
@@ -126,7 +139,7 @@ class _MessengerConversations
|
||||
}
|
||||
|
||||
// Folder
|
||||
if ( !\is_null( $args['folder'] ) )
|
||||
if ( !is_null( $args['folder'] ) )
|
||||
{
|
||||
$folderObj = \IPS\core\api\GraphQL\TypeRegistry::messengerFolder();
|
||||
$folders = $folderObj->getMemberFolders();
|
||||
@@ -138,33 +151,33 @@ class _MessengerConversations
|
||||
}
|
||||
|
||||
// Search
|
||||
if( !\is_null( $args['search'] ) )
|
||||
if( !is_null( $args['search'] ) )
|
||||
{
|
||||
$subQuery = \IPS\Db::i()->select( 'map_topic_id', array( 'core_message_topic_user_map', 'core_message_topic_user_map' ), $where );
|
||||
$subQuery = Db::i()->select( 'map_topic_id', array( 'core_message_topic_user_map', 'core_message_topic_user_map' ), $where );
|
||||
$where = array( array( 'core_message_posts.msg_topic_id IN (?)', $subQuery ) );
|
||||
$query = array();
|
||||
$prefix = \IPS\Db::i()->prefix;
|
||||
$prefix = Db::i()->prefix;
|
||||
|
||||
if ( !\is_null( $args['searchIn'] ) )
|
||||
if ( !is_null( $args['searchIn'] ) )
|
||||
{
|
||||
if ( \in_array( 'TOPIC', $args['searchIn'] ) )
|
||||
if ( in_array( 'TOPIC', $args['searchIn'] ) )
|
||||
{
|
||||
$query[] = \IPS\Content\Search\Mysql\Query::matchClause( "core_message_topics.mt_title", $args['search'], '+', FALSE );
|
||||
$query[] = Query::matchClause( "core_message_topics.mt_title", $args['search'], '+', FALSE );
|
||||
}
|
||||
if ( \in_array( 'POST', $args['searchIn'] ) )
|
||||
if ( in_array( 'POST', $args['searchIn'] ) )
|
||||
{
|
||||
$query[] = \IPS\Content\Search\Mysql\Query::matchClause( "core_message_posts.msg_post", $args['search'], '+', FALSE );
|
||||
$query[] = Query::matchClause( "core_message_posts.msg_post", $args['search'], '+', FALSE );
|
||||
}
|
||||
if ( \in_array( 'RECIPIENT', $args['searchIn'] ) )
|
||||
if ( in_array( 'RECIPIENT', $args['searchIn'] ) )
|
||||
{
|
||||
$query[] = "core_message_posts.msg_topic_id IN ( SELECT sender_map.map_topic_id FROM {$prefix}core_message_topic_user_map AS sender_map WHERE sender_map.map_is_starter=1 AND sender_map.map_user_id IN ( SELECT member_id FROM {$prefix}core_members AS sm WHERE name LIKE '" . \IPS\Db::i()->escape_string( $args['search'] ) . "%' ) )";
|
||||
$query[] = "core_message_posts.msg_topic_id IN ( SELECT sender_map.map_topic_id FROM {$prefix}core_message_topic_user_map AS sender_map WHERE sender_map.map_is_starter=1 AND sender_map.map_user_id IN ( SELECT member_id FROM {$prefix}core_members AS sm WHERE name LIKE '" . Db::i()->escape_string( $args['search'] ) . "%' ) )";
|
||||
}
|
||||
if ( \in_array( 'SENDER', $args['searchIn'] ) )
|
||||
if ( in_array( 'SENDER', $args['searchIn'] ) )
|
||||
{
|
||||
$query[] = "core_message_posts.msg_topic_id IN ( SELECT receiver_map.map_topic_id FROM {$prefix}core_message_topic_user_map AS receiver_map WHERE receiver_map.map_is_starter=0 AND receiver_map.map_user_id IN ( SELECT member_id FROM {$prefix}core_members AS rm WHERE name LIKE '" . \IPS\Db::i()->escape_string( $args['search'] ) . "%') )";
|
||||
$query[] = "core_message_posts.msg_topic_id IN ( SELECT receiver_map.map_topic_id FROM {$prefix}core_message_topic_user_map AS receiver_map WHERE receiver_map.map_is_starter=0 AND receiver_map.map_user_id IN ( SELECT member_id FROM {$prefix}core_members AS rm WHERE name LIKE '" . Db::i()->escape_string( $args['search'] ) . "%') )";
|
||||
}
|
||||
|
||||
if ( \count( $query ) )
|
||||
if ( count( $query ) )
|
||||
{
|
||||
$where[] = array( '(' . implode( ' OR ', $query ) . ')' );
|
||||
}
|
||||
@@ -173,7 +186,7 @@ class _MessengerConversations
|
||||
/* Get a count */
|
||||
try
|
||||
{
|
||||
$count = \IPS\Db::i()->select( 'COUNT(*)', 'core_message_posts', $where, NULL, NULL, 'msg_topic_id' )
|
||||
$count = Db::i()->select( 'COUNT(*)', 'core_message_posts', $where, NULL, NULL, 'msg_topic_id' )
|
||||
->join(
|
||||
'core_message_topics',
|
||||
'core_message_posts.msg_topic_id=core_message_topics.mt_id'
|
||||
@@ -184,7 +197,7 @@ class _MessengerConversations
|
||||
)
|
||||
->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
$count = 0;
|
||||
}
|
||||
@@ -193,7 +206,7 @@ class _MessengerConversations
|
||||
if( $count )
|
||||
{
|
||||
/* Because of strict group by, we first need to select the ids, then grab those topics */
|
||||
$iterator = \IPS\Db::i()->select(
|
||||
$iterator = Db::i()->select(
|
||||
'core_message_posts.msg_topic_id',
|
||||
'core_message_posts',
|
||||
$where,
|
||||
@@ -209,7 +222,7 @@ class _MessengerConversations
|
||||
);
|
||||
|
||||
/* Get iterator */
|
||||
$iterator = \IPS\Db::i()->select(
|
||||
$iterator = Db::i()->select(
|
||||
'core_message_topic_user_map.*, core_message_topics.*',
|
||||
'core_message_topic_user_map',
|
||||
array( 'map_topic_id IN(' . implode( ',', iterator_to_array( $iterator ) ) . ')' ),
|
||||
@@ -223,7 +236,7 @@ class _MessengerConversations
|
||||
else
|
||||
{
|
||||
/* Get iterator */
|
||||
$iterator = \IPS\Db::i()->select(
|
||||
$iterator = Db::i()->select(
|
||||
'core_message_topic_user_map.*, core_message_topics.*',
|
||||
'core_message_topic_user_map',
|
||||
$where,
|
||||
@@ -237,7 +250,7 @@ class _MessengerConversations
|
||||
|
||||
if( $iterator )
|
||||
{
|
||||
return new \IPS\Patterns\ActiveRecordIterator( $iterator, 'IPS\core\Messenger\Conversation' );
|
||||
return new ActiveRecordIterator( $iterator, 'IPS\core\Messenger\Conversation' );
|
||||
}
|
||||
|
||||
return array();
|
||||
|
||||
Reference in new issue
Block a user