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