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/Actor.php | |
| parent | f6a55426cac40501aa7f8e88eb7bfd318d7cd170 (diff) | |
let notes push themselves to interested parties
Diffstat (limited to 'Digitigrade/Model/Actor.php')
| -rw-r--r-- | Digitigrade/Model/Actor.php | 39 |
1 files changed, 39 insertions, 0 deletions
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', |
