Added Standard Objects for the encryption channel
This commit is contained in:
parent
0e08bef3bc
commit
d929a9ec4c
4 changed files with 405 additions and 7 deletions
|
@ -2,8 +2,12 @@
|
|||
|
||||
namespace Socialbox\Objects\Database;
|
||||
|
||||
use DateMalformedStringException;
|
||||
use DateTime;
|
||||
use InvalidArgumentException;
|
||||
use Socialbox\Enums\Types\CommunicationRecipientType;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\Standard\EncryptionChannelMessage;
|
||||
|
||||
class ChannelMessageRecord implements SerializableInterface
|
||||
{
|
||||
|
@ -13,7 +17,7 @@
|
|||
private string $message;
|
||||
private string $signature;
|
||||
private bool $received;
|
||||
private \DateTime $timestamp;
|
||||
private DateTime $timestamp;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of this class and initializes its properties with the provided data.
|
||||
|
@ -26,7 +30,7 @@
|
|||
* - 'signature' (string): The signature.
|
||||
* - 'received' (bool): Whether the message has been received.
|
||||
* - 'timestamp' (int|string|\DateTime): The timestamp of the message.
|
||||
* @return void
|
||||
* @throws DateMalformedStringException If the timestamp is a string that cannot be parsed.
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
|
@ -37,21 +41,21 @@
|
|||
$this->signature = $data['signature'];
|
||||
$this->received = (bool)$data['received'];
|
||||
|
||||
if($data['timestamp'] instanceof \DateTime)
|
||||
if($data['timestamp'] instanceof DateTime)
|
||||
{
|
||||
$this->timestamp = $data['timestamp'];
|
||||
}
|
||||
elseif(is_int($data['timestamp']))
|
||||
{
|
||||
$this->timestamp = (new \DateTime())->setTimestamp($data['timestamp']);
|
||||
$this->timestamp = (new DateTime())->setTimestamp($data['timestamp']);
|
||||
}
|
||||
elseif(is_string($data['timestamp']))
|
||||
{
|
||||
$this->timestamp = new \DateTime($data['timestamp']);
|
||||
$this->timestamp = new DateTime($data['timestamp']);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \InvalidArgumentException('Invalid timestamp type, got ' . gettype($data['timestamp']));
|
||||
throw new InvalidArgumentException('Invalid timestamp type, got ' . gettype($data['timestamp']));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,12 +109,22 @@
|
|||
return $this->signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the message has been received.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReceived(): bool
|
||||
{
|
||||
return $this->received;
|
||||
}
|
||||
|
||||
public function getTimestamp(): \DateTime
|
||||
/**
|
||||
* Returns the timestamp of the message.
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getTimestamp(): DateTime
|
||||
{
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
@ -138,4 +152,10 @@
|
|||
'timestamp' => $this->timestamp->format('Y-m-d H:i:s')
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toStandard(): EncryptionChannelMessage
|
||||
{
|
||||
return new EncryptionChannelMessage($this->toArray());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue