Improve Api\Mastodon\Account with data from apcontact
- Original work by @annando
This commit is contained in:
parent
cf72bde93d
commit
9a0a11ed39
|
@ -4,6 +4,7 @@ namespace Friendica\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Util\DateTimeFormat;
|
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
|
* 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
|
* @return Account
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function createFromContact(array $contact) {
|
public static function createFromContact(array $contact, array $apcontact = [])
|
||||||
|
{
|
||||||
$account = new Account();
|
$account = new Account();
|
||||||
$account->id = $contact['id'];
|
$account->id = $contact['id'];
|
||||||
$account->username = $contact['nick'];
|
$account->username = $contact['nick'];
|
||||||
$account->acct = $contact['nick'];
|
$account->acct = $contact['nick'];
|
||||||
$account->display_name = $contact['name'];
|
$account->display_name = $contact['name'];
|
||||||
$account->locked = $contact['blocked'];
|
$account->locked = !empty($apcontact['manually-approve']);
|
||||||
$account->created_at = DateTimeFormat::utc($contact['created'], DateTimeFormat::ATOM);
|
$account->created_at = DateTimeFormat::utc($contact['created'], DateTimeFormat::ATOM);
|
||||||
// No data is available from contact
|
$account->followers_count = $apcontact['followers_count'] ?? 0;
|
||||||
$account->followers_count = 0;
|
$account->following_count = $apcontact['following_count'] ?? 0;
|
||||||
$account->following_count = 0;
|
$account->statuses_count = $apcontact['statuses_count'] ?? 0;
|
||||||
$account->statuses_count = 0;
|
$account->note = BBCode::convert($contact['about'], false);
|
||||||
$account->note = BBCode::convert($contact['about']);
|
$account->url = $contact['url'];
|
||||||
$account->url = $contact['url'];
|
$account->avatar = $contact['avatar'];
|
||||||
$account->avatar = $contact['avatar'];
|
$account->avatar_static = $contact['avatar'];
|
||||||
$account->avatar_static = $contact['avatar'];
|
|
||||||
// No header picture in Friendica
|
// No header picture in Friendica
|
||||||
$account->header = '';
|
$account->header = '';
|
||||||
$account->header_static = '';
|
$account->header_static = '';
|
||||||
// No custom emojis per account in Friendica
|
// No custom emojis per account in Friendica
|
||||||
$account->emojis = [];
|
$account->emojis = [];
|
||||||
|
$account->bot = ($contact['contact-type'] == Contact::TYPE_NEWS);
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Friendica\Api\Mastodon;
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Model\APContact;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Introduction;
|
use Friendica\Model\Introduction;
|
||||||
use Friendica\Module\Base\Api;
|
use Friendica\Module\Base\Api;
|
||||||
|
@ -88,7 +89,9 @@ class FollowRequests extends Api
|
||||||
|
|
||||||
$return = [];
|
$return = [];
|
||||||
foreach ($intros as $intro) {
|
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
|
// Not ideal, the same "account" can have multiple ids depending on the context
|
||||||
$account->id = $intro['id'];
|
$account->id = $intro['id'];
|
||||||
|
|
Loading…
Reference in a new issue