From 145b5db9474e32ca3430fe35eaa7498d7f26ff95 Mon Sep 17 00:00:00 2001 From: winter Date: Sun, 16 Mar 2025 00:53:52 +0000 Subject: implement poking and such --- Digitigrade/Notification/PokeNotif.php | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Digitigrade/Notification/PokeNotif.php (limited to 'Digitigrade/Notification/PokeNotif.php') 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 @@ +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 -- cgit v1.3