Compare commits

...

29 commits

Author SHA1 Message Date
Michael Vogel
e0d4646c18
Merge pull request #13314 from MrPetovan/bug/13311-removeme-delegate
Add safeguards to user self-removal feature
2023-10-14 20:53:09 +02:00
Hypolite Petovan
7ca25b7297 Updated main translation file after adding strings 2023-10-14 14:25:20 -04:00
Hypolite Petovan
b29a68d467 Add exception when authentication returns different user id than logged in in Settings\RemoveMe 2023-10-14 14:15:42 -04:00
Hypolite Petovan
1f7b6a63bb Throw exception when user has delegates in User::remove 2023-10-14 14:15:41 -04:00
Hypolite Petovan
3a42849759 Add current user's hovercard to removeme page
- Extract Hovercard generation to Content\Widget
2023-10-14 14:15:41 -04:00
Hypolite Petovan
e6855d3125 Refactor Delegation modules
- Remove dependency on DI
- Group translation labels in template variables
- Reformat tempate code
2023-10-14 14:15:40 -04:00
Michael Vogel
c98a0a99a6
Merge pull request #13530 from MrPetovan/bug/json-error-factory-error
Move jsonError out of Factory\Api\Mastodon\Error
2023-10-14 19:35:49 +02:00
Hypolite Petovan
a0da13cf6b
Merge pull request #13384 from annando/smilies
Posts without text or only with emojis are now always accepted in the language check
2023-10-14 12:46:49 -04:00
Michael Vogel
8bf4408e64
Merge pull request #13536 from tobiasd/20231014-ru
updated RU translations
2023-10-14 09:43:39 +02:00
Tobias Diekershoff
bf5e2facb4 updated RU translations 2023-10-14 09:19:30 +02:00
Michael
e558a83783 Improved Emoji detection 2023-10-13 21:55:15 +00:00
Michael
d1eb1ec0f4 Use "IntlChar" for the emoji detection 2023-10-12 21:23:08 +00:00
Michael
19529e2aa1 Merge remote-tracking branch 'upstream/2023.09-rc' into smilies 2023-10-12 20:49:20 +00:00
Hypolite Petovan
5d428ac8af Add newly required constructor parameter to BaseApi-related tests 2023-10-11 10:17:32 -04:00
Hypolite Petovan
1b9ec3a214 Rename BaseApi->logErrorAndJsonExit to logAndJsonError to better match the functionality
- Also it's shorter and we're paying by the character
2023-10-11 09:44:03 -04:00
Hypolite Petovan
eb583330df Remove obsolete Factory\Api\Mastodon\Error->logError method and related dependencies 2023-10-11 09:44:03 -04:00
Hypolite Petovan
0a91484fa0 Move jsonError out of Factory\Api\Mastodon\Error->InternalError 2023-10-11 09:44:03 -04:00
Hypolite Petovan
696c56b6be Move jsonError out of Factory\Api\Mastodon\Error->Forbidden 2023-10-11 09:44:03 -04:00
Hypolite Petovan
6a2ca1a6b6 Move jsonError out of Factory\Api\Mastodon\Error->Unauthorized 2023-10-11 09:44:03 -04:00
Hypolite Petovan
7486ebdc10 Move jsonError out of Factory\Api\Mastodon\Error->UnprocessableEntity 2023-10-11 09:44:03 -04:00
Hypolite Petovan
7f846f153d Move jsonError out of Factory\Api\Mastodon\Error->RecordNotFound 2023-10-11 09:44:02 -04:00
Hypolite Petovan
9e71610711 Make BaseApi->checkAllowedScope into an object method
- It isn't called from static contexts anymore
2023-10-11 09:43:57 -04:00
Hypolite Petovan
f70a64891c Add Factory\Api\Mastodon\Error dependency to BaseApi
- Copy Factory\Api\Mastodon\Error->logError functionality to BaseApi
2023-10-11 09:43:54 -04:00
Hypolite Petovan
64b5f93a6a Add FIXME
- Current implementation is failing tests with emojis including the zero-width-joiner character, encoded on 3 bytes only.
2023-08-29 22:17:48 -04:00
Hypolite Petovan
059a111282 Add unit tests for Smilies::isEmojiPost
- Current implementation is failing tests with emojis including the zero-width-joiner character, encoded on 3 bytes only.
2023-08-29 22:16:09 -04:00
Michael Vogel
6ed440718d
Update src/Content/Smilies.php
Co-authored-by: Hypolite Petovan <hypolite@mrpetovan.com>
2023-08-29 04:59:27 +02:00
Michael
7ee07535f5 Move "html_entity_decode" 2023-08-28 20:53:31 +00:00
Michael
9066a6133c New function to replace blank characters 2023-08-28 20:24:20 +00:00
Michael
4dbb7dd3da Posts without text or only with emojis are now always accepted in the language check 2023-08-28 15:37:20 +00:00
204 changed files with 1326 additions and 1062 deletions

View file

@ -285,4 +285,33 @@ class Smilies
return str_replace($matches[0], $t, $matches[0]);
}
/**
* Checks if the body doesn't contain any alphanumeric characters
*
* @param string $body Possibly-HTML post body
* @return boolean
*/
public static function isEmojiPost(string $body): bool
{
// Strips all whitespace
$conv = preg_replace('#\s#u', '', html_entity_decode($body));
if (empty($conv)) {
return false;
}
if (!class_exists('IntlChar')) {
// Most Emojis are 4 byte Unicode characters, so this is a good workaround, when IntlChar does not exist on the system
return strlen($conv) / mb_strlen($conv) == 4;
}
for ($i = 0; $i < mb_strlen($conv); $i++) {
$character = mb_substr($conv, $i, 1);
if (\IntlChar::isalnum($character) || \IntlChar::ispunct($character) || \IntlChar::isgraph($character) && (strlen($character) <= 2)) {
return false;
}
}
return true;
}
}

View file

@ -1791,13 +1791,9 @@ class BBCode
$text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $text);
}
if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA)) {
$conv = html_entity_decode(str_replace([' ', "\n", "\r"], '', $text));
// Emojis are always 4 byte Unicode characters
if (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4)) {
if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA) && Smilies::isEmojiPost($text)) {
$text = '<span style="font-size: xx-large; line-height: normal;">' . $text . '</span>';
}
}
// Handle mentions and hashtag links
if ($simple_html == self::DIASPORA) {

View file

@ -0,0 +1,70 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Content\Widget;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
class Hovercard
{
/**
* @param array $contact
* @param int $localUid Used to show user actions
* @return string
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\ServiceUnavailableException
* @throws \ImagickException
*/
public static function getHTML(array $contact, int $localUid = 0): string
{
if ($localUid) {
$actions = Contact::photoMenu($contact, $localUid);
} else {
$actions = [];
}
// Move the contact data to the profile array so we can deliver it to
$tpl = Renderer::getMarkupTemplate('hovercard.tpl');
return Renderer::replaceMacros($tpl, [
'$profile' => [
'name' => $contact['name'],
'nick' => $contact['nick'],
'addr' => $contact['addr'] ?: $contact['url'],
'thumb' => Contact::getThumb($contact),
'url' => Contact::magicLinkByContact($contact),
'nurl' => $contact['nurl'],
'location' => $contact['location'],
'about' => $contact['about'],
'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
'tags' => $contact['keywords'],
'bd' => $contact['bd'] <= DBA::NULL_DATE ? '' : $contact['bd'],
'account_type' => Contact::getAccountType($contact['contact-type']),
'contact_type' => $contact['contact-type'],
'actions' => $actions,
'self' => $contact['self'],
],
]);
}
}

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

@ -37,11 +37,10 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
use Friendica\Network\HTTPException;
use Friendica\Object\Image;
use Friendica\Protocol\Delivery;
use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
@ -1638,16 +1637,24 @@ class User
* @param int $uid user to remove
* @return bool
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\NotFoundException
*/
public static function remove(int $uid): bool
{
if (empty($uid)) {
return false;
throw new \InvalidArgumentException('uid needs to be greater than 0');
}
Logger::notice('Removing user', ['user' => $uid]);
$user = DBA::selectFirst('user', [], ['uid' => $uid]);
$user = self::getById($uid);
if (!$user) {
throw new HTTPException\NotFoundException('User not found with uid: ' . $uid);
}
if (DBA::exists('user', ['parent-uid' => $uid])) {
throw new \RuntimeException(DI::l10n()->t("User with delegates can't be removed, please remove delegate users first"));
}
Hook::callAll('remove_user', $user);

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,10 +84,14 @@ class Conversations extends BaseApi
$conversations = [];
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]);
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,10 +77,14 @@ class Direct extends BaseApi
$statuses = [];
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'])) {
$statuses = array_reverse($statuses);

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