Compare commits

...

3 commits

Author SHA1 Message Date
42168b132d
Update addressBookAddContact method to return boolean and adjust response handling
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
2025-03-25 14:22:46 -04:00
4f9cc89cb8
Add methods to retrieve and check existence of information fields in Peer 2025-03-25 14:20:20 -04:00
3d9f5fc6b1
Improve logging in ContactManager to include relationship details and adjust relationship parameter handling in SocialClient 2025-03-25 14:02:10 -04:00
4 changed files with 37 additions and 7 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->produceError(StandardError::FORBIDDEN, 'Contact already exists'); return $rpcRequest->produceResponse(false);
} }
// Create the contact // Create the contact
$contactUuid = ContactManager::createContact($peer, $peerAddress, $relationship); ContactManager::createContact($peer, $peerAddress, $relationship);
} }
catch (DatabaseOperationException $e) catch (DatabaseOperationException $e)
{ {
@ -77,6 +77,6 @@
} }
// Return success // Return success
return $rpcRequest->produceResponse($contactUuid); return $rpcRequest->produceResponse(true);
} }
} }

View file

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

View file

@ -4,6 +4,7 @@
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;
@ -119,6 +120,35 @@
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 string Returns the contact uuid if the contact was created, False if it already exists * @return bool 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): string public function addressBookAddContact(PeerAddress|string $peer, null|string|ContactRelationshipType $relationship=ContactRelationshipType::MUTUAL): bool
{ {
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?->value 'relationship' => $relationship
]) ])
)->getResponse()->getResult(); )->getResponse()->getResult();
} }