aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/Interaction.php
diff options
context:
space:
mode:
authorwinter2025-01-19 22:17:12 +0000
committerwinter2025-01-19 22:17:12 +0000
commit8c6dad8c48d5d730b102d9de0079fee9752b0d35 (patch)
tree2cfe07a8c7958f78c767fd0d1444c3f8fef70511 /Digitigrade/Model/Interaction.php
parent2d9bd87fb1c565ee161f93219ce2533e8dbffe06 (diff)
implement notifications
Diffstat (limited to 'Digitigrade/Model/Interaction.php')
-rw-r--r--Digitigrade/Model/Interaction.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/Digitigrade/Model/Interaction.php b/Digitigrade/Model/Interaction.php
index e5619bb..cf2be01 100644
--- a/Digitigrade/Model/Interaction.php
+++ b/Digitigrade/Model/Interaction.php
@@ -1,11 +1,12 @@
<?php
namespace Digitigrade\Model;
-use Digitigrade\Timeline\HomeTimelineItem;
+use Digitigrade\Model\HomeTimelineItem;
+use Digitigrade\Notification\Notifyable;
use Digitigrade\Timeline\ReasonReshared;
use Digitigrade\Timeline\TimelineItem;
-class Interaction extends PushableModel {
+class Interaction extends PushableModel implements Notifyable {
public ?int $id;
public string $uri;
public \DateTimeImmutable $created;
@@ -61,6 +62,30 @@ class Interaction extends PushableModel {
return array_unique($instances);
}
+ public function getNotificationTitle(): string {
+ return sprintf(__('notifications.interaction.' . $this->kind->value . '.title'), $this->author->displayName);
+ }
+ public function getNotificationTitleLink(): ?string {
+ return '/@/' . $this->target->author->getFullHandle() . '/note/' . $this->target->id;
+ }
+ public function getNotificationBody(): ?string {
+ return $this->target->plainContent;
+ }
+ public function getNotificationImageUrl(): ?string {
+ return $this->author->avatar;
+ }
+ public function getNotificationImageLink(): ?string {
+ return '/@/' . $this->author->getFullHandle();
+ }
+
+ public function toJsonReference(): mixed {
+ return $this->id;
+ }
+
+ public static function fromJsonReference(mixed $reference): self {
+ return self::find($reference);
+ }
+
public function processTimelineAdditions() {
// basically, if this is a reshare, we need to put a home timeline item
// for all followers who can see the shared note
@@ -80,6 +105,14 @@ class Interaction extends PushableModel {
}
}
+ public function processNotifications() {
+ if (!$this->target->author->isLocal || $this->author == $this->target->author) {
+ return;
+ }
+ $recipient = UserAccount::findByLinkedActor($this->target->author);
+ Notification::fromNotifyable($this, $recipient)->send();
+ }
+
public function jsonSerialize(): array {
if ($this->deleted) {
return [