Fix legacy API
This commit is contained in:
parent
942001b04d
commit
d576e920d5
|
@ -221,6 +221,7 @@ function api_call(App $a, App\Arguments $args = null)
|
||||||
Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
|
Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
} catch (HTTPException $e) {
|
} catch (HTTPException $e) {
|
||||||
|
Logger::notice(API_LOG_PREFIX . 'got exception', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString(), 'error' => $e]);
|
||||||
DI::apiResponse()->error($e->getCode(), $e->getDescription(), $e->getMessage(), $type);
|
DI::apiResponse()->error($e->getCode(), $e->getDescription(), $e->getMessage(), $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,40 +283,6 @@ function api_unique_id_to_nurl($id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* return api-formatted array for item's author and owner
|
|
||||||
*
|
|
||||||
* @param App $a App
|
|
||||||
* @param array $item item from db
|
|
||||||
* @return array(array:author, array:owner)
|
|
||||||
* @throws BadRequestException
|
|
||||||
* @throws ImagickException
|
|
||||||
* @throws InternalServerErrorException
|
|
||||||
* @throws UnauthorizedException
|
|
||||||
*/
|
|
||||||
function api_item_get_user(App $a, $item)
|
|
||||||
{
|
|
||||||
if (empty($item['author-id'])) {
|
|
||||||
$item['author-id'] = Contact::getPublicIdByUserId(BaseApi::getCurrentUserID());
|
|
||||||
}
|
|
||||||
$status_user = DI::twitterUser()->createFromContactId($item['author-id'], BaseApi::getCurrentUserID())->toArray();
|
|
||||||
|
|
||||||
$author_user = $status_user;
|
|
||||||
|
|
||||||
$status_user["protected"] = isset($item['private']) && ($item['private'] == Item::PRIVATE);
|
|
||||||
|
|
||||||
if (($item['thr-parent'] ?? '') == ($item['uri'] ?? '')) {
|
|
||||||
if (empty($item['owner-id'])) {
|
|
||||||
$item['owner-id'] = Contact::getPublicIdByUserId(BaseApi::getCurrentUserID());
|
|
||||||
}
|
|
||||||
$owner_user = DI::twitterUser()->createFromContactId($item['owner-id'], BaseApi::getCurrentUserID())->toArray();
|
|
||||||
} else {
|
|
||||||
$owner_user = $author_user;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ([$status_user, $author_user, $owner_user]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TWITTER API
|
* TWITTER API
|
||||||
*/
|
*/
|
||||||
|
@ -2298,14 +2265,12 @@ function api_format_items($items, $user_info, $filter_user = false, $type = "jso
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ((array)$items as $item) {
|
foreach ((array)$items as $item) {
|
||||||
[$status_user, $author_user, $owner_user] = api_item_get_user($a, $item);
|
|
||||||
|
|
||||||
// Look if the posts are matching if they should be filtered by user id
|
// Look if the posts are matching if they should be filtered by user id
|
||||||
if ($filter_user && ($status_user["id"] != $user_info["id"])) {
|
if ($filter_user && ($item["author-id"] != $user_info["id"])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = api_format_item($item, $type, $status_user, $author_user, $owner_user);
|
$status = api_format_item($item, $type);
|
||||||
|
|
||||||
$ret[] = $status;
|
$ret[] = $status;
|
||||||
}
|
}
|
||||||
|
@ -2325,13 +2290,10 @@ function api_format_items($items, $user_info, $filter_user = false, $type = "jso
|
||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
* @throws UnauthorizedException
|
* @throws UnauthorizedException
|
||||||
*/
|
*/
|
||||||
function api_format_item($item, $type = "json", $status_user = null, $author_user = null, $owner_user = null)
|
function api_format_item($item, $type = "json")
|
||||||
{
|
{
|
||||||
$a = DI::app();
|
$author_user = DI::twitterUser()->createFromContactId($item['author-id'], BaseApi::getCurrentUserID())->toArray();
|
||||||
|
$owner_user = DI::twitterUser()->createFromContactId($item['owner-id'], BaseApi::getCurrentUserID())->toArray();
|
||||||
if (empty($status_user) || empty($author_user) || empty($owner_user)) {
|
|
||||||
[$status_user, $author_user, $owner_user] = api_item_get_user($a, $item);
|
|
||||||
}
|
|
||||||
|
|
||||||
DI::contentItem()->localize($item);
|
DI::contentItem()->localize($item);
|
||||||
|
|
||||||
|
@ -2359,7 +2321,7 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use
|
||||||
'in_reply_to_screen_name' => $in_reply_to['screen_name'],
|
'in_reply_to_screen_name' => $in_reply_to['screen_name'],
|
||||||
$geo => null,
|
$geo => null,
|
||||||
'favorited' => $item['starred'] ? true : false,
|
'favorited' => $item['starred'] ? true : false,
|
||||||
'user' => $status_user,
|
'user' => $author_user,
|
||||||
'friendica_author' => $author_user,
|
'friendica_author' => $author_user,
|
||||||
'friendica_owner' => $owner_user,
|
'friendica_owner' => $owner_user,
|
||||||
'friendica_private' => $item['private'] == Item::PRIVATE,
|
'friendica_private' => $item['private'] == Item::PRIVATE,
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Friendica;
|
||||||
|
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Module\BaseApi;
|
use Friendica\Module\BaseApi;
|
||||||
|
require_once __DIR__ . '/../../../../include/api.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* api/friendica
|
* api/friendica
|
||||||
|
|
|
@ -763,29 +763,6 @@ class ApiTest extends FixtureTest
|
||||||
self::assertSelfUser(DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
|
self::assertSelfUser(DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the api_item_get_user() function.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testApiItemGetUser()
|
|
||||||
{
|
|
||||||
$users = api_item_get_user($this->app, []);
|
|
||||||
self::assertSelfUser($users[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the api_item_get_user() function with a different item parent.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testApiItemGetUserWithDifferentParent()
|
|
||||||
{
|
|
||||||
$users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
|
|
||||||
self::assertSelfUser($users[0]);
|
|
||||||
self::assertEquals($users[0], $users[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the Arrays::walkRecursive() function.
|
* Test the Arrays::walkRecursive() function.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user