From b8e259f75dfa52584d7483313b0c6814867d2330 Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 20 Jan 2025 18:20:45 +0000 Subject: follow, unfollow, follow request notifications --- Digitigrade/Model/FollowRelation.php | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'Digitigrade/Model/FollowRelation.php') diff --git a/Digitigrade/Model/FollowRelation.php b/Digitigrade/Model/FollowRelation.php index 0af9da5..7cab761 100644 --- a/Digitigrade/Model/FollowRelation.php +++ b/Digitigrade/Model/FollowRelation.php @@ -2,8 +2,9 @@ namespace Digitigrade\Model; use Digitigrade\Model; +use Digitigrade\Notification\Notifyable; -class FollowRelation extends Model { +class FollowRelation extends Model implements Notifyable { public Actor $subject; public Actor $object; public FollowRelationStatus $status; @@ -48,4 +49,38 @@ class FollowRelation extends Model { public static function findAllWithObject(Actor $object): array { return self::findAllWhere('object = ?', [$object->id]); } + + public function toJsonReference(): mixed { + return [$this->subject->id, $this->object->id]; + } + + public static function fromJsonReference(mixed $reference): self { + return self::findByActors( + Actor::find($reference[0]), + Actor::find($reference[1]) + ); + } + + public function getNotificationTitle(): string { + $status = $this->status->value; + return sprintf(__("notifications.follow.$status"), $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