Added MaybeInaccessibleMessage
This commit is contained in:
parent
054f76d144
commit
dfe522d965
1 changed files with 45 additions and 0 deletions
45
src/TgBotLib/Objects/Telegram/MaybeInaccessibleMessage.php
Normal file
45
src/TgBotLib/Objects/Telegram/MaybeInaccessibleMessage.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects\Telegram;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
|
||||
abstract class MaybeInaccessibleMessage implements ObjectTypeInterface
|
||||
{
|
||||
protected int $date;
|
||||
|
||||
/**
|
||||
* Always 0. The field can be used to differentiate regular and inaccessible messages.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDate(): int
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public abstract function toArray(): array;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): MaybeInaccessibleMessage
|
||||
{
|
||||
if(!isset($data['date']))
|
||||
{
|
||||
throw new InvalidArgumentException('Expected date in message');
|
||||
}
|
||||
|
||||
if((int)$data['date'] === 0)
|
||||
{
|
||||
return InaccessibleMessage::fromArray($data);
|
||||
}
|
||||
|
||||
return Message::fromArray($data);
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue