From 0643f3edfde45164a7994f9c890a136c47ea0314 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 3 Mar 2025 15:04:11 -0500 Subject: [PATCH] Added EncryptionGetChannel --- .../EncryptionGetChannel.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetChannel.php diff --git a/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetChannel.php b/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetChannel.php new file mode 100644 index 0000000..ccae0eb --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/EncryptionChannel/EncryptionGetChannel.php @@ -0,0 +1,55 @@ +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'); + } + + try + { + $requestingPeer = $request->getPeer(); + $encryptionChannel = EncryptionChannelManager::getChannel($rpcRequest->getParameter('channel_uuid')); + } + catch(DatabaseOperationException $e) + { + throw new StandardRpcException('There was an error while trying to obtain the encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e); + } + + if($encryptionChannel === null) + { + return $rpcRequest->produceError(StandardError::NOT_FOUND, 'The requested encryption channel was not found'); + } + elseif(!$encryptionChannel->isParticipant($requestingPeer->getAddress())) + { + return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The requested encryption channel is not accessible'); + } + + return $rpcRequest->produceResponse($encryptionChannel->toStandard()); + } + } \ No newline at end of file