Refactor AddressBookUpdateRelationship and ContactManager to improve variable naming and add UUID validation

https://github.com/nosial/Socialbox-PHP/issues/37
This commit is contained in:
netkas 2025-03-11 15:20:56 -04:00
parent f01df7b4c4
commit 50c638b534
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
2 changed files with 28 additions and 7 deletions

View file

@ -30,7 +30,7 @@
try
{
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
$receivingPeerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
}
catch(InvalidArgumentException $e)
{
@ -41,8 +41,8 @@
{
throw new MissingRpcArgumentException('relationship');
}
$relationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship')));
if($relationship === null)
$newRelationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship')));
if($newRelationship === null)
{
throw new InvalidRpcArgumentException('relationship');
}
@ -50,14 +50,14 @@
try
{
// Check if the contact already exists
$peer = $request->getPeer();
if(!ContactManager::isContact($peer, $address))
$requestingPeer = $request->getPeer();
if(!ContactManager::isContact($requestingPeer->getUuid(), $receivingPeerAddress))
{
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist');
}
// Create the contact
ContactManager::updateContactRelationship($peer, $address, $relationship);
ContactManager::updateContactRelationship($requestingPeer->getUuid(), $receivingPeerAddress, $newRelationship);
}
catch (DatabaseOperationException $e)
{