aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade')
-rw-r--r--Digitigrade/Model.php10
-rw-r--r--Digitigrade/Model/Note.php16
2 files changed, 24 insertions, 2 deletions
diff --git a/Digitigrade/Model.php b/Digitigrade/Model.php
index 9ce759a..14d025d 100644
--- a/Digitigrade/Model.php
+++ b/Digitigrade/Model.php
@@ -139,6 +139,13 @@ abstract class Model {
}
/**
+ * Saves fields of the model that couldn't be saved automatically
+ * @return void
+ */
+ protected function dehydrate() {
+ }
+
+ /**
* Checks that all fields of the model are valid and allowed
* @return bool true if the model is valid, false otherwise
*/
@@ -308,6 +315,9 @@ abstract class Model {
}
}
+ // anything else that needs saving right now
+ $this->dehydrate();
+
$this->saved = true;
}
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;