diff --git a/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookGetContacts.php b/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookGetContacts.php index 483bfc2..f142c79 100644 --- a/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookGetContacts.php +++ b/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookGetContacts.php @@ -6,7 +6,6 @@ use Socialbox\Classes\Configuration; use Socialbox\Enums\StandardError; use Socialbox\Exceptions\DatabaseOperationException; - use Socialbox\Exceptions\Standard\InvalidRpcArgumentException; use Socialbox\Exceptions\Standard\StandardRpcException; use Socialbox\Interfaces\SerializableInterface; use Socialbox\Managers\ContactManager; @@ -23,32 +22,20 @@ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { $limit = Configuration::getPoliciesConfiguration()->getGetContactsLimit(); - if($rpcRequest->containsParameter('limit', true)) + if($rpcRequest->containsParameter('limit')) { $limit = (int)$rpcRequest->getParameter('limit'); - if($limit <= 0) - { - throw new InvalidRpcArgumentException('limit', 'Invalid limit, must be greater than 0'); - } - - $limit = min($limit, Configuration::getPoliciesConfiguration()->getGetContactsLimit()); } $page = 0; - if($rpcRequest->containsParameter('page', true)) + if($rpcRequest->containsParameter('page')) { $page = (int)$rpcRequest->getParameter('page'); - if($page < 0) - { - throw new InvalidRpcArgumentException('page', 'Invalid page, must be greater than or equal to 0'); - } - - $page = max($page, 0); } try { - return $rpcRequest->produceResponse(ContactManager::getStandardContacts($request->getPeer(), $limit, $page)); + return $rpcRequest->produceResponse(ContactManager::getStandardContacts($request->getPeer()->getUuid(), $limit, $page)); } catch(DatabaseOperationException $e) { diff --git a/src/Socialbox/Managers/ContactManager.php b/src/Socialbox/Managers/ContactManager.php index 197fe43..281f8a4 100644 --- a/src/Socialbox/Managers/ContactManager.php +++ b/src/Socialbox/Managers/ContactManager.php @@ -7,6 +7,7 @@ use ncc\ThirdParty\Symfony\Uid\UuidV4; use PDO; use PDOException; + use Socialbox\Classes\Configuration; use Socialbox\Classes\Cryptography; use Socialbox\Classes\Database; use Socialbox\Classes\Validator; @@ -317,12 +318,16 @@ { if ($page < 1) { - $page = 1; + throw new InvalidArgumentException('The page number cannot be less than 1'); } if ($limit < 1) { - $limit = 1; + throw new InvalidArgumentException('The limit cannot be less than 1'); + } + elseif($limit > Configuration::getPoliciesConfiguration()->getGetContactsLimit()) + { + throw new InvalidArgumentException('The limit cannot exceed a value of ' . Configuration::getPoliciesConfiguration()->getGetContactsLimit()); } $contacts = [];