Compare commits
3 commits
604f75f5c8
...
42168b132d
Author | SHA1 | Date | |
---|---|---|---|
42168b132d | |||
4f9cc89cb8 | |||
3d9f5fc6b1 |
4 changed files with 37 additions and 7 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue