From 25b748f04911262826d0a0bc9609e03ee47c3232 Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 14 Jan 2025 18:13:57 +0000 Subject: add interaction counters --- Digitigrade/Model/Note.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Digitigrade/Model/Note.php') diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index a4891a3..cf23e80 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -123,10 +123,18 @@ class Note extends PushableModel implements TimelineIncludeable { return Interaction::findAllWithTarget($this); } + public function countInteractionsOfKind(InteractionKind $kind): int { + return Interaction::countWhere('target = ? AND kind = ? AND deleted = false', [$this->id, $kind->value]); + } + public function getInteractionsWithAuthor(Actor $author): array { return Interaction::findAllWhere('author = ? AND target = ? AND deleted = false', [$author->id, $this->id]); } + public function countReplies(): int { + return self::countWhere('in_reply_to = ? AND deleted = false', [$this->id]); + } + protected function getRelevantServers(): array { $recipientActors = match ($this->privacy->scope) { NotePrivacyScope::NONE => [], @@ -134,6 +142,12 @@ class Note extends PushableModel implements TimelineIncludeable { default => $this->author->findFollowers() }; $recipientActors = array_merge($recipientActors, $this->mentions, $this->privacy->alsoVisibleTo); + // reply-to and thread apex author should be covered by mentions but in case they're not: + if (isset($this->inReplyTo)) + $recipientActors[] = $this->inReplyTo->author; + if (isset($this->threadApex)) + $recipientActors[] = $this->threadApex->author; + $recipientActors = array_unique($recipientActors); $instances = array_map(function (Actor $a) { return $a->findHomeInstance(); -- cgit v1.3