]> git.mxchange.org Git - friendica.git/commitdiff
Correct value of Mastodon API Account acct field for local users
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 25 Dec 2019 10:58:54 +0000 (05:58 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 30 Dec 2019 11:12:51 +0000 (06:12 -0500)
src/Api/Mastodon/Account.php
src/Api/Mastodon/Instance.php
src/Module/Api/Mastodon/FollowRequests.php

index 0a86be7e7b92f43e107a059523493aafccc5b1c0..077b02f82d2bfbc682944628b23a21ddf14f4d55 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Api\Mastodon;
 
+use Friendica\App\BaseURL;
 use Friendica\Content\Text\BBCode;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
@@ -62,17 +63,21 @@ class Account
        /**
         * Creates an account record from a public contact record. Expects all contact table fields to be set.
         *
-        * @param array $publicContact Full contact table record with uid = 0
-        * @param array $apcontact     Optional full apcontact table record
+        * @param BaseURL $baseUrl
+        * @param array   $publicContact Full contact table record with uid = 0
+        * @param array   $apcontact     Optional full apcontact table record
         * @return Account
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function create(array $publicContact, array $apcontact = [])
+       public static function create(BaseURL $baseUrl, array $publicContact, array $apcontact = [])
        {
                $account = new Account();
                $account->id              = $publicContact['id'];
                $account->username        = $publicContact['nick'];
-               $account->acct            = $publicContact['addr'];
+               $account->acct            =
+                       strpos($publicContact['url'], $baseUrl->get() . '/') === 0 ?
+                       $publicContact['nick'] :
+                       $publicContact['addr'];
                $account->display_name    = $publicContact['name'];
                $account->locked          = !empty($apcontact['manually-approve']);
                $account->created_at      = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::ATOM);
index 6d1dfb73379b3031a7ebe1e400e47bf728cc1e6f..6652641b493e4477df3e1268797cf710c027c9c3 100644 (file)
@@ -79,7 +79,7 @@ class Instance
                        if (!empty($administrator)) {
                                $adminContact = DBA::selectFirst('contact', [], ['nick' => $administrator['nickname'], 'self' => true]);
                                $apcontact = APContact::getByURL($adminContact['url'], false);
-                               $instance->contact_account = Account::create($adminContact, $apcontact);
+                               $instance->contact_account = Account::create($baseUrl, $adminContact, $apcontact);
                        }
                }
 
index 304f78767f3202514c7a77e7f4b56436d1031200..e1e70577b846a57978b021853e9c9677c1b36327 100644 (file)
@@ -26,6 +26,15 @@ class FollowRequests extends Api
                }
        }
 
+       /**
+        * @param array $parameters
+        * @throws HTTPException\BadRequestException
+        * @throws HTTPException\ForbiddenException
+        * @throws HTTPException\NotFoundException
+        * @throws HTTPException\UnauthorizedException
+        * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#accept-follow
+        * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#reject-follow
+        */
        public static function post(array $parameters = [])
        {
                parent::post($parameters);
@@ -58,7 +67,8 @@ class FollowRequests extends Api
        /**
         * @param array $parameters
         * @throws HTTPException\InternalServerErrorException
-        * @see https://docs.joinmastodon.org/api/rest/follow-requests/#get-api-v1-follow-requests
+        * @throws \ImagickException
+        * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#pending-follows
         */
        public static function rawContent(array $parameters = [])
        {
@@ -66,6 +76,8 @@ class FollowRequests extends Api
                $max_id = $_GET['max_id'] ?? null;
                $limit = intval($_GET['limit'] ?? 40);
 
+               $baseUrl = DI::baseUrl();
+
                if (isset($since_id) && isset($max_id)) {
                        $condition = ['`uid` = ? AND NOT `ignore` AND `id` > ? AND `id` < ?', self::$current_user_id, $since_id, $max_id];
                } elseif (isset($since_id)) {
@@ -94,7 +106,7 @@ class FollowRequests extends Api
 
                        $publicContact = Contact::getById($cdata['public']);
                        $apcontact = APContact::getByURL($publicContact['url'], false);
-                       $account = Mastodon\Account::create($publicContact, $apcontact);
+                       $account = Mastodon\Account::create($baseUrl, $publicContact, $apcontact);
 
                        // Not ideal, the same "account" can have multiple ids depending on the context
                        $account->id = $intro['id'];
@@ -107,13 +119,11 @@ class FollowRequests extends Api
                        $base_query['limit'] = $limit;
                }
 
-               $BaseURL = DI::baseUrl();
-
                $links = [];
                if ($count > $limit) {
-                       $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['max_id' => $intros[count($intros) - 1]['id']]) . '>; rel="next"';
+                       $links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['max_id' => $intros[count($intros) - 1]['id']]) . '>; rel="next"';
                }
-               $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['since_id' => $intros[0]['id']]) . '>; rel="prev"';
+               $links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['since_id' => $intros[0]['id']]) . '>; rel="prev"';
 
                header('Link: ' . implode(', ', $links));