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/Model/BlockRelation.php | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Digitigrade/Model/BlockRelation.php (limited to 'Digitigrade/Model/BlockRelation.php') diff --git a/Digitigrade/Model/BlockRelation.php b/Digitigrade/Model/BlockRelation.php new file mode 100644 index 0000000..ca7166c --- /dev/null +++ b/Digitigrade/Model/BlockRelation.php @@ -0,0 +1,82 @@ +subject = $subject; + $rel->object = $object; + $rel->save(); + return $rel; + } + + protected function getUpdateWhereClause(\PDO $db): ?string { + if (self::findWhere('subject = ? and object = ?', [$this->subject->id, $this->object->id]) != null) { + return 'subject = ' . $this->subject->id . ' and object = ' . $this->object->id; + } + return null; + } + + public static function findByActors(Actor $subject, Actor $object): ?self { + return self::findWhere('subject = ? and object = ?', [$subject->id, $object->id]); + } + + /** + * @return self[] + */ + public static function findAllWithSubject(Actor $subject): array { + return self::findAllWhere('subject = ?', [$subject->id]); + } + + /** + * @return self[] + */ + 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 { + return sprintf(__("notifications.block"), $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