Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
throw new NotFoundException();
} 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);
}
}
}
}
-/**
- * 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
*/
}
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
- if ($filter_user && ($status_user["id"] != $user_info["id"])) {
+ if ($filter_user && ($item["author-id"] != $user_info["id"])) {
continue;
}
- $status = api_format_item($item, $type, $status_user, $author_user, $owner_user);
+ $status = api_format_item($item, $type);
$ret[] = $status;
}
* @throws InternalServerErrorException
* @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();
-
- if (empty($status_user) || empty($author_user) || empty($owner_user)) {
- [$status_user, $author_user, $owner_user] = api_item_get_user($a, $item);
- }
+ $author_user = DI::twitterUser()->createFromContactId($item['author-id'], BaseApi::getCurrentUserID())->toArray();
+ $owner_user = DI::twitterUser()->createFromContactId($item['owner-id'], BaseApi::getCurrentUserID())->toArray();
DI::contentItem()->localize($item);
'in_reply_to_screen_name' => $in_reply_to['screen_name'],
$geo => null,
'favorited' => $item['starred'] ? true : false,
- 'user' => $status_user,
+ 'user' => $author_user,
'friendica_author' => $author_user,
'friendica_owner' => $owner_user,
'friendica_private' => $item['private'] == Item::PRIVATE,
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.
*