mirror of
https://github.com/friendica/friendica
synced 2025-04-25 07:50:10 +00:00
Merge branch 'develop' into refactoring-of-app-class
This commit is contained in:
commit
a24a65de2f
561 changed files with 64963 additions and 61342 deletions
|
@ -7,10 +7,8 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -29,15 +27,6 @@ class Block extends BaseApi
|
|||
|
||||
Contact\User::setBlocked($this->parameters['id'], $uid, true);
|
||||
|
||||
$ucid = Contact::getUserContactId($this->parameters['id'], $uid);
|
||||
if ($ucid) {
|
||||
$contact = Contact::getById($ucid);
|
||||
if (!empty($contact)) {
|
||||
// Mastodon-expected behavior: relationship is severed on block
|
||||
Contact::terminateFriendship($contact);
|
||||
}
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,28 +59,34 @@ class Apps extends BaseApi
|
|||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
|
||||
}
|
||||
|
||||
$client_id = bin2hex(random_bytes(32));
|
||||
$client_secret = bin2hex(random_bytes(32));
|
||||
|
||||
$fields = ['client_id' => $client_id, 'client_secret' => $client_secret, 'name' => $request['client_name'], 'redirect_uri' => $request['redirect_uris']];
|
||||
$fields = ['name' => $request['client_name'], 'redirect_uri' => $request['redirect_uris']];
|
||||
|
||||
if (!empty($request['scopes'])) {
|
||||
$fields['scopes'] = $request['scopes'];
|
||||
}
|
||||
|
||||
$fields['read'] = (stripos($request['scopes'], self::SCOPE_READ) !== false);
|
||||
$fields['write'] = (stripos($request['scopes'], self::SCOPE_WRITE) !== false);
|
||||
$fields['follow'] = (stripos($request['scopes'], self::SCOPE_FOLLOW) !== false);
|
||||
$fields['push'] = (stripos($request['scopes'], self::SCOPE_PUSH) !== false);
|
||||
|
||||
if (!empty($request['website'])) {
|
||||
$fields['website'] = $request['website'];
|
||||
}
|
||||
|
||||
$application = DBA::selectFirst('application', ['id'], $fields);
|
||||
if (!empty($application['id'])) {
|
||||
$this->logger->debug('Found existing application', ['request' => $request, 'id' => $application['id']]);
|
||||
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id'])->toArray());
|
||||
}
|
||||
|
||||
$fields['read'] = (stripos($request['scopes'], self::SCOPE_READ) !== false);
|
||||
$fields['write'] = (stripos($request['scopes'], self::SCOPE_WRITE) !== false);
|
||||
$fields['follow'] = (stripos($request['scopes'], self::SCOPE_FOLLOW) !== false);
|
||||
$fields['push'] = (stripos($request['scopes'], self::SCOPE_PUSH) !== false);
|
||||
$fields['client_id'] = bin2hex(random_bytes(32));
|
||||
$fields['client_secret'] = bin2hex(random_bytes(32));
|
||||
|
||||
if (!DBA::insert('application', $fields)) {
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
$this->logger->debug('Create new application', ['request' => $request, 'id' => DBA::lastInsertId()]);
|
||||
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,38 +42,37 @@ class Media extends BaseApi
|
|||
|
||||
$type = Post\Media::getType($request['file']['type']);
|
||||
|
||||
if (in_array($type, [Post\Media::IMAGE, Post\Media::UNKNOWN])) {
|
||||
if (in_array($type, [Post\Media::IMAGE, Post\Media::UNKNOWN, Post\Media::APPLICATION])) {
|
||||
$media = Photo::upload($uid, $request['file'], '', null, null, '', '', $request['description']);
|
||||
if (empty($media)) {
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
if (!empty($media)) {
|
||||
Logger::info('Uploaded photo', ['media' => $media]);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
|
||||
} elseif ($type == Post\Media::IMAGE) {
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
|
||||
}
|
||||
|
||||
Logger::info('Uploaded photo', ['media' => $media]);
|
||||
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
|
||||
} else {
|
||||
$tempFileName = $request['file']['tmp_name'];
|
||||
$fileName = basename($request['file']['name']);
|
||||
$fileSize = intval($request['file']['size']);
|
||||
$maxFileSize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maxfilesize'));
|
||||
|
||||
if ($fileSize <= 0) {
|
||||
Logger::notice('Filesize is invalid', ['size' => $fileSize, 'request' => $request]);
|
||||
@unlink($tempFileName);
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if ($maxFileSize && $fileSize > $maxFileSize) {
|
||||
Logger::notice('Filesize is too large', ['size' => $fileSize, 'max' => $maxFileSize, 'request' => $request]);
|
||||
@unlink($tempFileName);
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = Attach::storeFile($tempFileName, self::getCurrentUserID(), $fileName, $request['file']['type'], '<' . Contact::getPublicIdByUserId(self::getCurrentUserID()) . '>');
|
||||
@unlink($tempFileName);
|
||||
Logger::info('Uploaded media', ['id' => $id]);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromAttach($id));
|
||||
}
|
||||
|
||||
$tempFileName = $request['file']['tmp_name'];
|
||||
$fileName = basename($request['file']['name']);
|
||||
$fileSize = intval($request['file']['size']);
|
||||
$maxFileSize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maxfilesize'));
|
||||
|
||||
if ($fileSize <= 0) {
|
||||
Logger::notice('Filesize is invalid', ['size' => $fileSize, 'request' => $request]);
|
||||
@unlink($tempFileName);
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if ($maxFileSize && $fileSize > $maxFileSize) {
|
||||
Logger::notice('Filesize is too large', ['size' => $fileSize, 'max' => $maxFileSize, 'request' => $request]);
|
||||
@unlink($tempFileName);
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = Attach::storeFile($tempFileName, self::getCurrentUserID(), $fileName, $request['file']['type'], '<' . Contact::getPublicIdByUserId(self::getCurrentUserID()) . '>');
|
||||
@unlink($tempFileName);
|
||||
Logger::info('Uploaded media', ['id' => $id]);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromAttach($id));
|
||||
}
|
||||
|
||||
public function put(array $request = [])
|
||||
|
|
|
@ -66,7 +66,7 @@ class Context extends BaseApi
|
|||
if (!empty($uid) && !$request['show_all']) {
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
["NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored`))", $uid]
|
||||
["NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored` OR `is-blocked`))", $uid]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class Direct extends BaseApi
|
|||
if (!empty($uid)) {
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
["NOT `parent-author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored`) AND `cid` = `parent-author-id`)", $uid]
|
||||
["NOT `parent-author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored` OR `is-blocked`) AND `cid` = `parent-author-id`)", $uid]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,8 @@ class Home extends BaseApi
|
|||
$condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
|
||||
}
|
||||
|
||||
$condition = DBA::mergeConditions($condition, ["NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` IN (`parent-owner-id`, `parent-author-id`) AND (`blocked` OR `ignored` OR `is-blocked` OR `channel-only`))", $uid]);
|
||||
|
||||
$items = Post::selectTimelineForUser($uid, ['uri-id'], $condition, $params);
|
||||
|
||||
$display_quotes = self::appSupportsQuotes();
|
||||
|
|
|
@ -93,7 +93,7 @@ class Tag extends BaseApi
|
|||
if (!empty($uid)) {
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
["NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored`) AND `cid` = `author-id`)", $uid]
|
||||
["NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored` OR `is-blocked`) AND `cid` = `author-id`)", $uid]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue