Added EncryptionGetChannel
This commit is contained in:
parent
5a87d5ccd1
commit
0643f3edfd
1 changed files with 55 additions and 0 deletions
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Classes\Validator;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\EncryptionChannelManager;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
|
||||
class EncryptionGetChannel extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
if(!$rpcRequest->containsParameter('channel_uuid'))
|
||||
{
|
||||
throw new MissingRpcArgumentException('channel_uuid');
|
||||
}
|
||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
||||
{
|
||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$requestingPeer = $request->getPeer();
|
||||
$encryptionChannel = EncryptionChannelManager::getChannel($rpcRequest->getParameter('channel_uuid'));
|
||||
}
|
||||
catch(DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardRpcException('There was an error while trying to obtain the encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
if($encryptionChannel === null)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::NOT_FOUND, 'The requested encryption channel was not found');
|
||||
}
|
||||
elseif(!$encryptionChannel->isParticipant($requestingPeer->getAddress()))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The requested encryption channel is not accessible');
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse($encryptionChannel->toStandard());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue