aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/actor.php
diff options
context:
space:
mode:
authorwinter2024-12-19 20:59:18 +0000
committerwinter2024-12-19 20:59:18 +0000
commit72b07245f44c73ed41bfcca2465a9ee34426a922 (patch)
tree57372703100ad792c95c665a568aabe8a763bfdf /routes/actor.php
parent1e070a7a0097c74f8ac30678d39267f19c76f9f6 (diff)
implement follow relationships (untested)
does NOT implement the actual behaviour behind follows (receiving posts and such)
Diffstat (limited to 'routes/actor.php')
-rw-r--r--routes/actor.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/routes/actor.php b/routes/actor.php
index 51c0e1a..30b28c5 100644
--- a/routes/actor.php
+++ b/routes/actor.php
@@ -2,6 +2,7 @@
use Digitigrade\HttpResponseStatus\NotFound;
use Digitigrade\HttpResponseStatus\TemporaryRedirect;
+use Digitigrade\HttpResponseStatus\Unauthorized;
use Digitigrade\Model\Actor;
use Digitigrade\Model\Note;
use Digitigrade\Router;
@@ -43,4 +44,28 @@ Router::getInstance()->mount('/user/:handle/fullFeed', function (array $args) {
'previousPage' => null,
'items' => $notes
]);
+});
+
+Router::getInstance()->mount('/user/:handle/follow', function (array $args) {
+ $target = Actor::findLocalByHandle($args['handle']);
+ if ($target == null) {
+ throw new NotFound();
+ }
+ $initiator = Actor::findByRequestHeaders();
+ if ($initiator == null) {
+ throw new Unauthorized('please authenticate yourself on behalf of the initiating actor');
+ }
+ $initiator->follow($target);
+});
+
+Router::getInstance()->mount('/user/:handle/unfollow', function (array $args) {
+ $target = Actor::findLocalByHandle($args['handle']);
+ if ($target == null) {
+ throw new NotFound();
+ }
+ $initiator = Actor::findByRequestHeaders();
+ if ($initiator == null) {
+ throw new Unauthorized('please authenticate yourself on behalf of the initiating actor');
+ }
+ $initiator->unfollow($target);
}); \ No newline at end of file