2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
use ActivityPub\Entities\Note as ActivityPubNote;
|
|
|
|
use App\Models\ActorModel;
|
2021-04-02 17:20:02 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2021-05-06 14:00:48 +00:00
|
|
|
use RuntimeException;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property int|null $episode_id
|
|
|
|
* @property Episode|null $episode
|
|
|
|
*/
|
|
|
|
class Note extends ActivityPubNote
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Episode|null
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
|
|
|
protected $episode;
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'id' => 'string',
|
|
|
|
'uri' => 'string',
|
|
|
|
'actor_id' => 'integer',
|
|
|
|
'in_reply_to_id' => '?string',
|
|
|
|
'reblog_of_id' => '?string',
|
|
|
|
'episode_id' => '?integer',
|
|
|
|
'message' => 'string',
|
|
|
|
'message_html' => 'string',
|
|
|
|
'favourites_count' => 'integer',
|
|
|
|
'reblogs_count' => 'integer',
|
|
|
|
'replies_count' => 'integer',
|
|
|
|
'created_by' => 'integer',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the note's attached episode
|
|
|
|
*
|
|
|
|
* @return \App\Entities\Episode
|
|
|
|
*/
|
|
|
|
public function getEpisode()
|
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->episode_id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Note must have an episode_id before getting episode.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->episode === null) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->episode = (new EpisodeModel())->getEpisodeById(
|
|
|
|
$this->episode_id,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->episode;
|
|
|
|
}
|
|
|
|
}
|