Merge pull request #13530 from MrPetovan/bug/json-error-factory-error

Move jsonError out of Factory\Api\Mastodon\Error
This commit is contained in:
Michael Vogel 2023-10-14 19:35:49 +02:00 committed by GitHub
commit c98a0a99a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
186 changed files with 463 additions and 461 deletions

View File

@ -21,81 +21,53 @@
namespace Friendica\Factory\Api\Mastodon;
use Friendica\App\Arguments;
use Friendica\BaseFactory;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Psr\Log\LoggerInterface;
/** @todo A Factory shouldn't return something to the frontpage, it's for creating content, not showing it */
class Error extends BaseFactory
{
/** @var Arguments */
private $args;
/** @var string[] The $_SERVER array */
private $server;
/** @var L10n */
private $l10n;
public function __construct(LoggerInterface $logger, Arguments $args, L10n $l10n, array $server)
public function __construct(LoggerInterface $logger, L10n $l10n)
{
parent::__construct($logger);
$this->args = $args;
$this->server = $server;
$this->l10n = $l10n;
}
private function logError(int $errorno, string $error)
{
$this->logger->info('API Error', ['no' => $errorno, 'error' => $error, 'method' => $this->args->getMethod(), 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
}
public function RecordNotFound()
public function RecordNotFound(): \Friendica\Object\Api\Mastodon\Error
{
$error = $this->l10n->t('Record not found');
$error_description = '';
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(404, $error);
$this->jsonError(404, $errorObj->toArray());
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
}
public function UnprocessableEntity(string $error = '')
public function UnprocessableEntity(string $error = ''): \Friendica\Object\Api\Mastodon\Error
{
$error = $error ?: $this->l10n->t('Unprocessable Entity');
$error_description = '';
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(422, $error);
$this->jsonError(422, $errorObj->toArray());
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
}
public function Unauthorized(string $error = '', string $error_description = '')
public function Unauthorized(string $error = '', string $error_description = ''): \Friendica\Object\Api\Mastodon\Error
{
$error = $error ?: $this->l10n->t('Unauthorized');
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(401, $error);
$this->jsonError(401, $errorObj->toArray());
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
}
public function Forbidden(string $error = '')
public function Forbidden(string $error = ''): \Friendica\Object\Api\Mastodon\Error
{
$error = $error ?: $this->l10n->t('Token is not authorized with a valid user or is missing a required scope');
$error_description = '';
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(403, $error);
$this->jsonError(403, $errorObj->toArray());
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
}
public function InternalError(string $error = '')
public function InternalError(string $error = ''): \Friendica\Object\Api\Mastodon\Error
{
$error = $error ?: $this->l10n->t('Internal Server Error');
$error_description = '';
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(500, $error);
$this->jsonError(500, $errorObj->toArray());
return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
}
}

View File

@ -359,7 +359,7 @@ class Status extends BaseFactory
{
$item = ActivityPub\Transmitter::getItemArrayFromMail($id, true);
if (empty($item)) {
$this->mstdnErrorFactory->RecordNotFound();
throw new HTTPException\NotFoundException('Mail record not found with id: ' . $id);
}
$account = $this->mstdnAccountFactory->createFromContactId($item['author-id']);

View File

@ -45,7 +45,7 @@ class Inbox extends BaseApi
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$page = $request['page'] ?? null;

View File

@ -58,7 +58,7 @@ class Outbox extends BaseApi
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$postdata = Network::postdata();

View File

@ -38,7 +38,7 @@ class Whoami extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$owner = User::getOwnerDataById($uid);

View File

@ -44,7 +44,7 @@ class Activity extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -34,7 +34,7 @@ class Create extends BaseApi
{
protected function post(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
// params

View File

@ -34,7 +34,7 @@ class Delete extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -35,7 +35,7 @@ class Show extends BaseApi
{
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$this->checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
$type = $this->getRequestValue($this->parameters, 'extension', 'json');

View File

@ -35,7 +35,7 @@ class Update extends BaseApi
{
protected function post(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
// params

View File

@ -44,9 +44,9 @@ class Search extends BaseApi
/** @var DirectMessage */
private $directMessage;
public function __construct(DirectMessage $directMessage, Database $dba, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
public function __construct(DirectMessage $directMessage, Database $dba, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->dba = $dba;
$this->directMessage = $directMessage;
@ -54,7 +54,7 @@ class Search extends BaseApi
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -32,7 +32,7 @@ class Setseen extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -40,7 +40,7 @@ class Create extends BaseApi
{
protected function post(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
// params

View File

@ -35,7 +35,7 @@ class Delete extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -34,7 +34,7 @@ class Index extends BaseApi
{
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -33,7 +33,7 @@ class Notification extends BaseApi
{
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$Notifies = DI::notify()->selectAllForUser($uid, 50);

View File

@ -40,7 +40,7 @@ class Seen extends BaseApi
{
protected function post(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
if (DI::args()->getArgc() !== 4) {

View File

@ -37,16 +37,16 @@ class Photo extends BaseApi
private $friendicaPhoto;
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->friendicaPhoto = $friendicaPhoto;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$this->checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
$type = $this->getRequestValue($this->parameters, 'extension', 'json');

View File

@ -41,16 +41,16 @@ class Create extends BaseApi
private $friendicaPhoto;
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->friendicaPhoto = $friendicaPhoto;
}
protected function post(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
$type = $this->getRequestValue($this->parameters, 'extension', 'json');

View File

@ -43,16 +43,16 @@ class Lists extends BaseApi
private $friendicaPhoto;
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->friendicaPhoto = $friendicaPhoto;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$this->checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
$type = $this->getRequestValue($this->parameters, 'extension', 'json');

View File

@ -41,16 +41,16 @@ class Update extends BaseApi
private $friendicaPhoto;
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->friendicaPhoto = $friendicaPhoto;
}
protected function post(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
$type = $this->getRequestValue($this->parameters, 'extension', 'json');

View File

@ -36,7 +36,7 @@ class Delete extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -33,7 +33,7 @@ class Index extends BaseApi
{
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$albums = Photo::getAlbums($uid);

View File

@ -43,16 +43,16 @@ class Show extends BaseApi
private $friendicaPhoto;
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
public function __construct(FriendicaPhoto $friendicaPhoto, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->friendicaPhoto = $friendicaPhoto;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$this->checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
$request = $this->getRequest([

View File

@ -34,7 +34,7 @@ class Update extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -36,7 +36,7 @@ class Show extends BaseApi
{
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
// retrieve general information about profiles for user

View File

@ -35,16 +35,16 @@ class Dislike extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'dislike', $uid);

View File

@ -41,12 +41,12 @@ class DislikedBy extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::DISLIKE, 'deleted' => false]);

View File

@ -35,16 +35,16 @@ class Undislike extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'undislike', $uid);

View File

@ -37,7 +37,7 @@ class Conversation extends BaseApi
{
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$this->checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
// params

View File

@ -40,20 +40,20 @@ class Accounts extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id']) && empty($this->parameters['name'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!empty($this->parameters['id'])) {
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} else {
$contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]);
if (!empty($contact['id'])) {
$id = $contact['id'];
} elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}

View File

@ -34,11 +34,11 @@ class Block extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$this->checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setBlocked($this->parameters['id'], $uid, true);

View File

@ -34,7 +34,7 @@ class FeaturedTags extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$this->jsonExit([]);
}

View File

@ -33,11 +33,11 @@ class Follow extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$this->checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([

View File

@ -37,16 +37,16 @@ class Followers extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([

View File

@ -37,16 +37,16 @@ class Following extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([

View File

@ -34,7 +34,7 @@ class IdentityProofs extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$this->jsonExit([]);
}

View File

@ -37,16 +37,16 @@ class Lists extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$lists = [];

View File

@ -33,11 +33,11 @@ class Mute extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$this->checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setIgnored($this->parameters['id'], $uid, true);

View File

@ -34,11 +34,11 @@ class Note extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
@ -47,7 +47,7 @@ class Note extends BaseApi
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
if (empty($cdata['user'])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);

View File

@ -36,7 +36,7 @@ class Relationships extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -44,7 +44,7 @@ class Relationships extends BaseApi
], $request);
if (empty($request['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!is_array($request['id'])) {

View File

@ -38,7 +38,7 @@ class Search extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -47,12 +47,12 @@ class Statuses extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([

View File

@ -33,11 +33,11 @@ class Unblock extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$this->checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setBlocked($this->parameters['id'], $uid, false);

View File

@ -33,16 +33,16 @@ class Unfollow extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$this->checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
if (empty($cdata['user'])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$contact = Contact::getById($cdata['user']);

View File

@ -33,11 +33,11 @@ class Unmute extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$this->checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setIgnored($this->parameters['id'], $uid, false);

View File

@ -36,7 +36,7 @@ class UpdateCredentials extends BaseApi
{
protected function patch(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$owner = User::getOwnerDataById($uid);

View File

@ -37,7 +37,7 @@ class VerifyCredentials extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$self = User::getOwnerDataById($uid);

View File

@ -34,7 +34,7 @@ class Announcements extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
// @todo Possibly use the message from the pageheader addon for this
$this->jsonExit([]);

View File

@ -70,7 +70,7 @@ class Apps extends BaseApi
}
if (empty($request['client_name']) || empty($request['redirect_uris'])) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Missing parameters'));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
}
$client_id = bin2hex(random_bytes(32));
@ -92,7 +92,7 @@ class Apps extends BaseApi
}
if (!DBA::insert('application', $fields)) {
DI::mstdnError()->InternalError();
$this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());

View File

@ -32,11 +32,11 @@ class VerifyCredentials extends BaseApi
{
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$application = self::getCurrentApplication();
if (empty($application['id'])) {
DI::mstdnError()->Unauthorized();
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
}
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id']));

View File

@ -36,7 +36,7 @@ class Blocks extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -39,7 +39,7 @@ class Bookmarks extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -25,6 +25,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\NotFoundException;
/**
* @see https://docs.joinmastodon.org/methods/timelines/conversations/
@ -33,11 +34,11 @@ class Conversations extends BaseApi
{
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]);
@ -51,7 +52,7 @@ class Conversations extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -83,9 +84,13 @@ class Conversations extends BaseApi
$conversations = [];
while ($conv = DBA::fetch($convs)) {
self::setBoundaries($conv['id']);
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']);
try {
while ($conv = DBA::fetch($convs)) {
self::setBoundaries($conv['id']);
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']);
}
} catch (NotFoundException $e) {
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
DBA::close($convs);

View File

@ -25,6 +25,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\NotFoundException;
/**
* @see https://docs.joinmastodon.org/methods/timelines/conversations/
@ -33,15 +34,19 @@ class Read extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]);
$this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray());
try {
$this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray());
} catch (NotFoundException $e) {
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}
}

View File

@ -41,7 +41,7 @@ class Favourited extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -33,7 +33,7 @@ class Filters extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$this->response->unsupported(Router::POST, $request);
}
@ -43,7 +43,7 @@ class Filters extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$this->jsonExit([]);
}

View File

@ -44,7 +44,7 @@ class FollowRequests extends BaseApi
*/
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$this->checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
@ -89,7 +89,7 @@ class FollowRequests extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -32,7 +32,7 @@ class FollowedTags extends BaseApi
{
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -43,9 +43,9 @@ class Instance extends BaseApi
/** @var IManageConfigValues */
private $config;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = [])
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->database = $database;
$this->config = $config;

View File

@ -54,6 +54,7 @@ class InstanceV2 extends BaseApi
private $contactHeader;
public function __construct(
\Friendica\Factory\Api\Mastodon\Error $errorFactory,
App $app,
L10n $l10n,
App\BaseURL $baseUrl,
@ -66,7 +67,7 @@ class InstanceV2 extends BaseApi
array $server,
array $parameters = []
) {
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->database = $database;
$this->config = $config;

View File

@ -33,19 +33,19 @@ class Lists extends BaseApi
{
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!Circle::exists($this->parameters['id'], $uid)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Circle::remove($this->parameters['id'])) {
DI::mstdnError()->InternalError();
$this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit([]);
@ -53,7 +53,7 @@ class Lists extends BaseApi
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -61,14 +61,14 @@ class Lists extends BaseApi
], $request);
if (empty($request['title'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Circle::create($uid, $request['title']);
$id = Circle::getIdByName($uid, $request['title']);
if (!$id) {
DI::mstdnError()->InternalError();
$this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit(DI::mstdnList()->createFromCircleId($id));
@ -82,7 +82,7 @@ class Lists extends BaseApi
], $request);
if (empty($request['title']) || empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Circle::update($this->parameters['id'], $request['title']);
@ -93,7 +93,7 @@ class Lists extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
@ -106,7 +106,7 @@ class Lists extends BaseApi
$id = $this->parameters['id'];
if (!Circle::exists($id, $uid)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$lists = DI::mstdnList()->createFromCircleId($id);
}

View File

@ -36,14 +36,14 @@ class Accounts extends BaseApi
{
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$request = $this->getRequest([
'account_ids' => [], // Array of account IDs to remove from the list
], $request);
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
return Circle::removeMembers($this->parameters['id'], $request['account_ids']);
@ -51,14 +51,14 @@ class Accounts extends BaseApi
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$request = $this->getRequest([
'account_ids' => [], // Array of account IDs to add to the list
], $request);
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Circle::addMembers($this->parameters['id'], $request['account_ids']);
@ -69,16 +69,16 @@ class Accounts extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([

View File

@ -34,7 +34,7 @@ class Markers extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();
@ -48,7 +48,7 @@ class Markers extends BaseApi
}
if (empty($timeline) || empty($last_read_id) || empty($application['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline];
@ -69,7 +69,7 @@ class Markers extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();

View File

@ -35,7 +35,7 @@ class Media extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -48,12 +48,12 @@ class Media extends BaseApi
Logger::info('Photo post', ['request' => $request, 'files' => $_FILES]);
if (empty($_FILES['file'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$media = Photo::upload($uid, $_FILES['file'], '', null, null, '', '', $request['description']);
if (empty($media)) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Logger::info('Uploaded photo', ['media' => $media]);
@ -63,7 +63,7 @@ class Media extends BaseApi
public function put(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -74,17 +74,17 @@ class Media extends BaseApi
], $request);
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]);
if (empty($photo['resource-id'])) {
$media = Post\Media::getById($this->parameters['id']);
if (empty($media['uri-id'])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Media::updateById(['description' => $request['description']], $this->parameters['id']);
$this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id']));
@ -100,16 +100,16 @@ class Media extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!Photo::exists(['id' => $id, 'uid' => $uid])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id));

View File

@ -36,16 +36,16 @@ class Mutes extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([

View File

@ -41,7 +41,7 @@ class Notifications extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) {
@ -50,7 +50,7 @@ class Notifications extends BaseApi
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
$this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes()));
} catch (\Exception $e) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}

View File

@ -32,7 +32,7 @@ class Clear extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
DI::notification()->setAllDismissedForUser($uid);

View File

@ -34,11 +34,11 @@ class Dismiss extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$condition = ['id' => $this->parameters['id']];

View File

@ -39,7 +39,7 @@ class Polls extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid));

View File

@ -36,7 +36,7 @@ class Preferences extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$user = User::getById($uid, ['language', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);

View File

@ -39,20 +39,17 @@ class PushSubscription extends BaseApi
{
/** @var SubscriptionFactory */
protected $subscriptionFac;
/** @var Error */
protected $errorFac;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, SubscriptionFactory $subscriptionFac, Error $errorFac, array $server, array $parameters = [])
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, SubscriptionFactory $subscriptionFac, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->subscriptionFac = $subscriptionFac;
$this->errorFac = $errorFac;
}
protected function post(array $request = []): void
{
self::checkAllowedScope(self::SCOPE_PUSH);
$this->checkAllowedScope(self::SCOPE_PUSH);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();
@ -86,7 +83,7 @@ class PushSubscription extends BaseApi
public function put(array $request = []): void
{
self::checkAllowedScope(self::SCOPE_PUSH);
$this->checkAllowedScope(self::SCOPE_PUSH);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();
@ -97,7 +94,7 @@ class PushSubscription extends BaseApi
$subscription = Subscription::select($application['id'], $uid, ['id']);
if (empty($subscription)) {
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
$this->errorFac->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$fields = [
@ -125,7 +122,7 @@ class PushSubscription extends BaseApi
protected function delete(array $request = []): void
{
self::checkAllowedScope(self::SCOPE_PUSH);
$this->checkAllowedScope(self::SCOPE_PUSH);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();
@ -142,13 +139,13 @@ class PushSubscription extends BaseApi
protected function rawContent(array $request = []): void
{
self::checkAllowedScope(self::SCOPE_PUSH);
$this->checkAllowedScope(self::SCOPE_PUSH);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();
if (!Subscription::exists($application['id'], $uid)) {
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
$this->errorFac->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]);

View File

@ -41,9 +41,9 @@ class Reports extends BaseApi
/** @var \Friendica\Moderation\Repository\Report */
private $reportRepo;
public function __construct(\Friendica\Moderation\Repository\Report $reportRepo, \Friendica\Moderation\Factory\Report $reportFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
public function __construct(\Friendica\Moderation\Repository\Report $reportRepo, \Friendica\Moderation\Factory\Report $reportFactory, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->reportFactory = $reportFactory;
$this->reportRepo = $reportRepo;
@ -51,7 +51,7 @@ class Reports extends BaseApi
public function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$request = $this->getRequest([
'account_id' => '', // ID of the account to report

View File

@ -35,7 +35,7 @@ class ScheduledStatuses extends BaseApi
{
public function put(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$this->response->unsupported(Router::PUT, $request);
@ -43,15 +43,15 @@ class ScheduledStatuses extends BaseApi
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Delayed::deleteById($this->parameters['id']);
@ -64,7 +64,7 @@ class ScheduledStatuses extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (isset($this->parameters['id'])) {

View File

@ -43,7 +43,7 @@ class Search extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -60,7 +60,7 @@ class Search extends BaseApi
], $request);
if (empty($request['q'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$limit = min($request['limit'], 40);

View File

@ -49,7 +49,7 @@ class Statuses extends BaseApi
{
public function put(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -164,7 +164,7 @@ class Statuses extends BaseApi
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -297,7 +297,7 @@ class Statuses extends BaseApi
$item['uri'] = Item::newURI($item['guid']);
$id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at']));
if (empty($id)) {
DI::mstdnError()->InternalError();
$this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray());
}
@ -310,25 +310,25 @@ class Statuses extends BaseApi
}
}
DI::mstdnError()->InternalError();
$this->logAndJsonError(500, $this->errorFactory->InternalError());
}
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]);
if (empty($item['id'])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Item::markForDeletionById($item['id'])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$this->jsonExit([]);
@ -342,7 +342,7 @@ class Statuses extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false));

View File

@ -35,20 +35,20 @@ class Bookmark extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be bookmarked'));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
}
if ($item['uid'] == 0) {
@ -56,10 +56,10 @@ class Bookmark extends BaseApi
if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} else {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}

View File

@ -40,7 +40,7 @@ class Card extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {

View File

@ -41,7 +41,7 @@ class Context extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
@ -116,7 +116,7 @@ class Context extends BaseApi
}
DBA::close($posts);
} else {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}

View File

@ -35,16 +35,16 @@ class Favourite extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'like', $uid);

View File

@ -41,11 +41,11 @@ class FavouritedBy extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]);

View File

@ -35,20 +35,20 @@ class Mute extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted'));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted')));
}
Post\ThreadUser::setIgnored($item['uri-id'], $uid, true);

View File

@ -34,16 +34,16 @@ class Pin extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid);

View File

@ -38,22 +38,25 @@ class Reblog extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['network'] == Protocol::DIASPORA) {
Diaspora::performReshare($this->parameters['id'], $uid);
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])));
$this->logAndJsonError(
422,
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])))
);
} else {
Item::performActivity($item['id'], 'announce', $uid);
}

View File

@ -41,11 +41,11 @@ class RebloggedBy extends BaseApi
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);

View File

@ -37,11 +37,11 @@ class Source extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];

View File

@ -35,20 +35,20 @@ class Unbookmark extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unbookmarked'));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
}
if ($item['uid'] == 0) {
@ -56,10 +56,10 @@ class Unbookmark extends BaseApi
if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} else {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}

View File

@ -35,16 +35,16 @@ class Unfavourite extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'unlike', $uid);

View File

@ -35,20 +35,20 @@ class Unmute extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted'));
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted')));
}
Post\ThreadUser::setIgnored($item['uri-id'], $uid, false);

View File

@ -34,16 +34,16 @@ class Unpin extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid);

View File

@ -37,29 +37,32 @@ class Unreblog extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['network'] == Protocol::DIASPORA) {
$item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'body' => '', 'origin' => true, 'uid' => $uid]);
if (empty($item['id'])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Item::markForDeletionById($item['id'])) {
DI::mstdnError()->RecordNotFound();
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])));
$this->logAndJsonError(
422,
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])))
);
} else {
Item::performActivity($item['id'], 'unannounce', $uid);
}

View File

@ -36,7 +36,7 @@ class Suggestions extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -36,11 +36,11 @@ class Tags extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$tag = ltrim($this->parameters['hashtag'], '#');

View File

@ -33,11 +33,11 @@ class Follow extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$fields = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];

View File

@ -33,11 +33,11 @@ class Unfollow extends BaseApi
{
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];

View File

@ -26,6 +26,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\NotFoundException;
/**
* @see https://docs.joinmastodon.org/methods/timelines/
@ -37,7 +38,7 @@ class Direct extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([
@ -76,9 +77,13 @@ class Direct extends BaseApi
$statuses = [];
while ($mail = DBA::fetch($mails)) {
self::setBoundaries($mail['uri-id']);
$statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']);
try {
while ($mail = DBA::fetch($mails)) {
self::setBoundaries($mail['uri-id']);
$statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']);
}
} catch (NotFoundException $e) {
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!empty($request['min_id'])) {

View File

@ -41,7 +41,7 @@ class Home extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = $this->getRequest([

View File

@ -41,11 +41,11 @@ class ListTimeline extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([

View File

@ -41,11 +41,11 @@ class Tag extends BaseApi
*/
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
DI::mstdnError()->UnprocessableEntity();
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
/**

View File

@ -34,7 +34,7 @@ class UpdateProfile extends BaseApi
{
protected function post(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$this->checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
$api_user = DI::twitterUser()->createFromUserId($uid, true)->toArray();

Some files were not shown because too many files have changed in this diff Show More