]> git.mxchange.org Git - friendica.git/commitdiff
Improve Api\Mastodon\Account with data from apcontact
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Dec 2019 13:23:28 +0000 (08:23 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Dec 2019 13:25:45 +0000 (08:25 -0500)
- Original work by @annando

src/Api/Mastodon/Account.php
src/Module/Api/Mastodon/FollowRequests.php

index 5d4f369155eae1e37e1cf9407ef73c79fef97acf..18ab93be0c5a387f08bbe3bf74e0b060a8431d99 100644 (file)
@@ -4,6 +4,7 @@ namespace Friendica\Api\Mastodon;
 
 use Friendica\Content\Text\BBCode;
 use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Util\DateTimeFormat;
 
 /**
@@ -55,31 +56,33 @@ class Account
        /**
         * Creates an account record from a contact record. Expects all contact table fields to be set
         *
-        * @param array $contact
+        * @param array $contact   Full contact table record
+        * @param array $apcontact Full apcontact table record
         * @return Account
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function createFromContact(array $contact) {
+       public static function createFromContact(array $contact, array $apcontact = [])
+       {
                $account = new Account();
-               $account->id = $contact['id'];
-               $account->username = $contact['nick'];
-               $account->acct = $contact['nick'];
-               $account->display_name = $contact['name'];
-               $account->locked = $contact['blocked'];
-               $account->created_at = DateTimeFormat::utc($contact['created'], DateTimeFormat::ATOM);
-               // No data is available from contact
-               $account->followers_count = 0;
-               $account->following_count = 0;
-               $account->statuses_count = 0;
-               $account->note = BBCode::convert($contact['about']);
-               $account->url = $contact['url'];
-               $account->avatar = $contact['avatar'];
-               $account->avatar_static = $contact['avatar'];
+               $account->id              = $contact['id'];
+               $account->username        = $contact['nick'];
+               $account->acct            = $contact['nick'];
+               $account->display_name    = $contact['name'];
+               $account->locked          = !empty($apcontact['manually-approve']);
+               $account->created_at      = DateTimeFormat::utc($contact['created'], DateTimeFormat::ATOM);
+               $account->followers_count = $apcontact['followers_count'] ?? 0;
+               $account->following_count = $apcontact['following_count'] ?? 0;
+               $account->statuses_count  = $apcontact['statuses_count'] ?? 0;
+               $account->note            = BBCode::convert($contact['about'], false);
+               $account->url             = $contact['url'];
+               $account->avatar          = $contact['avatar'];
+               $account->avatar_static   = $contact['avatar'];
                // No header picture in Friendica
-               $account->header = '';
-               $account->header_static = '';
+               $account->header          = '';
+               $account->header_static   = '';
                // No custom emojis per account in Friendica
-               $account->emojis = [];
+               $account->emojis          = [];
+               $account->bot             = ($contact['contact-type'] == Contact::TYPE_NEWS);
 
                return $account;
        }
index 55bf70a9549b7153cc247c8b723d4d02b38385ff..739400eb77c54634414af4f1e3c5caefbec6776d 100644 (file)
@@ -6,6 +6,7 @@ use Friendica\Api\Mastodon;
 use Friendica\App\BaseURL;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Model\Introduction;
 use Friendica\Module\Base\Api;
@@ -88,7 +89,9 @@ class FollowRequests extends Api
 
                $return = [];
                foreach ($intros as $intro) {
-                       $account = Mastodon\Account::createFromContact(Contact::getById($intro['contact-id']));
+                       $contact = Contact::getById($intro['contact-id']);
+                       $apcontact = APContact::getByURL($contact['url'], false);
+                       $account = Mastodon\Account::createFromContact($contact, $apcontact);
 
                        // Not ideal, the same "account" can have multiple ids depending on the context
                        $account->id = $intro['id'];