<?php
/**
- * @copyright Copyright (C) 2010-2021, 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 static function rawContent()
+ public function run(HTTPException $httpException, array $request = [], bool $scopecheck = true): ResponseInterface
+ {
+ return parent::run($httpException, $request, false);
+ }
+
+ protected function rawContent(array $request = [])
+ {
+ self::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);
+ }
+
+ System::jsonExit($inbox, 'application/activity+json');
+ }
+
+ protected function post(array $request = [])
{
$postdata = Network::postdata();
$filename = 'failed-activitypub';
}
$tempfile = tempnam(System::getTempPath(), $filename);
- file_put_contents($tempfile, json_encode(['parameters' => static::$parameters, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
+ file_put_contents($tempfile, json_encode(['parameters' => $this->parameters, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
Logger::notice('Incoming message stored', ['file' => $tempfile]);
}
- if (!empty(static::$parameters['nickname'])) {
- $user = DBA::selectFirst('user', ['uid'], ['nickname' => static::$parameters['nickname']]);
+ if (!empty($this->parameters['nickname'])) {
+ $user = DBA::selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname']]);
if (!DBA::isResult($user)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}