diff options
| author | winter | 2024-12-19 22:59:40 +0000 |
|---|---|---|
| committer | winter | 2024-12-19 22:59:40 +0000 |
| commit | df051a7524a93f96bfc69924c202a51286517ce2 (patch) | |
| tree | ae6818812367b642e5359291f04b47a6627c02e8 /Digitigrade/Model/Note.php | |
| parent | f6a55426cac40501aa7f8e88eb7bfd318d7cd170 (diff) | |
let notes push themselves to interested parties
Diffstat (limited to 'Digitigrade/Model/Note.php')
| -rw-r--r-- | Digitigrade/Model/Note.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 0117a3c..7ffb67e 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -2,6 +2,7 @@ namespace Digitigrade\Model; use Digitigrade\Db; +use Digitigrade\Job\PushObject; class Note extends PushableModel { public ?int $id; @@ -109,6 +110,32 @@ class Note extends PushableModel { return Interaction::findAllWithTarget($this); } + /** + * Sends this note to all instances it's relevant to. + * + * For example, this may include the servers of any followers if the scope is at + * least 'followers', anyone mentioned, and anyone in the alsoVisibleTo field. + * If the scope is 'public' it may also send it to other servers? i'm not sure + * @return void + */ + public function publish() { + $recipientActors = match ($this->privacy->scope) { + NotePrivacyScope::NONE => [], + NotePrivacyScope::MUTUALS => $this->author->findMutualFollows(), + default => $this->author->findFollowers() + }; + $recipientActors = array_merge($recipientActors, $this->mentions, $this->privacy->alsoVisibleTo); + $recipientActors = array_unique($recipientActors); + $instances = array_map(function (Actor $a) { + return $a->findHomeInstance(); + }, $recipientActors); + $instances = array_unique($instances); + + foreach ($instances as $instance) { + (new PushObject($this, $instance))->submit(); + } + } + public function jsonSerialize(): array { return [ 'type' => 'note', |
