sforkowany z mirror/friendica
Improve Api\Mastodon\Account with data from apcontact
- Original work by @annando2022.09-rc
rodzic
cf72bde93d
commit
9a0a11ed39
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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'];
|
||||
|
|
Ładowanie…
Reference in New Issue