aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/Actor.php
diff options
context:
space:
mode:
authorwinter2025-01-23 18:55:52 +0000
committerwinter2025-01-23 18:55:58 +0000
commitbc9c83b6c33d460a574fbeb764c23bfbe941b4c0 (patch)
tree5d9e816b56feea462d15e391544b0b13eeb47c8d /Digitigrade/Model/Actor.php
parentddccaf16f39a4bf710266edc389fcde124e7ef56 (diff)
implement blocking users
it doesn't work yet for notifications! but i think i got it in most other places
Diffstat (limited to 'Digitigrade/Model/Actor.php')
-rw-r--r--Digitigrade/Model/Actor.php38
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"),
]
];
}