diff options
Diffstat (limited to 'Digitigrade')
| -rw-r--r-- | Digitigrade/Model.php | 16 | ||||
| -rw-r--r-- | Digitigrade/Model/Note.php | 14 |
2 files changed, 30 insertions, 0 deletions
diff --git a/Digitigrade/Model.php b/Digitigrade/Model.php index 4a206a6..be664cb 100644 --- a/Digitigrade/Model.php +++ b/Digitigrade/Model.php @@ -183,6 +183,22 @@ abstract class Model { return static::findAllWhere('1 = 1', []); } + public static function countWhere(string $whereClause, array $parameters): int { + $classNameParts = explode('\\', static::class); + $className = $classNameParts[count($classNameParts) - 1]; + $tableName = self::mangleName($className); + + $query = "SELECT count(*) FROM $tableName WHERE $whereClause"; + $stmt = Db::getInstance()->getPdo()->prepare($query); + $stmt->execute($parameters); + return $stmt->fetchColumn(0); + } + + public static function count(): int { + // FIXME + return static::countWhere('1 = 1', []); + } + public static function find(int $id): ?static { return static::findWhere('id = ?', [$id]); } 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(); |
