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.php58
1 files changed, 36 insertions, 22 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php
index 89f4d50..07f24ec 100644
--- a/Digitigrade/Model/Actor.php
+++ b/Digitigrade/Model/Actor.php
@@ -97,38 +97,42 @@ class Actor extends PushableModel implements RpcReceiver {
}
public function rpcCall(string $method, array $args) {
+ // $args = [Actor $actingAs]
+ if (!$this->isLocal) {
+ // trigger the same action on the remote server
+ $endpoint = $this->endpoints->{$method} ?? null;
+ if (!isset($endpoint)) {
+ throw new RpcException("Actor `$this->uri` has no $method endpoint");
+ }
+ $result = send_request_authenticated($endpoint, method: 'POST', actingAs: $args[0]);
+ if (!str_contains($result->headers[0], ' 20')) {
+ throw new RpcException('remote call did not indicate success: ' . $result->headers[0]);
+ }
+ }
+
+ // the actual logic
switch ($method) {
- case 'follow': // $this is the target, $args[0] is the initiator
+ case 'follow':
$status = $this->requestToFollow ? FollowRelationStatus::PENDING : FollowRelationStatus::ACTIVE;
- if (!$this->isLocal) {
- $endpoint = $this->endpoints->follow ?? null;
- if (!isset($endpoint, $this->endpoints->unfollow)) {
- throw new RpcException("Actor `$this->uri` has no (un)follow endpoint");
- }
- $result = send_request_authenticated($endpoint, method: 'POST', actingAs: $args[0]);
- if (!str_contains($result->headers[0], ' 20')) {
- throw new RpcException('remote call did not indicate success: ' . $result->headers[0]);
- }
- }
FollowRelation::create($args[0], $this, $status);
return $status;
case 'unfollow':
- if (!$this->isLocal) {
- $endpoint = $this->endpoints->unfollow ?? null;
- if (!isset($endpoint, $this->endpoints->follow)) {
- throw new RpcException("Actor `$this->uri` has no (un)follow endpoint");
- }
- $result = send_request_authenticated($endpoint, method: 'POST', actingAs: $args[0]);
- if (!str_contains($result->headers[0], ' 20')) {
- throw new RpcException('remote call did not indicate success: ' . $result->headers[0]);
- }
- }
FollowRelation::findByActors($args[0], $this)->remove();
return;
+ case 'acceptedFollow':
+ $rel = FollowRelation::findByActors($this, $args[0]);
+ $rel->status = FollowRelationStatus::ACTIVE;
+ $rel->save();
+ return;
+
+ case 'rejectedFollow':
+ FollowRelation::findByActors($this, $args[0])->remove();
+ return;
+
default:
- throw new \RuntimeException("Actor rpc method $method not (yet?) implemented");
+ throw new \RuntimeException("behaviour for actor rpc method $method not (yet?) implemented");
}
}
@@ -145,6 +149,14 @@ class Actor extends PushableModel implements RpcReceiver {
$target->rpcCall('unfollow', [$this]);
}
+ public function acceptPendingFollowFrom(self $initiator) {
+ $initiator->rpcCall('acceptedFollow', [$this]);
+ }
+
+ public function rejectPendingFollowFrom(self $initiator) {
+ $initiator->rpcCall('rejectedFollow', [$this]);
+ }
+
/**
* @return Actor[] a list of actors that follow this actor (does not include pending follows)
*/
@@ -203,6 +215,8 @@ class Actor extends PushableModel implements RpcReceiver {
'fullFeed' => path_to_uri("/user/$this->handle/fullFeed"),
'follow' => path_to_uri("/user/$this->handle/follow"),
'unfollow' => path_to_uri("/user/$this->handle/unfollow"),
+ 'acceptedFollow' => path_to_uri("/user/$this->handle/acceptedFollow"),
+ 'rejectedFollow' => path_to_uri("/user/$this->handle/rejectedFollow"),
]
];
}