]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/ActivityPub/Outbox.php
Merge pull request #12946 from friendica/api-permission
[friendica.git] / src / Module / ActivityPub / Outbox.php
index a8a02172767d4464489e2dce0892fb63a6b00172..492971bba073e27f068ba56569cb6c071ee935f2 100644 (file)
@@ -26,6 +26,7 @@ use Friendica\Model\User;
 use Friendica\Module\BaseApi;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\HTTPSignature;
+use Friendica\Util\Network;
 
 /**
  * ActivityPub Outbox
@@ -50,9 +51,34 @@ class Outbox extends BaseApi
                        $page = 1;
                }
 
-               $requester = HTTPSignature::getSigner('', $_SERVER);
-               $outbox = ActivityPub\Transmitter::getOutbox($owner, $page, $request['max_id'] ?? null, $requester);
+               $outbox = ActivityPub\ClientToServer::getOutbox($owner, $uid, $page, $request['max_id'] ?? null, HTTPSignature::getSigner('', $_SERVER));
 
                System::jsonExit($outbox, 'application/activity+json');
        }
+
+       protected function post(array $request = [])
+       {
+               self::checkAllowedScope(self::SCOPE_WRITE);
+               $uid      = self::getCurrentUserID();
+               $postdata = Network::postdata();
+
+               if (empty($postdata) || empty($this->parameters['nickname'])) {
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
+               }
+
+               $owner = User::getOwnerDataByNick($this->parameters['nickname']);
+               if (empty($owner)) {
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
+               }
+               if ($owner['uid'] != $uid) {
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
+               }
+
+               $activity = json_decode($postdata, true);
+               if (empty($activity)) {
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
+               }
+
+               System::jsonExit(ActivityPub\ClientToServer::processActivity($activity, $uid, self::getCurrentApplication() ?? []));
+       }
 }