Compare commits

..

No commits in common. "42168b132d439297d9d0546e83c480c01c1222a2" and "604f75f5c81ba62ffa5edc83c0ae3c3db03d0c05" have entirely different histories.

4 changed files with 7 additions and 37 deletions

View file

@ -65,11 +65,11 @@
// Check if the contact already exists // Check if the contact already exists
if(ContactManager::isContact($peer, $peerAddress)) if(ContactManager::isContact($peer, $peerAddress))
{ {
return $rpcRequest->produceResponse(false); return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact already exists');
} }
// Create the contact // Create the contact
ContactManager::createContact($peer, $peerAddress, $relationship); $contactUuid = ContactManager::createContact($peer, $peerAddress, $relationship);
} }
catch (DatabaseOperationException $e) catch (DatabaseOperationException $e)
{ {
@ -77,6 +77,6 @@
} }
// Return success // Return success
return $rpcRequest->produceResponse(true); return $rpcRequest->produceResponse($contactUuid);
} }
} }

View file

@ -101,7 +101,7 @@
} }
$uuid = UuidV4::v4()->toRfc4122(); $uuid = UuidV4::v4()->toRfc4122();
Logger::getLogger()->debug(sprintf('Creating new contact (%s) for %s with a relationship of %s as UUID %s', $contactAddress, $peerUuid, $relationship->value, $uuid)); Logger::getLogger()->debug(sprintf('Creating new contact (%s) for %s as UUID %s', $contactAddress, $peerUuid, $uuid));
try try
{ {

View file

@ -4,7 +4,6 @@
use InvalidArgumentException; use InvalidArgumentException;
use Socialbox\Enums\Flags\PeerFlags; use Socialbox\Enums\Flags\PeerFlags;
use Socialbox\Enums\Types\InformationFieldName;
use Socialbox\Interfaces\SerializableInterface; use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Objects\Database\PeerInformationFieldRecord; use Socialbox\Objects\Database\PeerInformationFieldRecord;
use Socialbox\Objects\PeerAddress; use Socialbox\Objects\PeerAddress;
@ -120,35 +119,6 @@
return $this->informationFields; return $this->informationFields;
} }
/**
* Retrieves the information field associated with the peer.
*
* @param InformationFieldName $name The name of the information field to retrieve.
* @return InformationField|null The information field associated with the peer.
*/
public function getInformationField(InformationFieldName $name): ?InformationField
{
foreach($this->informationFields as $field)
{
if($field->getName() == $name)
{
return $field;
}
}
return null;
}
/**
* Checks if the information field exists.
*
* @param InformationFieldName $name The name of the information field to check.
* @return bool True if the information field exists, false otherwise.
*/
public function informationFieldExists(InformationFieldName $name): bool
{
return $this->getInformationField($name) !== null;
}
/** /**
* Retrieves the flags associated with the entity. * Retrieves the flags associated with the entity.
* *

View file

@ -194,10 +194,10 @@
* *
* @param PeerAddress|string $peer The address of the peer to add as a contact * @param PeerAddress|string $peer The address of the peer to add as a contact
* @param string|ContactRelationshipType|null $relationship Optional. The relationship for the peer * @param string|ContactRelationshipType|null $relationship Optional. The relationship for the peer
* @return bool Returns the contact uuid if the contact was created, False if it already exists * @return string Returns the contact uuid if the contact was created, False if it already exists
* @throws RpcException Thrown if there was an error with the RPC request * @throws RpcException Thrown if there was an error with the RPC request
*/ */
public function addressBookAddContact(PeerAddress|string $peer, null|string|ContactRelationshipType $relationship=ContactRelationshipType::MUTUAL): bool public function addressBookAddContact(PeerAddress|string $peer, null|string|ContactRelationshipType $relationship=ContactRelationshipType::MUTUAL): string
{ {
if($peer instanceof PeerAddress) if($peer instanceof PeerAddress)
{ {
@ -212,7 +212,7 @@
return (bool)$this->sendRequest( return (bool)$this->sendRequest(
new RpcRequest(StandardMethods::ADDRESS_BOOK_ADD_CONTACT, parameters: [ new RpcRequest(StandardMethods::ADDRESS_BOOK_ADD_CONTACT, parameters: [
'peer' => $peer, 'peer' => $peer,
'relationship' => $relationship 'relationship' => $relationship?->value
]) ])
)->getResponse()->getResult(); )->getResponse()->getResult();
} }