diff options
| author | winter | 2025-01-28 20:34:49 +0000 |
|---|---|---|
| committer | winter | 2025-01-28 20:34:49 +0000 |
| commit | e591374bb4b7d231fadf99d2e278806e53971919 (patch) | |
| tree | 146bc3eeca58fb298dc204341734f55680509c00 /Digitigrade/Model/Note.php | |
| parent | 09a42d23cd067dc5c2a7d4f03e8f074a9317f6c8 (diff) | |
display attachments on notes
Diffstat (limited to 'Digitigrade/Model/Note.php')
| -rw-r--r-- | Digitigrade/Model/Note.php | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 0164e7d..a4df99d 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -82,10 +82,14 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { $this->mentions = $this->findMentions(); $this->attachments = NoteAttachment::findAllWhere('note_id = ?', [$this->id]); $this->extensions = $this->findExtensions(); + + // put attachments back in the right order + usort($this->attachments, fn($a, $b) => $a->index <=> $b->index); } protected function dehydrate() { $this->saveMentions(); + $this->saveAttachments(); $this->saveExtensions(); } @@ -130,6 +134,15 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { } } + private function saveAttachments() { + $index = 0; + foreach ($this->attachments as $att) { + $att->index = $index++; + $att->setOwnerId($this->id); + $att->save(); + } + } + private function saveExtensions() { $pdo = Db::getInstance()->getPdo(); foreach ($this->extensions as $uri => $obj) { |
