2023-09-05 17:10:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
2023-10-09 11:59:26 +00:00
|
|
|
use ResqueScheduler;
|
|
|
|
|
use Utopia\Database\DateTime;
|
2023-09-05 17:10:48 +00:00
|
|
|
|
|
|
|
|
class Messaging extends Event
|
|
|
|
|
{
|
2023-09-27 13:28:00 +00:00
|
|
|
protected ?string $messageId = null;
|
2023-10-09 11:59:26 +00:00
|
|
|
private ?string $deliveryTime = null;
|
2023-09-05 17:10:48 +00:00
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct(Event::MESSAGING_QUEUE_NAME, Event::MESSAGING_CLASS_NAME);
|
|
|
|
|
}
|
2023-09-05 17:40:33 +00:00
|
|
|
|
2023-09-05 17:10:48 +00:00
|
|
|
/**
|
2023-09-27 13:28:00 +00:00
|
|
|
* Sets message ID for the messaging event.
|
2023-09-05 17:10:48 +00:00
|
|
|
*
|
2023-09-27 13:28:00 +00:00
|
|
|
* @param string $message
|
2023-09-05 17:10:48 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2023-09-27 13:28:00 +00:00
|
|
|
public function setMessageId(string $messageId): self
|
2023-09-05 17:10:48 +00:00
|
|
|
{
|
2023-09-27 13:28:00 +00:00
|
|
|
$this->messageId = $messageId;
|
2023-09-05 17:10:48 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-27 13:28:00 +00:00
|
|
|
* Returns set message ID for the messaging event.
|
2023-09-05 17:10:48 +00:00
|
|
|
*
|
2023-09-27 13:28:00 +00:00
|
|
|
* @return string
|
2023-09-05 17:10:48 +00:00
|
|
|
*/
|
2023-09-27 13:28:00 +00:00
|
|
|
public function getMessageId(): string
|
2023-09-05 17:10:48 +00:00
|
|
|
{
|
2023-09-27 13:28:00 +00:00
|
|
|
return $this->messageId;
|
2023-09-05 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-09 11:59:26 +00:00
|
|
|
* Sets Delivery time for the messaging event.
|
2023-09-05 17:10:48 +00:00
|
|
|
*
|
2023-10-09 11:59:26 +00:00
|
|
|
* @param string $deliveryTime
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setDeliveryTime(string $deliveryTime): self
|
|
|
|
|
{
|
|
|
|
|
$this->deliveryTime = $deliveryTime;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns set Delivery Time for the messaging event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDeliveryTime(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->deliveryTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Executes the event and sends it to the messaging worker.
|
2023-09-05 17:10:48 +00:00
|
|
|
*/
|
2023-10-09 11:59:26 +00:00
|
|
|
public function trigger(): string | bool
|
2023-09-05 17:10:48 +00:00
|
|
|
{
|
2023-10-09 11:59:26 +00:00
|
|
|
ResqueScheduler::enqueueAt(!empty($this->deliveryTime) ? $this->deliveryTime : DateTime::now(), $this->queue, $this->class, [
|
2023-09-05 17:10:48 +00:00
|
|
|
'project' => $this->project,
|
|
|
|
|
'user' => $this->user,
|
2023-09-27 13:28:00 +00:00
|
|
|
'messageId' => $this->messageId,
|
2023-09-05 17:10:48 +00:00
|
|
|
]);
|
2023-10-09 11:59:26 +00:00
|
|
|
return true;
|
2023-09-05 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
}
|