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,33 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Application;
|
||||
use IPS\core\api\GraphQL\Types\NotificationType;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Notification\Api;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark notification read mutation for GraphQL API
|
||||
*/
|
||||
class _MarkNotificationRead
|
||||
class MarkNotificationRead
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a notification as read";
|
||||
public static string $description = "Mark a notification as read";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -43,7 +51,7 @@ class _MarkNotificationRead
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : NotificationType
|
||||
{
|
||||
return \IPS\core\Api\GraphQL\TypeRegistry::notification();
|
||||
}
|
||||
@@ -51,45 +59,44 @@ class _MarkNotificationRead
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return array|NULL
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : ?array
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
$where = array();
|
||||
$where[] = array( "notification_app IN('" . implode( "','", array_keys( \IPS\Application::enabledApplications() ) ) . "')" );
|
||||
$where[] = array( "member = ?", \IPS\Member::loggedIn()->member_id );
|
||||
$where[] = array( "notification_app IN('" . implode( "','", array_keys( Application::enabledApplications() ) ) . "')" );
|
||||
$where[] = array( "member = ?", Member::loggedIn()->member_id );
|
||||
|
||||
if( isset( $args['id'] ) && $args['id'] !== NULL )
|
||||
if( isset( $args['id'] ) )
|
||||
{
|
||||
$where[] = array( "id = ?", \intval( $args['id'] ) );
|
||||
$where[] = array( "id = ?", intval( $args['id'] ) );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$row = \IPS\Db::i()->select( '*', 'core_notifications', $where )->first();
|
||||
$notification = \IPS\Notification\Api::constructFromData( $row );
|
||||
$row = Db::i()->select( '*', 'core_notifications', $where )->first();
|
||||
$notification = Api::constructFromData( $row );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
if( isset( $args['id'] ) && $args['id'] !== NULL )
|
||||
if( isset( $args['id'] ) )
|
||||
{
|
||||
// Only throw an error if we were trying to work on a specific notification
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_NOTIFICATION', 'GQL/0003/2', 403 );
|
||||
throw new SafeException( 'INVALID_NOTIFICATION', 'GQL/0003/2', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_notifications', array( 'read_time' => time() ), $where );
|
||||
\IPS\Member::loggedIn()->recountNotifications();
|
||||
Db::i()->update( 'core_notifications', array( 'read_time' => time() ), $where );
|
||||
Member::loggedIn()->recountNotifications();
|
||||
|
||||
if( $notification )
|
||||
if( isset( $notification ) )
|
||||
{
|
||||
return array( 'notification' => $notification, 'data' => $notification->getData() );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user