*/ protected $casts = [ 'id' => 'string', 'uri' => 'string', 'episode_id' => 'integer', 'actor_id' => 'integer', 'in_reply_to_id' => '?string', 'message' => 'string', 'message_html' => 'string', 'likes_count' => 'integer', 'replies_count' => 'integer', 'created_by' => 'integer', 'is_from_post' => 'boolean', ]; public function getEpisode(): ?Episode { if ($this->episode_id === null) { throw new RuntimeException('Comment must have an episode_id before getting episode.'); } if (! $this->episode instanceof Episode) { $this->episode = (new EpisodeModel())->getEpisodeById($this->episode_id); } return $this->episode; } /** * Returns the comment's actor * * @noRector ReturnTypeDeclarationRector */ public function getActor(): ?Actor { if ($this->actor_id === null) { throw new RuntimeException('Comment must have an actor_id before getting actor.'); } if ($this->actor === null) { // @phpstan-ignore-next-line $this->actor = model(ActorModel::class, false) ->getActorById($this->actor_id); } // @phpstan-ignore-next-line return $this->actor; } /** * @return EpisodeComment[] */ public function getReplies(): array { if ($this->id === null) { throw new RuntimeException('Comment must be created before getting replies.'); } if ($this->replies === null) { $this->replies = (new EpisodeCommentModel())->getCommentReplies($this->id); } return $this->replies; } public function getHasReplies(): bool { return $this->getReplies() !== []; } /** * @noRector ReturnTypeDeclarationRector */ public function getReplyToComment(): ?self { if ($this->in_reply_to_id === null) { throw new RuntimeException('Comment is not a reply.'); } if ($this->reply_to_comment === null) { $this->reply_to_comment = model(EpisodeCommentModel::class, false) ->getCommentById($this->in_reply_to_id); } return $this->reply_to_comment; } public function setMessage(string $message): static { helper('fediverse'); $messageWithoutTags = strip_tags($message); $this->attributes['message'] = $messageWithoutTags; $this->attributes['message_html'] = str_replace("\n", '
', linkify($messageWithoutTags)); return $this; } }