Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -10,25 +10,33 @@
*/
namespace IPS\core\api\GraphQL\Mutations\Messenger;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\Application;
use IPS\Application\Module;
use IPS\core\api\GraphQL\Types\MessengerConversationType;
use IPS\core\Messenger\Conversation;
use IPS\Member;
use IPS\Notification;
use OutOfRangeException;
use function defined;
/* 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;
}
/**
* Add user to conversation mutation for GraphQL API
*/
class _AddConversationUser
class AddConversationUser
{
/*
* @brief Query description
*/
public static $description = "Add a user to a PM conversation";
public static string $description = "Add a user to a PM conversation";
/*
* Mutation arguments
@@ -44,7 +52,7 @@ class _AddConversationUser
/**
* Return the mutation return type
*/
public function type()
public function type() : MessengerConversationType
{
return \IPS\core\Api\GraphQL\TypeRegistry::messengerConversation();
}
@@ -52,38 +60,37 @@ class _AddConversationUser
/**
* Resolves this mutation
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\forums\Forum
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @return Conversation
*/
public function resolve($val, $args)
public function resolve( mixed $val, array $args ) : Conversation
{
if( !\IPS\Member::loggedIn()->member_id )
if( !Member::loggedIn()->member_id )
{
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
}
try
{
$conversation = \IPS\core\Messenger\Conversation::loadAndCheckPerms( $args['id'] );
$conversation = Conversation::loadAndCheckPerms( $args['id'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_MESSAGE', '1F294/2_graphql', 400 );
throw new SafeException( 'NO_MESSAGE', '1F294/2_graphql', 400 );
}
// Fetch our new member
$member = \IPS\Member::load( $args['memberId'] );
$member = Member::load( $args['memberId'] );
if( !$member->member_id ){
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_MEMBER', '1F294/2_graphql', 403 );
throw new SafeException( 'INVALID_MEMBER', '1F294/2_graphql', 403 );
}
// Check member limit
if ( \IPS\Member::loggedIn()->group['g_max_mass_pm'] !== -1 AND $conversation->to_count + 1 > \IPS\Member::loggedIn()->group['g_max_mass_pm'] )
if ( Member::loggedIn()->group['g_max_mass_pm'] !== -1 AND $conversation->to_count + 1 > Member::loggedIn()->group['g_max_mass_pm'] )
{
throw new \IPS\Api\GraphQL\SafeException( 'TOO_MANY_RECIPIENTS', '1F294/2', 400 );
throw new SafeException( 'TOO_MANY_RECIPIENTS', '1F294/2', 400 );
}
$maps = $conversation->maps( TRUE );
@@ -91,12 +98,12 @@ class _AddConversationUser
// Authorize the member
if ( array_key_exists( $member->member_id, $maps ) and !$maps[ $member->member_id ]['map_user_active'] AND !$maps[ $member->member_id ]['map_user_banned'] )
{
throw new \IPS\Api\GraphQL\SafeException( 'MEMBER_LEFT', '1F294/2', 403 );
throw new SafeException( 'MEMBER_LEFT', '1F294/2', 403 );
}
if ( !$this->memberCanReceiveNewMessage( $member ) )
{
throw new \IPS\Api\GraphQL\SafeException( 'BAD_RECIPIENT', '1F294/2', 403 );
throw new SafeException( 'BAD_RECIPIENT', '1F294/2', 403 );
}
//echo 'here';
@@ -104,7 +111,7 @@ class _AddConversationUser
$conversation->authorize( $member );
$conversation->maps(TRUE); // Need to rebuild participant maps here to reflect this change
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, \IPS\Member::loggedIn() ) );
$notification = new Notification( Application::load('core'), 'private_message_added', $conversation, array( $conversation, Member::loggedIn() ) );
$notification->recipients->attach( $member );
$notification->send();
@@ -114,10 +121,10 @@ class _AddConversationUser
/**
* Can the member recieve new messages?
*
* @param \IPS\Member The member to check
* @return boolean
* @param Member $member The member to check
* @return bool
*/
public function memberCanReceiveNewMessage( $member )
public function memberCanReceiveNewMessage( Member $member ) : bool
{
if ( $member->members_disable_pm )
{
@@ -125,19 +132,19 @@ class _AddConversationUser
}
/* Group can not use messenger */
if ( !$member->canAccessModule( \IPS\Application\Module::get( 'core', 'messaging', 'front' ) ) )
if ( !$member->canAccessModule( Module::get( 'core', 'messaging', 'front' ) ) )
{
return FALSE;
}
/* Inbox is full */
if ( ( $member->group['g_max_messages'] > 0 AND $member->msg_count_total >= $member->group['g_max_messages'] ) and !\IPS\Member::loggedIn()->group['gbw_pm_override_inbox_full'] )
if ( ( $member->group['g_max_messages'] > 0 AND $member->msg_count_total >= $member->group['g_max_messages'] ) and !Member::loggedIn()->group['gbw_pm_override_inbox_full'] )
{
return FALSE;
}
/* Is being ignored */
if ( $member->isIgnoring( \IPS\Member::loggedIn(), 'messages' ) )
if ( $member->isIgnoring( Member::loggedIn(), 'messages' ) )
{
return FALSE;
}
@@ -10,25 +10,30 @@
*/
namespace IPS\core\api\GraphQL\Mutations\Messenger;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\core\api\GraphQL\Types\MessengerConversationType;
use IPS\core\Messenger\Conversation;
use IPS\Member;
use OutOfRangeException;
use function defined;
/* 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;
}
/**
* Leave conversation mutation for GraphQL API
*/
class _LeaveConversation
class LeaveConversation
{
/*
* @brief Query description
*/
public static $description = "Leave a PM conversation";
public static string $description = "Leave a PM conversation";
/*
* Mutation arguments
@@ -43,7 +48,7 @@ class _LeaveConversation
/**
* Return the mutation return type
*/
public function type()
public function type() : MessengerConversationType
{
return \IPS\core\Api\GraphQL\TypeRegistry::messengerConversation();
}
@@ -51,26 +56,25 @@ class _LeaveConversation
/**
* Resolves this mutation
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\forums\Forum
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @return mixed
*/
public function resolve($val, $args)
public function resolve( mixed $val, array $args ) : mixed
{
if( !\IPS\Member::loggedIn()->member_id )
if( !Member::loggedIn()->member_id )
{
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
}
try
{
$conversation = \IPS\core\Messenger\Conversation::loadAndCheckPerms( $args['id'] );
$conversation->deauthorize( \IPS\Member::loggedIn() );
$conversation = Conversation::loadAndCheckPerms( $args['id'] );
$conversation->deauthorize( Member::loggedIn() );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
throw new SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
}
return NULL;
@@ -10,25 +10,30 @@
*/
namespace IPS\core\api\GraphQL\Mutations\Messenger;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\core\api\GraphQL\Types\MessengerConversationType;
use IPS\core\Messenger\Conversation;
use IPS\Member;
use OutOfRangeException;
use function defined;
/* 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;
}
/**
* Remove user from conversation mutation for GraphQL API
*/
class _RemoveConversationUser
class RemoveConversationUser
{
/*
* @brief Query description
*/
public static $description = "Leave a PM conversation";
public static string $description = "Leave a PM conversation";
/*
* Mutation arguments
@@ -44,7 +49,7 @@ class _RemoveConversationUser
/**
* Return the mutation return type
*/
public function type()
public function type() : MessengerConversationType
{
return \IPS\core\Api\GraphQL\TypeRegistry::messengerConversation();
}
@@ -52,33 +57,32 @@ class _RemoveConversationUser
/**
* Resolves this mutation
*
* @param mixed Value passed into this resolver
* @param array Arguments
* @param array Context values
* @return \IPS\forums\Forum
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @return Conversation
*/
public function resolve($val, $args)
public function resolve( mixed $val, array $args ) : Conversation
{
if( !\IPS\Member::loggedIn()->member_id )
if( !Member::loggedIn()->member_id )
{
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
}
try
{
$conversation = \IPS\core\Messenger\Conversation::loadAndCheckPerms( $args['id'] );
$conversation = Conversation::loadAndCheckPerms( $args['id'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
throw new SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
}
if( $conversation->starter_id !== \IPS\Member::loggedIn()->member_id )
if( $conversation->starter_id !== Member::loggedIn()->member_id )
{
throw new \IPS\Api\GraphQL\SafeException( 'NOT_OWNER', 'GQL/0003/1', 403 );
throw new SafeException( 'NOT_OWNER', 'GQL/0003/1', 403 );
}
$conversation->deauthorize( \IPS\Member::load( $args['memberId'] ), TRUE );
$conversation->deauthorize( Member::load( $args['memberId'] ), TRUE );
$conversation->maps(TRUE); // Need to rebuild participant maps here to reflect this change
return $conversation;