diff --git a/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetChannels.php b/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetChannels.php new file mode 100644 index 0000000..93c6d9e --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetChannels.php @@ -0,0 +1,60 @@ +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'); + } + + $page = 1; + $limit = Configuration::getPoliciesConfiguration()->getEncryptionChannelsLimit(); + if($rpcRequest->containsParameter('page')) + { + $page = (int)$rpcRequest->getParameter('page'); + } + + if($rpcRequest->containsParameter('limit')) + { + $limit = (int)$rpcRequest->getParameter('limit'); + } + + try + { + $requestingPeer = $request->getPeer(); + return $rpcRequest->produceResponse(array_map(function($channel) use ($requestingPeer) + { + return $channel->toStandard(); + }, EncryptionChannelManager::getChannels($requestingPeer->getAddress(), $page, $limit))); + } + catch(DatabaseOperationException $e) + { + throw new StandardRpcException('There was an error while trying to obtain the encryption channels', StandardError::INTERNAL_SERVER_ERROR, $e); + } + } + } \ No newline at end of file