Enable selfdestructing messages

This commit is contained in:
Deon George 2021-08-13 12:51:57 +10:00
parent 4533b1d0ed
commit d0b7038604
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254

View File

@ -22,6 +22,7 @@ class Message implements \JsonSerializable
private Model $o;
private Blocks $blocks;
private ?Carbon $selfdestruct = NULL;
/**
* Message constructor.
@ -127,6 +128,9 @@ class Message implements \JsonSerializable
*/
public function post(Carbon $delete=NULL): Generic
{
if (! $delete && $this->selfdestruct)
$delete = $this->selfdestruct;
if ($this->_data->has('ephemeral'))
abort('500','Cannot post ephemeral messages.');
@ -212,22 +216,22 @@ class Message implements \JsonSerializable
* Make the message self destruct
*
* @param Carbon $time
* @return Generic
* @throws \Exception
* @return Message
*/
public function selfdestruct(Carbon $time): Generic
public function selfdestruct(Carbon $time): self
{
$this->blocks->addContextElements(
collect()
->push(Blocks\Text::item(sprintf('This message will self destruct in %s...',$time->diffForHumans(Carbon::now(),['syntax' => CarbonInterface::DIFF_RELATIVE_TO_NOW])))));
$this->blocks->addContextElements(collect([
Blocks\Text::item(sprintf('This message will self destruct in %s...',$time->diffForHumans(Carbon::now(),['syntax' => CarbonInterface::DIFF_RELATIVE_TO_NOW])))
]));
return $this->post($time);
$this->selfdestruct = $time;
return $this;
}
/**
* Add an attachment to a message
*
* @param Attachment $attachments
* @param Attachments $attachments
* @return Message
*/
public function setAttachments(Attachments $attachments): self