aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Notification
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Notification')
-rw-r--r--Digitigrade/Notification/AdminEditedNoteNotif.php9
-rw-r--r--Digitigrade/Notification/PokeNotif.php62
2 files changed, 70 insertions, 1 deletions
diff --git a/Digitigrade/Notification/AdminEditedNoteNotif.php b/Digitigrade/Notification/AdminEditedNoteNotif.php
index f3c18a1..888130b 100644
--- a/Digitigrade/Notification/AdminEditedNoteNotif.php
+++ b/Digitigrade/Notification/AdminEditedNoteNotif.php
@@ -2,6 +2,7 @@
namespace Digitigrade\Notification;
use Digitigrade\Model\Note;
+use Digitigrade\Model\Notification;
use Digitigrade\Model\UserAccount;
class AdminEditedNoteNotif implements Notifyable {
@@ -22,7 +23,7 @@ class AdminEditedNoteNotif implements Notifyable {
}
public function getNotificationTitle(): string {
- return __f('notification.adminEditedNote', $this->admin->actor->displayName);
+ return __f('notifications.adminEditedNote', $this->admin->actor->displayName);
}
public function getNotificationTitleLink(): ?string {
@@ -40,4 +41,10 @@ class AdminEditedNoteNotif implements Notifyable {
public function getNotificationImageLink(): ?string {
return $this->admin->actor->getLocalUiHref();
}
+
+ public function processNotifications() {
+ if (!$this->note->author->isLocal)
+ return;
+ Notification::fromNotifyable($this, UserAccount::findByLinkedActor($this->note->author))->send();
+ }
} \ No newline at end of file
diff --git a/Digitigrade/Notification/PokeNotif.php b/Digitigrade/Notification/PokeNotif.php
new file mode 100644
index 0000000..5446098
--- /dev/null
+++ b/Digitigrade/Notification/PokeNotif.php
@@ -0,0 +1,62 @@
+<?php
+namespace Digitigrade\Notification;
+
+use Digitigrade\Model\Actor;
+use Digitigrade\Model\Notification;
+use Digitigrade\Model\UserAccount;
+use Digitigrade\PokeVerb;
+
+class PokeNotif implements Notifyable {
+ private Actor $subject;
+ private PokeVerb $verb;
+ private Actor $object;
+ private bool $urgent;
+
+ public function __construct(Actor $subject, PokeVerb $verb, Actor $object, bool $urgent) {
+ $this->subject = $subject;
+ $this->verb = $verb;
+ $this->object = $object;
+ $this->urgent = $urgent;
+ }
+
+ public function toJsonReference(): mixed {
+ return [$this->subject->id, $this->verb->value, $this->object->id, $this->urgent];
+ }
+
+ public static function fromJsonReference(mixed $reference): ?self {
+ return new self(
+ Actor::find($reference[0]),
+ PokeVerb::from($reference[1]),
+ Actor::find($reference[2]),
+ $reference[3]
+ );
+ }
+
+ public function getNotificationTitle(): string {
+ $kind = $this->urgent ? 'urgent' : 'normal';
+ $verb = $this->verb->value;
+ return __f("notifications.poke.$kind", $this->subject->displayName, __("notifications.poke.verb.$verb"));
+ }
+
+ public function getNotificationTitleLink(): ?string {
+ return $this->subject->getLocalUiHref();
+ }
+
+ public function getNotificationBody(): ?string {
+ return null;
+ }
+
+ public function getNotificationImageUrl(): ?string {
+ return $this->subject->avatar ?? '/static/default-avatar.png';
+ }
+
+ public function getNotificationImageLink(): ?string {
+ return $this->subject->getLocalUiHref();
+ }
+
+ public function processNotifications() {
+ if (!$this->object->isLocal)
+ return;
+ Notification::fromNotifyable($this, UserAccount::findByLinkedActor($this->object))->send();
+ }
+} \ No newline at end of file