From 75b3778dccccddb5cc90b2b4e0a3f958826ad8ba Mon Sep 17 00:00:00 2001 From: winter Date: Wed, 15 Jan 2025 20:33:38 +0000 Subject: implement home timeline --- Digitigrade/Model/Note.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'Digitigrade/Model/Note.php') diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 71b25ae..7fb1221 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -2,8 +2,9 @@ namespace Digitigrade\Model; use Digitigrade\Db; -use Digitigrade\Job\PushObject; -use Digitigrade\TimelineIncludeable; +use Digitigrade\Timeline\HomeTimelineItem; +use Digitigrade\Timeline\TimelineIncludeable; +use Digitigrade\Timeline\TimelineItem; class Note extends PushableModel implements TimelineIncludeable { public ?int $id; @@ -139,13 +140,19 @@ class Note extends PushableModel implements TimelineIncludeable { return self::countWhere('in_reply_to = ? AND deleted = false', [$this->id]); } - protected function getRelevantServers(): array { - $recipientActors = match ($this->privacy->scope) { + /** + * @return Actor[] actors who this note can be seen by, are mentioned, etc + */ + public function getRelevantActors(): array { + return array_unique(array_merge(match ($this->privacy->scope) { NotePrivacyScope::NONE => [], NotePrivacyScope::MUTUALS => $this->author->findMutualFollows(), default => $this->author->findFollowers() - }; - $recipientActors = array_merge($recipientActors, $this->mentions, $this->privacy->alsoVisibleTo); + }, $this->mentions, $this->privacy->alsoVisibleTo, [$this->author])); + } + + protected function getRelevantServers(): array { + $recipientActors = $this->getRelevantActors(); // 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; @@ -170,6 +177,24 @@ class Note extends PushableModel implements TimelineIncludeable { render_template('note', ['note' => $this]); } + public function toJsonReference(): mixed { + return $this->id; + } + + public static function fromJsonReference(mixed $reference): self { + return self::find($reference); + } + + public function processTimelineAdditions() { + $item = new TimelineItem($this); + foreach ($this->getRelevantActors() as $actor) { + if (!$actor->isLocal) + continue; + $user = UserAccount::findByLinkedActor($actor); + HomeTimelineItem::fromTimelineItem($item, $user)->save(); + } + } + public function jsonSerialize(): array { if ($this->deleted) { return [ -- cgit v1.3