aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorwinter2025-03-15 21:57:00 +0000
committerwinter2025-03-15 21:57:00 +0000
commitd5dd9044632320e625ce90ae9627ebc11c7a04d6 (patch)
treeb5466a37f464e9b3ba43c7ed0d232afc442f656b
parent8843a8cb197e71b1ca42f1ea56be5f806ad0f5b4 (diff)
send notification to author when admin edits note
-rw-r--r--Digitigrade/Notification/AdminEditedNoteNotif.php43
-rw-r--r--locale/en_GB.json1
-rw-r--r--routes/note_fragment.php10
3 files changed, 54 insertions, 0 deletions
diff --git a/Digitigrade/Notification/AdminEditedNoteNotif.php b/Digitigrade/Notification/AdminEditedNoteNotif.php
new file mode 100644
index 0000000..f3c18a1
--- /dev/null
+++ b/Digitigrade/Notification/AdminEditedNoteNotif.php
@@ -0,0 +1,43 @@
+<?php
+namespace Digitigrade\Notification;
+
+use Digitigrade\Model\Note;
+use Digitigrade\Model\UserAccount;
+
+class AdminEditedNoteNotif implements Notifyable {
+ private UserAccount $admin;
+ private Note $note;
+
+ public function __construct(UserAccount $admin, Note $note) {
+ $this->admin = $admin;
+ $this->note = $note;
+ }
+
+ public function toJsonReference(): mixed {
+ return [$this->admin->id, $this->note->id];
+ }
+
+ public static function fromJsonReference(mixed $reference): self {
+ return new self(UserAccount::find($reference[0]), Note::find($reference[1]));
+ }
+
+ public function getNotificationTitle(): string {
+ return __f('notification.adminEditedNote', $this->admin->actor->displayName);
+ }
+
+ public function getNotificationTitleLink(): ?string {
+ return $this->note->getLocalUiHref();
+ }
+
+ public function getNotificationBody(): ?string {
+ return isset($this->note->summary) ? ('[' . $this->note->summary . ']') : $this->note->plainContent;
+ }
+
+ public function getNotificationImageUrl(): ?string {
+ return $this->admin->actor->avatar ?? '/static/default-avatar.png';
+ }
+
+ public function getNotificationImageLink(): ?string {
+ return $this->admin->actor->getLocalUiHref();
+ }
+} \ No newline at end of file
diff --git a/locale/en_GB.json b/locale/en_GB.json
index 22cc291..094ac2e 100644
--- a/locale/en_GB.json
+++ b/locale/en_GB.json
@@ -84,6 +84,7 @@
"notifications.follow.reject": "%s rejected your follow request",
"notifications.block": "%s blocked you",
"notifications.unblock": "%s unblocked you",
+ "notification.adminEditedNote": "An admin (%s) edited your note",
"login.pageTitle": "Log in",
"login.email": "Email address",
"login.password": "Password",
diff --git a/routes/note_fragment.php b/routes/note_fragment.php
index 9cc9143..907260d 100644
--- a/routes/note_fragment.php
+++ b/routes/note_fragment.php
@@ -10,8 +10,10 @@ use Digitigrade\Model\InteractionKind;
use Digitigrade\Model\Note;
use Digitigrade\Model\NoteAttachment;
use Digitigrade\Model\NotePrivacyScope;
+use Digitigrade\Model\Notification;
use Digitigrade\Model\StorageObject;
use Digitigrade\Model\UserAccount;
+use Digitigrade\Notification\AdminEditedNoteNotif;
use Digitigrade\PolicyManager;
use Digitigrade\Router;
use Digitigrade\StorageProvider\FilesystemStorage;
@@ -138,6 +140,14 @@ Router::getInstance()->mount('/fragment/note/:id/edit', function (array $args) {
$note->modified = new DateTimeImmutable();
$note->save();
$note->publish();
+
+ if ($user->actor != $note->author) {
+ Notification::fromNotifyable(
+ new AdminEditedNoteNotif($user, $note),
+ UserAccount::findByLinkedActor($note->author)
+ )->send();
+ }
+
render_template('note/note', ['note' => $note]);
} else {
render_template('note/editable', ['note' => $note]);