From 72b07245f44c73ed41bfcca2465a9ee34426a922 Mon Sep 17 00:00:00 2001 From: winter Date: Thu, 19 Dec 2024 20:59:18 +0000 Subject: implement follow relationships (untested) does NOT implement the actual behaviour behind follows (receiving posts and such) --- routes/actor.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'routes/actor.php') 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 -- cgit v1.3