2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2021 Ad Aures
|
2021-04-02 17:20:02 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-08-23 11:05:16 +00:00
|
|
|
namespace Modules\Fediverse\Entities;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
use Michalsn\Uuid\UuidEntity;
|
2021-05-19 16:35:13 +00:00
|
|
|
use RuntimeException;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property string $id
|
|
|
|
* @property int $actor_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Actor $actor
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property int|null $target_actor_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Actor $target_actor
|
2021-08-13 11:07:29 +00:00
|
|
|
* @property string|null $post_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Post $post
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $type
|
|
|
|
* @property object $payload
|
2021-12-14 16:41:10 +00:00
|
|
|
* @property string|null $status
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property Time|null $scheduled_at
|
|
|
|
* @property Time $created_at
|
|
|
|
*/
|
2021-04-02 17:20:02 +00:00
|
|
|
class Activity extends UuidEntity
|
|
|
|
{
|
2021-06-08 09:52:11 +00:00
|
|
|
protected ?Actor $actor = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
protected ?Actor $target_actor = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
protected ?Post $post = null;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2021-08-13 11:07:29 +00:00
|
|
|
protected $uuids = ['id', 'post_id'];
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
2024-04-28 16:39:01 +00:00
|
|
|
* @var list<string>
|
2021-05-06 14:00:48 +00:00
|
|
|
*/
|
2021-04-02 17:20:02 +00:00
|
|
|
protected $dates = ['scheduled_at', 'created_at'];
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
2021-04-02 17:20:02 +00:00
|
|
|
protected $casts = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => 'string',
|
|
|
|
'actor_id' => 'integer',
|
2021-04-02 17:20:02 +00:00
|
|
|
'target_actor_id' => '?integer',
|
2023-06-12 14:47:38 +00:00
|
|
|
'post_id' => '?string',
|
|
|
|
'type' => 'string',
|
|
|
|
'payload' => 'json',
|
|
|
|
'status' => '?string',
|
2021-04-02 17:20:02 +00:00
|
|
|
];
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getActor(): Actor
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->actor_id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Activity must have an actor_id before getting the actor.');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $this->actor instanceof Actor) {
|
2021-06-09 12:40:22 +00:00
|
|
|
$this->actor = model('ActorModel', false)
|
2021-05-19 16:35:13 +00:00
|
|
|
->getActorById($this->actor_id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->actor;
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getTargetActor(): Actor
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->target_actor_id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Activity must have a target_actor_id before getting the target actor.');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $this->target_actor instanceof Actor) {
|
2021-06-09 12:40:22 +00:00
|
|
|
$this->target_actor = model('ActorModel', false)
|
2021-06-08 09:52:11 +00:00
|
|
|
->getActorById($this->target_actor_id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->target_actor;
|
|
|
|
}
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
public function getPost(): Post
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($this->post_id === null) {
|
|
|
|
throw new RuntimeException('Activity must have a post_id before getting post.');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $this->post instanceof Post) {
|
2021-08-13 11:07:29 +00:00
|
|
|
$this->post = model('PostModel', false)
|
|
|
|
->getPostById($this->post_id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
return $this->post;
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
}
|