Improve Api\Mastodon\Account with data from apcontact

- Original work by @annando
2022.09-rc
Hypolite Petovan 2019-12-11 08:23:28 -05:00
rodzic cf72bde93d
commit 9a0a11ed39
2 zmienionych plików z 26 dodań i 20 usunięć

Wyświetl plik

@ -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,23 +56,24 @@ 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->locked = !empty($apcontact['manually-approve']);
$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->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'];
@ -80,6 +82,7 @@ class Account
$account->header_static = '';
// No custom emojis per account in Friendica
$account->emojis = [];
$account->bot = ($contact['contact-type'] == Contact::TYPE_NEWS);
return $account;
}

Wyświetl plik

@ -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'];