diff options
| author | winter | 2025-01-28 16:59:43 +0000 |
|---|---|---|
| committer | winter | 2025-01-28 16:59:43 +0000 |
| commit | 09a42d23cd067dc5c2a7d4f03e8f074a9317f6c8 (patch) | |
| tree | c01ea939a0c72c2a4ed5b6479d7739f3dbaaf01f /Digitigrade/Model/Note.php | |
| parent | 4c66a437d3125ef1a03bac96b80c82e9da060a81 (diff) | |
implement extensions on existing objects
Diffstat (limited to 'Digitigrade/Model/Note.php')
| -rw-r--r-- | Digitigrade/Model/Note.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 01bc861..0164e7d 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -81,10 +81,12 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { $this->formattedContent = $this->findFormattedContents(); $this->mentions = $this->findMentions(); $this->attachments = NoteAttachment::findAllWhere('note_id = ?', [$this->id]); + $this->extensions = $this->findExtensions(); } protected function dehydrate() { $this->saveMentions(); + $this->saveExtensions(); } protected function validate(): bool { @@ -109,6 +111,17 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return $actors; } + private function findExtensions(): array { + $pdo = Db::getInstance()->getPdo(); + $stmt = $pdo->prepare('SELECT uri, data FROM note_extension WHERE note_id = ?'); + $stmt->execute([$this->id]); + $items = []; + while ($row = $stmt->fetch()) { + $items[$row['uri']] = json_decode($row['data']); + } + return $items; + } + private function saveMentions() { $pdo = Db::getInstance()->getPdo(); foreach ($this->mentions as $mention) { @@ -117,6 +130,17 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { } } + private function saveExtensions() { + $pdo = Db::getInstance()->getPdo(); + foreach ($this->extensions as $uri => $obj) { + $stmt = $pdo->prepare( + 'INSERT INTO note_extension(note_id, uri, data) VALUES (?, ?, ?) ' . + 'ON CONFLICT (note_id, uri) DO UPDATE SET data = EXCLUDED.data' + ); + $stmt->execute([$this->id, $uri, json_encode($obj)]); + } + } + public static function findAllWithAuthor(Actor $author, ?int $limit = null, int $offset = 0, bool $includeDeleted = false): array { $where = 'author = ?'; if (!$includeDeleted) { |
