2025-01-24 19:12:03 -05:00
|
|
|
<?php
|
|
|
|
|
2025-01-29 15:52:38 -05:00
|
|
|
namespace Socialbox\Classes\StandardMethods\AddressBook;
|
2025-01-24 19:12:03 -05:00
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use Socialbox\Abstracts\Method;
|
|
|
|
use Socialbox\Enums\StandardError;
|
|
|
|
use Socialbox\Exceptions\DatabaseOperationException;
|
2025-01-30 12:30:20 -05:00
|
|
|
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
|
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
2025-01-30 00:37:37 -05:00
|
|
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
2025-01-24 19:12:03 -05:00
|
|
|
use Socialbox\Interfaces\SerializableInterface;
|
|
|
|
use Socialbox\Managers\ContactManager;
|
|
|
|
use Socialbox\Objects\ClientRequest;
|
|
|
|
use Socialbox\Objects\PeerAddress;
|
|
|
|
use Socialbox\Objects\RpcRequest;
|
|
|
|
|
|
|
|
class AddressBookGetContact extends Method
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
|
|
|
{
|
|
|
|
if(!$rpcRequest->containsParameter('peer'))
|
|
|
|
{
|
2025-01-30 12:30:20 -05:00
|
|
|
throw new MissingRpcArgumentException('peer');
|
2025-01-24 19:12:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
|
|
}
|
|
|
|
catch(InvalidArgumentException $e)
|
|
|
|
{
|
2025-01-30 12:30:20 -05:00
|
|
|
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
2025-01-24 19:12:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(!ContactManager::isContact($request->getPeer(), $address))
|
|
|
|
{
|
2025-01-30 19:55:10 -05:00
|
|
|
// Return empty response if the contact does not exist
|
|
|
|
return $rpcRequest->produceResponse();
|
2025-01-24 19:12:03 -05:00
|
|
|
}
|
|
|
|
|
2025-01-30 19:51:37 -05:00
|
|
|
$rpcRequest->produceResponse(ContactManager::getStandardContact($request->getPeer(), $address));
|
2025-01-24 19:12:03 -05:00
|
|
|
}
|
|
|
|
catch(DatabaseOperationException $e)
|
|
|
|
{
|
2025-01-30 00:37:37 -05:00
|
|
|
throw new StandardRpcException('Failed to get contact', StandardError::INTERNAL_SERVER_ERROR, $e);
|
2025-01-24 19:12:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|