aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/Note.php
diff options
context:
space:
mode:
authorwinter2025-01-15 20:33:38 +0000
committerwinter2025-01-15 20:33:38 +0000
commit75b3778dccccddb5cc90b2b4e0a3f958826ad8ba (patch)
tree6240a96338f58b5f175e97132a4ce5d804e3b2da /Digitigrade/Model/Note.php
parent07df9da970ceaa54c734d73bdb148fa36d42db63 (diff)
implement home timeline
Diffstat (limited to 'Digitigrade/Model/Note.php')
-rw-r--r--Digitigrade/Model/Note.php37
1 files changed, 31 insertions, 6 deletions
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 [