]> git.mxchange.org Git - friendica.git/commitdiff
Fix legacy API
authorMichael <heluecht@pirati.ca>
Fri, 19 Nov 2021 20:15:12 +0000 (20:15 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 19 Nov 2021 20:15:12 +0000 (20:15 +0000)
include/api.php
src/Module/Api/Friendica/Index.php
tests/legacy/ApiTest.php

index d1ff1458ed06f1cc64e49476d21c159f8ea17289..a442b1e89a3f028e2fbef59141d78c8854e879db 100644 (file)
@@ -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()]);
                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);
        }
 }
@@ -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
  */
@@ -2298,14 +2265,12 @@ function api_format_items($items, $user_info, $filter_user = false, $type = "jso
        }
 
        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;
        }
@@ -2325,13 +2290,10 @@ function api_format_items($items, $user_info, $filter_user = false, $type = "jso
  * @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);
 
@@ -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'],
                $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,
index dbe45f545fdd06c040397f62c609154437310dec..5806f2e4810adc78d4a69d7d3aff04d200f65165 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Friendica;
 
 use Friendica\DI;
 use Friendica\Module\BaseApi;
+require_once __DIR__ . '/../../../../include/api.php';
 
 /**
  * api/friendica
index 13509bf3434aac3f7d111c12ad1dbbdababb6aa2..490fac7dd521da7f1695d756c671998ccf14bbc6 100644 (file)
@@ -763,29 +763,6 @@ class ApiTest extends FixtureTest
                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.
         *