2025-01-30 00:24:11 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Socialbox\Classes\StandardMethods\AddressBook;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use Socialbox\Abstracts\Method;
|
|
|
|
use Socialbox\Enums\StandardError;
|
|
|
|
use Socialbox\Exceptions\DatabaseOperationException;
|
2025-01-30 00:34:22 -05:00
|
|
|
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
|
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
2025-01-30 00:27:06 -05:00
|
|
|
use Socialbox\Exceptions\Standard\StandardException;
|
2025-01-30 00:24:11 -05:00
|
|
|
use Socialbox\Interfaces\SerializableInterface;
|
|
|
|
use Socialbox\Managers\ContactManager;
|
|
|
|
use Socialbox\Objects\ClientRequest;
|
|
|
|
use Socialbox\Objects\PeerAddress;
|
|
|
|
use Socialbox\Objects\RpcRequest;
|
|
|
|
|
|
|
|
class AddressBookContactExists extends Method
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns True if the contact exists in the address book, False otherwise.
|
|
|
|
*
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
|
|
|
{
|
|
|
|
if(!$rpcRequest->containsParameter('peer'))
|
|
|
|
{
|
2025-01-30 00:34:22 -05:00
|
|
|
throw new MissingRpcArgumentException('peer');
|
2025-01-30 00:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
|
|
}
|
|
|
|
catch(InvalidArgumentException $e)
|
|
|
|
{
|
2025-01-30 00:34:22 -05:00
|
|
|
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
2025-01-30 00:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$peer = $request->getPeer();
|
|
|
|
return $rpcRequest->produceResponse(ContactManager::isContact($peer, $address));
|
|
|
|
}
|
|
|
|
catch (DatabaseOperationException $e)
|
|
|
|
{
|
|
|
|
throw new StandardException('Failed to check if the contact exists', StandardError::INTERNAL_SERVER_ERROR, $e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|