From bc9c83b6c33d460a574fbeb764c23bfbe941b4c0 Mon Sep 17 00:00:00 2001 From: winter Date: Thu, 23 Jan 2025 18:55:52 +0000 Subject: implement blocking users it doesn't work yet for notifications! but i think i got it in most other places --- Digitigrade/Notification/Notifyable.php | 2 +- Digitigrade/Notification/UnblockNotif.php | 49 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Digitigrade/Notification/UnblockNotif.php (limited to 'Digitigrade/Notification') diff --git a/Digitigrade/Notification/Notifyable.php b/Digitigrade/Notification/Notifyable.php index 510437e..7a7826f 100644 --- a/Digitigrade/Notification/Notifyable.php +++ b/Digitigrade/Notification/Notifyable.php @@ -3,7 +3,7 @@ namespace Digitigrade\Notification; interface Notifyable { public function toJsonReference(): mixed; - public static function fromJsonReference(mixed $reference): self; + public static function fromJsonReference(mixed $reference): ?self; public function getNotificationTitle(): string; public function getNotificationTitleLink(): ?string; public function getNotificationBody(): ?string; diff --git a/Digitigrade/Notification/UnblockNotif.php b/Digitigrade/Notification/UnblockNotif.php new file mode 100644 index 0000000..7f7ac64 --- /dev/null +++ b/Digitigrade/Notification/UnblockNotif.php @@ -0,0 +1,49 @@ +subject = $subject; + $this->object = $object; + } + + public function toJsonReference(): mixed { + return [$this->subject->id, $this->object->id]; + } + + public static function fromJsonReference(mixed $reference): self { + return new self( + Actor::find($reference[0]), + Actor::find($reference[1]) + ); + } + + public function getNotificationTitle(): string { + return sprintf(__('notifications.unblock'), $this->subject->displayName); + } + public function getNotificationTitleLink(): ?string { + return '/@/' . $this->subject->getFullHandle(); + } + public function getNotificationImageUrl(): ?string { + return $this->subject->avatar ?? '/static/default-avatar.png'; + } + public function getNotificationImageLink(): ?string { + return $this->getNotificationTitleLink(); + } + public function getNotificationBody(): ?string { + return null; + } + + 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