2022-08-12 16:02:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Ad Aures
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2022-09-08 11:50:23 +00:00
|
|
|
namespace Modules\Fediverse\Entities;
|
2022-08-12 16:02:56 +00:00
|
|
|
|
2024-04-28 16:39:01 +00:00
|
|
|
use CodeIgniter\I18n\Time;
|
2022-08-12 16:02:56 +00:00
|
|
|
use Michalsn\Uuid\UuidEntity;
|
|
|
|
use Modules\Fediverse\Models\ActorModel;
|
|
|
|
use Modules\Fediverse\Models\PostModel;
|
|
|
|
use RuntimeException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property int $id
|
|
|
|
* @property int $actor_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Actor $actor
|
2022-08-12 16:02:56 +00:00
|
|
|
* @property int $target_actor_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Actor $target_actor
|
2022-08-12 16:02:56 +00:00
|
|
|
* @property string|null $post_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Post $post
|
2022-08-12 16:02:56 +00:00
|
|
|
* @property string $activity_id
|
|
|
|
* @property Activity $activity
|
|
|
|
* @property 'like'|'follow'|'share'|'reply' $type
|
|
|
|
* @property Time|null $read_at
|
|
|
|
* @property Time $created_at
|
|
|
|
* @property Time $updated_at
|
|
|
|
*/
|
|
|
|
class Notification extends UuidEntity
|
|
|
|
{
|
|
|
|
protected ?Actor $actor = null;
|
|
|
|
|
|
|
|
protected ?Actor $target_actor = null;
|
|
|
|
|
|
|
|
protected ?Post $post = null;
|
|
|
|
|
|
|
|
protected ?Activity $activity = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
protected $uuids = ['post_id', 'activity_id'];
|
|
|
|
|
|
|
|
/**
|
2024-04-28 16:39:01 +00:00
|
|
|
* @var list<string>
|
2022-08-12 16:02:56 +00:00
|
|
|
*/
|
|
|
|
protected $dates = ['read_at', 'created_at', 'updated_at'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => 'integer',
|
|
|
|
'actor_id' => 'integer',
|
2022-08-12 16:02:56 +00:00
|
|
|
'target_actor_id' => 'integer',
|
2023-06-12 14:47:38 +00:00
|
|
|
'post_id' => '?string',
|
|
|
|
'activity_id' => 'string',
|
|
|
|
'type' => 'string',
|
2022-08-12 16:02:56 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public function getActor(): ?Actor
|
|
|
|
{
|
|
|
|
if ($this->actor_id === null) {
|
|
|
|
throw new RuntimeException('Notification must have an actor_id before getting actor.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $this->actor instanceof Actor) {
|
|
|
|
$this->actor = (new ActorModel())->getActorById($this->actor_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTargetActor(): ?Actor
|
|
|
|
{
|
|
|
|
if ($this->target_actor_id === null) {
|
|
|
|
throw new RuntimeException('Notification must have a target_actor_id before getting target actor.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $this->target_actor instanceof Actor) {
|
|
|
|
$this->target_actor = (new ActorModel())->getActorById($this->target_actor_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->target_actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPost(): ?Post
|
|
|
|
{
|
|
|
|
if ($this->post_id === null) {
|
|
|
|
throw new RuntimeException('Notification must have a post_id before getting post.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $this->post instanceof Post) {
|
|
|
|
$this->post = (new PostModel())->getPostById($this->post_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->post;
|
|
|
|
}
|
|
|
|
}
|