aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/Note.php
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Model/Note.php')
-rw-r--r--Digitigrade/Model/Note.php27
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',