From bda28640d6e066ae338c6f31407df274ed09f026 Mon Sep 17 00:00:00 2001 From: winter Date: Sun, 8 Dec 2024 23:18:35 +0000 Subject: implement remote object fetching! this is most of the tricky parts of inbound federation :3 --- WpfTest/Model/Note.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'WpfTest/Model/Note.php') diff --git a/WpfTest/Model/Note.php b/WpfTest/Model/Note.php index 85b3567..af2d2aa 100644 --- a/WpfTest/Model/Note.php +++ b/WpfTest/Model/Note.php @@ -2,9 +2,8 @@ namespace WpfTest\Model; use WpfTest\Db; -use WpfTest\Model; -class Note extends Model implements \JsonSerializable { +class Note extends FetchableModel implements \JsonSerializable { public ?int $id; public string $uri; public \DateTimeImmutable $created; @@ -30,7 +29,15 @@ class Note extends Model implements \JsonSerializable { public array $attachments = []; public array $extensions = []; - protected function hydrate(array $row) { + protected function getUpdateWhereClause(\PDO $db): ?string { + if (self::findWhere('uri = ?', [$this->uri]) != null) + return 'uri = ' . $db->quote($this->uri); + if (self::findWhere('id = ?', [$this->id]) != null) + return "id = $this->id"; + return null; + } + + protected function hydrate() { $this->privacy = NotePrivacy::findWhere('note_id = ?', [$this->id]); $this->formattedContent = $this->findFormattedContents(); $this->mentions = $this->findMentions(); @@ -74,14 +81,7 @@ class Note extends Model implements \JsonSerializable { }, $this->mentions), 'inReplyTo' => $this->inReplyTo?->uri, 'threadApex' => $this->threadApex?->uri, - 'privacy' => [ - 'scope' => $this->privacy->scope->name, - 'alsoVisibleTo' => $this->privacy->alsoVisibleTo, - 'indexable' => $this->privacy->indexable, - 'canReshare' => $this->privacy->canReshare->name, - 'canReply' => $this->privacy->canReply->name, - 'canOtherInteract' => $this->privacy->canOtherInteract->name - ], + 'privacy' => $this->privacy, 'attachments' => array_map(function (NoteAttachment $attachment) { return [ 'type' => $attachment->type, -- cgit v1.3