From df051a7524a93f96bfc69924c202a51286517ce2 Mon Sep 17 00:00:00 2001 From: winter Date: Thu, 19 Dec 2024 22:59:40 +0000 Subject: let notes push themselves to interested parties --- Digitigrade/Model/Actor.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Digitigrade/Model/Actor.php') diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php index e419ef6..89f4d50 100644 --- a/Digitigrade/Model/Actor.php +++ b/Digitigrade/Model/Actor.php @@ -145,6 +145,45 @@ class Actor extends PushableModel implements RpcReceiver { $target->rpcCall('unfollow', [$this]); } + /** + * @return Actor[] a list of actors that follow this actor (does not include pending follows) + */ + public function findFollowers(): array { + $relations = FollowRelation::findAllWithObject($this); + $relations = array_filter($relations, function (FollowRelation $rel) { + return $rel->status == FollowRelationStatus::ACTIVE; + }); + return array_map(function (FollowRelation $rel) { + return $rel->subject; + }, $relations); + } + + /** + * @return Actor[] a list of actors that are followed by this actor (does not include pending follows) + */ + public function findFollowees(): array { + $relations = FollowRelation::findAllWithSubject($this); + $relations = array_filter($relations, function (FollowRelation $rel) { + return $rel->status == FollowRelationStatus::ACTIVE; + }); + return array_map(function (FollowRelation $rel) { + return $rel->object; + }, $relations); + } + + /** + * @return Actor[] a list of actors that both follow and are followed by this actor + */ + public function findMutualFollows(): array { + $followers = $this->findFollowers(); + $followees = $this->findFollowees(); + return array_intersect($followers, $followees); + } + + public function findHomeInstance(): Instance { + return Instance::findByHostname(hostname_from_uri($this->uri)); + } + public function jsonSerialize(): array { return [ 'type' => 'actor', -- cgit v1.3