diff options
Diffstat (limited to 'Digitigrade/Model/Note.php')
| -rw-r--r-- | Digitigrade/Model/Note.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 7da6d8e..01bc861 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -83,6 +83,10 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { $this->attachments = NoteAttachment::findAllWhere('note_id = ?', [$this->id]); } + protected function dehydrate() { + $this->saveMentions(); + } + protected function validate(): bool { // author has to be from the same instance as the note itself return hostname_from_uri($this->author->uri) == hostname_from_uri($this->uri); @@ -105,6 +109,14 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return $actors; } + private function saveMentions() { + $pdo = Db::getInstance()->getPdo(); + foreach ($this->mentions as $mention) { + $stmt = $pdo->prepare('INSERT INTO note_mention(note_id, actor_id) VALUES (?, ?) ON CONFLICT DO NOTHING'); + $stmt->execute([$this->id, $mention->id]); + } + } + public static function findAllWithAuthor(Actor $author, ?int $limit = null, int $offset = 0, bool $includeDeleted = false): array { $where = 'author = ?'; if (!$includeDeleted) { @@ -197,8 +209,8 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { } public function getNotificationTitle(): string { - // assuming that this notification is because the note is a reply for now - return sprintf(__('notifications.interaction.reply.title'), $this->author->displayName); + $action = isset($this->inReplyTo) ? 'interaction.reply' : 'mention'; + return sprintf(__("notifications.$action.title"), $this->author->displayName); } public function getNotificationTitleLink(): ?string { return '/@/' . $this->author->getFullHandle() . '/note/' . $this->id; |
