From 824eed83f2efd4a1c1832cbbc2f77a3c86f2079b Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 6 Mar 2025 15:19:57 -0500 Subject: [PATCH] Add EncryptionGetOutgoingChannels class to retrieve outgoing encryption channels with pagination support --- .../EncryptionGetOutgoingChannels.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetOutgoingChannels.php diff --git a/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetOutgoingChannels.php b/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetOutgoingChannels.php new file mode 100644 index 0000000..b31c332 --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetOutgoingChannels.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()->getEncryptionChannelOutgoingLimit(); + 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::getOutgoingChannels($requestingPeer->getAddress(), $page, $limit))); + } + catch(DatabaseOperationException $e) + { + throw new StandardRpcException('There was an error while trying to obtain outgoing encryption channels', StandardError::INTERNAL_SERVER_ERROR, $e); + } + } + } \ No newline at end of file