diff options
Diffstat (limited to 'Digitigrade/Model/Actor.php')
| -rw-r--r-- | Digitigrade/Model/Actor.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php index b4e9392..f2eecae 100644 --- a/Digitigrade/Model/Actor.php +++ b/Digitigrade/Model/Actor.php @@ -2,6 +2,7 @@ namespace Digitigrade\Model; use Digitigrade\Notification\PendingFollowActionedNotif; +use Digitigrade\Notification\UnblockNotif; use Digitigrade\Notification\UnfollowNotif; use Digitigrade\RpcException; use Digitigrade\RpcReceiver; @@ -142,6 +143,16 @@ class Actor extends PushableModel implements RpcReceiver { (new PendingFollowActionedNotif($args[0], $this, 'reject'))->processNotifications(); return; + case 'block': + $rel = BlockRelation::create($args[0], $this); + $rel->processNotifications(); + return; + + case 'unblock': + BlockRelation::findByActors($args[0], $this)->remove(); + (new UnblockNotif($args[0], $this))->processNotifications(); + return; + default: throw new \RuntimeException("behaviour for actor rpc method $method not (yet?) implemented"); } @@ -233,6 +244,31 @@ class Actor extends PushableModel implements RpcReceiver { return array_intersect($followers, $followees); } + /** + * Blocks another actor. + * @param Actor $target the actor to block + */ + public function block(self $target) { + $target->rpcCall('block', [$this]); + } + + /** + * Unblocks another actor. + * @param Actor $target the actor to unblock + */ + public function unblock(self $target) { + $target->rpcCall('unblock', [$this]); + } + + /** + * @param Actor $target the other actor + * @return boolean whether this actor blocks the target actor + */ + public function blocks(Actor $target): bool { + $relation = BlockRelation::findByActors($this, $target); + return $relation != null; + } + public function findHomeInstance(): Instance { if ($this->isLocal) { // can't do this because we don't keep track of ourself in the instance table @@ -282,6 +318,8 @@ class Actor extends PushableModel implements RpcReceiver { 'unfollow' => path_to_uri("/actor/$this->id/unfollow"), 'acceptedFollow' => path_to_uri("/actor/$this->id/acceptedFollow"), 'rejectedFollow' => path_to_uri("/actor/$this->id/rejectedFollow"), + 'block' => path_to_uri("/actor/$this->id/block"), + 'unblock' => path_to_uri("/actor/$this->id/unblock"), ] ]; } |
