aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Notification
diff options
context:
space:
mode:
authorwinter2025-01-20 18:20:45 +0000
committerwinter2025-01-20 18:20:45 +0000
commitb8e259f75dfa52584d7483313b0c6814867d2330 (patch)
tree00f84b0f4485889d2278de99389fdced001ba357 /Digitigrade/Notification
parentfb4cbc73bae831e68fe8234811184f46077db5e6 (diff)
follow, unfollow, follow request notifications
Diffstat (limited to 'Digitigrade/Notification')
-rw-r--r--Digitigrade/Notification/PendingFollowActionedNotif.php52
-rw-r--r--Digitigrade/Notification/UnfollowNotif.php49
2 files changed, 101 insertions, 0 deletions
diff --git a/Digitigrade/Notification/PendingFollowActionedNotif.php b/Digitigrade/Notification/PendingFollowActionedNotif.php
new file mode 100644
index 0000000..6ab36ee
--- /dev/null
+++ b/Digitigrade/Notification/PendingFollowActionedNotif.php
@@ -0,0 +1,52 @@
+<?php
+namespace Digitigrade\Notification;
+
+use Digitigrade\Model\Actor;
+use Digitigrade\Model\Notification;
+use Digitigrade\Model\UserAccount;
+
+class PendingFollowActionedNotif implements Notifyable {
+ private Actor $subject;
+ private Actor $object;
+ private string $action;
+
+ public function __construct(Actor $subject, Actor $object, string $action) {
+ $this->subject = $subject;
+ $this->object = $object;
+ $this->action = $action;
+ }
+
+ public function toJsonReference(): mixed {
+ return [$this->subject->id, $this->object->id, $this->action];
+ }
+
+ public static function fromJsonReference(mixed $reference): self {
+ return new self(
+ Actor::find($reference[0]),
+ Actor::find($reference[1]),
+ $reference[2]
+ );
+ }
+
+ public function getNotificationTitle(): string {
+ return sprintf(__("notifications.follow.$this->action"), $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
diff --git a/Digitigrade/Notification/UnfollowNotif.php b/Digitigrade/Notification/UnfollowNotif.php
new file mode 100644
index 0000000..e00c342
--- /dev/null
+++ b/Digitigrade/Notification/UnfollowNotif.php
@@ -0,0 +1,49 @@
+<?php
+namespace Digitigrade\Notification;
+
+use Digitigrade\Model\Actor;
+use Digitigrade\Model\Notification;
+use Digitigrade\Model\UserAccount;
+
+class UnfollowNotif implements Notifyable {
+ private Actor $subject;
+ private Actor $object;
+
+ public function __construct(Actor $subject, Actor $object) {
+ $this->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.follow.removed'), $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