From: Hypolite Petovan Date: Wed, 11 Dec 2019 13:23:28 +0000 (-0500) Subject: Improve Api\Mastodon\Account with data from apcontact X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9a0a11ed399a7f099f23285b5174ad66b750b59c;p=friendica.git Improve Api\Mastodon\Account with data from apcontact - Original work by @annando --- diff --git a/src/Api/Mastodon/Account.php b/src/Api/Mastodon/Account.php index 5d4f369155..18ab93be0c 100644 --- a/src/Api/Mastodon/Account.php +++ b/src/Api/Mastodon/Account.php @@ -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; } diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index 55bf70a954..739400eb77 100644 --- a/src/Module/Api/Mastodon/FollowRequests.php +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -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'];