aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Model')
-rw-r--r--Digitigrade/Model/Note.php13
-rw-r--r--Digitigrade/Model/NoteAttachment.php6
2 files changed, 16 insertions, 3 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) {
diff --git a/Digitigrade/Model/NoteAttachment.php b/Digitigrade/Model/NoteAttachment.php
index c47ec64..9e6a3d3 100644
--- a/Digitigrade/Model/NoteAttachment.php
+++ b/Digitigrade/Model/NoteAttachment.php
@@ -10,13 +10,13 @@ class NoteAttachment extends Model {
public string $href;
public ?string $description;
- protected function setOwnerId(int $id) {
+ public function setOwnerId(int $id) {
$this->noteId = $id;
}
protected function getUpdateWhereClause($db): ?string {
- if (self::findWhere('note_id = ?', [$this->noteId]) != null) {
- return "note_id = $this->noteId";
+ if (self::findWhere('note_id = ? AND index = ?', [$this->noteId, $this->index]) != null) {
+ return "note_id = $this->noteId AND index = $this->index";
}
return null;
}