diff --git a/src/Socialbox/Classes/StandardMethods/AddressBookUpdateRelationship.php b/src/Socialbox/Classes/StandardMethods/AddressBookUpdateRelationship.php new file mode 100644 index 0000000..cd913ec --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/AddressBookUpdateRelationship.php @@ -0,0 +1,68 @@ +containsParameter('peer')) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required peer parameter'); + } + + try + { + $address = PeerAddress::fromAddress($rpcRequest->getParameter('peer')); + } + catch(InvalidArgumentException $e) + { + throw new StandardException('Invalid peer address', StandardError::RPC_INVALID_ARGUMENTS, $e); + } + + if(!$rpcRequest->containsParameter('relationship')) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required relationship parameter'); + } + $relationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship'))); + if($relationship === null) + { + throw new StandardException('Invalid relationship type', StandardError::RPC_INVALID_ARGUMENTS); + } + + try + { + // Check if the contact already exists + $peer = $request->getPeer(); + if(!ContactManager::isContact($peer, $address)) + { + return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist'); + } + + // Create the contact + ContactManager::updateContactRelationship($peer, $address, $relationship); + } + catch (DatabaseOperationException $e) + { + throw new StandardException('Failed to update contact relationship', StandardError::INTERNAL_SERVER_ERROR, $e); + } + + // Return success + return $rpcRequest->produceResponse(true); + } + } \ No newline at end of file