]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/ActivityPub/Inbox.php
Use the post language for the language detection / config for quality
[friendica.git] / src / Module / ActivityPub / Inbox.php
index a9858d94c8d2f77bb1f513708f121db8d421f654..ee9d098da4620f44088513022357dbd139299c2c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module\ActivityPub;
 
-use Friendica\BaseModule;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\User;
+use Friendica\Module\BaseApi;
+use Friendica\Module\Special\HTTPException;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\Network;
+use Psr\Http\Message\ResponseInterface;
 
 /**
  * ActivityPub Inbox
  */
-class Inbox extends BaseModule
+class Inbox extends BaseApi
 {
+       public function run(HTTPException $httpException, array $request = [], bool $scopecheck = true): ResponseInterface
+       {
+               return parent::run($httpException, $request, false);
+       }
+
        protected function rawContent(array $request = [])
+       {
+               $this->checkAllowedScope(self::SCOPE_READ);
+               $uid  = self::getCurrentUserID();
+               $page = $request['page'] ?? null;
+
+               if (empty($page) && empty($request['max_id'])) {
+                       $page = 1;
+               }
+
+               if (!empty($this->parameters['nickname'])) {
+                       $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();
+                       }
+                       $inbox = ActivityPub\ClientToServer::getInbox($uid, $page, $request['max_id'] ?? null);
+               } else {
+                       $inbox = ActivityPub\ClientToServer::getPublicInbox($uid, $page, $request['max_id'] ?? null);
+               }
+
+               $this->jsonExit($inbox, 'application/activity+json');
+       }
+
+       protected function post(array $request = [])
        {
                $postdata = Network::postdata();