From a643888aebd195ffa3e8c9639e38bf0df412aad1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 16:13:31 +0000 Subject: [PATCH 1/9] More data for the Mastodon status class --- src/DI.php | 16 +++++ src/Factory/Api/Mastodon/Mention.php | 67 +++++++++++++++++++ src/Factory/Api/Mastodon/Status.php | 19 +++++- src/Factory/Api/Mastodon/Tag.php | 65 ++++++++++++++++++ src/Object/Api/Mastodon/Card.php | 62 +++++++++++++++++ src/Object/Api/Mastodon/Mention.php | 66 ++++++++++++++++++ src/Object/Api/Mastodon/Status.php | 31 +++++---- .../Api/Mastodon/Status/UserAttributes.php | 64 ++++++++++++++++++ src/Object/Api/Mastodon/Tag.php | 51 ++++++++++++++ 9 files changed, 426 insertions(+), 15 deletions(-) create mode 100644 src/Factory/Api/Mastodon/Mention.php create mode 100644 src/Factory/Api/Mastodon/Tag.php create mode 100644 src/Object/Api/Mastodon/Card.php create mode 100644 src/Object/Api/Mastodon/Mention.php create mode 100644 src/Object/Api/Mastodon/Status/UserAttributes.php create mode 100644 src/Object/Api/Mastodon/Tag.php diff --git a/src/DI.php b/src/DI.php index 73f9b7811..e259c271a 100644 --- a/src/DI.php +++ b/src/DI.php @@ -279,6 +279,22 @@ abstract class DI return self::$dice->create(Factory\Api\Mastodon\Status::class); } + /** + * @return Factory\Api\Mastodon\Mention + */ + public static function mstdnMention() + { + return self::$dice->create(Factory\Api\Mastodon\Mention::class); + } + + /** + * @return Factory\Api\Mastodon\Tag + */ + public static function mstdnTag() + { + return self::$dice->create(Factory\Api\Mastodon\Tag::class); + } + /** * @return Factory\Api\Twitter\User */ diff --git a/src/Factory/Api/Mastodon/Mention.php b/src/Factory/Api/Mastodon/Mention.php new file mode 100644 index 000000000..5ab82d710 --- /dev/null +++ b/src/Factory/Api/Mastodon/Mention.php @@ -0,0 +1,67 @@ +. + * + */ + +namespace Friendica\Factory\Api\Mastodon; + +use Friendica\App\BaseURL; +use Friendica\BaseFactory; +use Friendica\Model\Contact; +use Friendica\Model\Tag; +use Friendica\Network\HTTPException; +use Friendica\Repository\ProfileField; +use Psr\Log\LoggerInterface; + +class Mention extends BaseFactory +{ + /** @var BaseURL */ + protected $baseUrl; + /** @var ProfileField */ + protected $profileField; + /** @var Field */ + protected $mstdnField; + + public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField) + { + parent::__construct($logger); + + $this->baseUrl = $baseURL; + $this->profileField = $profileField; + $this->mstdnField = $mstdnField; + } + + /** + * @param int $uriId Uri-ID of the item + * @return array + * @throws HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + public function createFromUriId(int $uriId) + { + $mentions = []; + $tags = Tag::getByURIId($uriId, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION]); + foreach ($tags as $tag) { + $contact = Contact::getByURL($tag['url'], false); + $mention = new \Friendica\Object\Api\Mastodon\Mention($this->baseUrl, $tag, $contact); + $mentions[] = $mention->toArray(); + } + return $mentions; + } +} diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index c31c211a5..0069c91b3 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -23,6 +23,7 @@ namespace Friendica\Factory\Api\Mastodon; use Friendica\App\BaseURL; use Friendica\BaseFactory; +use Friendica\Content\Text\BBCode; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; @@ -68,6 +69,22 @@ class Status extends BaseFactory DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]) ); - return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts); + $userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes( + DBA::exists('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]), + DBA::exists('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]), + DBA::exists('thread', ['iid' => $item['id'], 'uid' => $item['uid'], 'ignored' => true]), + (bool)$item['starred'], + DBA::exists('user-item', ['iid' => $item['id'], 'uid' => $item['uid'], 'pinned' => true]) + ); + + $sensitive = DBA::exists('tag-view', ['uri-id' => $uriId, 'name' => 'nsfw']); + $application = new \Friendica\Object\Api\Mastodon\Application($item['app']); + $mentions = DI::mstdnMention()->createFromUriId($uriId); + $tags = DI::mstdnTag()->createFromUriId($uriId); + + $attachment = BBCode::getAttachmentData($item['body']); + $card = new \Friendica\Object\Api\Mastodon\Card($attachment); + + return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card); } } diff --git a/src/Factory/Api/Mastodon/Tag.php b/src/Factory/Api/Mastodon/Tag.php new file mode 100644 index 000000000..9b81e6d69 --- /dev/null +++ b/src/Factory/Api/Mastodon/Tag.php @@ -0,0 +1,65 @@ +. + * + */ + +namespace Friendica\Factory\Api\Mastodon; + +use Friendica\App\BaseURL; +use Friendica\BaseFactory; +use Friendica\Model\Tag as TagModel; +use Friendica\Network\HTTPException; +use Friendica\Repository\ProfileField; +use Psr\Log\LoggerInterface; + +class Tag extends BaseFactory +{ + /** @var BaseURL */ + protected $baseUrl; + /** @var ProfileField */ + protected $profileField; + /** @var Field */ + protected $mstdnField; + + public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField) + { + parent::__construct($logger); + + $this->baseUrl = $baseURL; + $this->profileField = $profileField; + $this->mstdnField = $mstdnField; + } + + /** + * @param int $uriId Uri-ID of the item + * @return array + * @throws HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + public function createFromUriId(int $uriId) + { + $hashtags = []; + $tags = TagModel::getByURIId($uriId, [TagModel::HASHTAG]); + foreach ($tags as $tag) { + $hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, $tag); + $hashtags[] = $hashtag->toArray(); + } + return $hashtags; + } +} diff --git a/src/Object/Api/Mastodon/Card.php b/src/Object/Api/Mastodon/Card.php new file mode 100644 index 000000000..990f6a6bf --- /dev/null +++ b/src/Object/Api/Mastodon/Card.php @@ -0,0 +1,62 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon; + +use Friendica\BaseEntity; +use Friendica\Content\Text\BBCode; +use Friendica\Object\Api\Mastodon\Status\Counts; +use Friendica\Object\Api\Mastodon\Status\UserAttributes; +use Friendica\Util\DateTimeFormat; + +/** + * Class Card + * + * @see https://docs.joinmastodon.org/entities/card + */ +class Card extends BaseEntity +{ + /** @var string */ + protected $url; + /** @var string */ + protected $title; + /** @var string */ + protected $description; + /** @var string */ + protected $type; + /** @var string */ + protected $image; + + /** + * Creates a status record from an item record. + * + * @param array $attachment Attachment record + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function __construct(array $attachment) + { + $this->url = $attachment['url'] ?? ''; + $this->title = $attachment['title'] ?? ''; + $this->description = $attachment['description'] ?? ''; + $this->type = $attachment['type'] ?? ''; + $this->image = $attachment['image'] ?? ''; + } +} diff --git a/src/Object/Api/Mastodon/Mention.php b/src/Object/Api/Mastodon/Mention.php new file mode 100644 index 000000000..22e623e60 --- /dev/null +++ b/src/Object/Api/Mastodon/Mention.php @@ -0,0 +1,66 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon; + +use Friendica\App\BaseURL; +use Friendica\BaseEntity; + +/** + * Class Mention + * + * @see https://docs.joinmastodon.org/entities/mention + */ +class Mention extends BaseEntity +{ + /** @var string */ + protected $id; + /** @var string */ + protected $username; + /** @var string */ + protected $url = null; + /** @var string */ + protected $acct = null; + + /** + * Creates a mention record from an tag-view record. + * + * @param BaseURL $baseUrl + * @param array $tag tag-view record + * @param array $contact contact table record + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function __construct(BaseURL $baseUrl, array $tag, array $contact) + { + $this->id = $contact['id'] ?? 0; + $this->username = $tag['name']; + $this->url = $tag['url']; + + if (!empty($contact)) { + $this->acct = + strpos($contact['url'], $baseUrl->get() . '/') === 0 ? + $contact['nick'] : + $contact['addr']; + } else { + $this->acct = ''; + } + } +} diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index aa26fa198..cc9108fc8 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -24,6 +24,7 @@ namespace Friendica\Object\Api\Mastodon; use Friendica\BaseEntity; use Friendica\Content\Text\BBCode; use Friendica\Object\Api\Mastodon\Status\Counts; +use Friendica\Object\Api\Mastodon\Status\UserAttributes; use Friendica\Util\DateTimeFormat; /** @@ -96,7 +97,7 @@ class Status extends BaseEntity * @param array $item * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function __construct(array $item, Account $account, Counts $counts) + public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card) { $this->id = (string)$item['uri-id']; $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::ATOM); @@ -106,32 +107,34 @@ class Status extends BaseEntity $this->in_reply_to_account_id = (string)$item['parent-author-id']; } - $this->sensitive = false; + $this->sensitive = $sensitive; $this->spoiler_text = $item['title']; $visibility = ['public', 'private', 'unlisted']; $this->visibility = $visibility[$item['private']]; - $this->language = null; + $languages = json_decode($item['language'], true); + $this->language = is_array($languages) ? array_key_first($languages) : null; + $this->uri = $item['uri']; $this->url = $item['plink'] ?? null; $this->replies_count = $counts->replies; $this->reblogs_count = $counts->reblogs; $this->favourites_count = $counts->favourites; - $this->favourited = false; - $this->reblogged = false; - $this->muted = false; - $this->bookmarked = false; - $this->pinned = false; + $this->favourited = $userAttributes->favourited; + $this->reblogged = $userAttributes->reblogged; + $this->muted = $userAttributes->muted; + $this->bookmarked = $userAttributes->bookmarked; + $this->pinned = $userAttributes->pinned; $this->content = BBCode::convert($item['body'], false); - $this->reblog = null; - $this->application = null; + $this->reblog = null; /// @todo + $this->application = $application->toArray(); $this->account = $account->toArray(); - $this->media_attachments = []; - $this->mentions = []; - $this->tags = []; + $this->media_attachments = []; /// @todo + $this->mentions = $mentions; + $this->tags = $tags; $this->emojis = []; - $this->card = null; + $this->card = $card->toArray(); $this->poll = null; } } diff --git a/src/Object/Api/Mastodon/Status/UserAttributes.php b/src/Object/Api/Mastodon/Status/UserAttributes.php new file mode 100644 index 000000000..f33cc5117 --- /dev/null +++ b/src/Object/Api/Mastodon/Status/UserAttributes.php @@ -0,0 +1,64 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon\Status; + +/** + * Class UserAttributes + * + * @see https://docs.joinmastodon.org/entities/status + */ +class UserAttributes +{ + /** @var bool */ + protected $favourited; + /** @var bool */ + protected $reblogged; + /** @var bool */ + protected $muted; + /** @var bool */ + protected $bookmarked; + /** @var bool */ + protected $pinned; + + /** + * Creates a authorized user attributes object + * + * @param bool $favourited + * @param bool $reblogged + * @param bool $muted + * @param bool $bookmarked + * @param bool $pinned + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function __construct(bool $favourited, bool $reblogged, bool $muted, bool $bookmarked, bool $pinned) + { + $this->favourited = $favourited; + $this->reblogged = $reblogged; + $this->muted = $muted; + $this->bookmarked = $bookmarked; + $this->pinned = $pinned; + } + + public function __get($name) { + return $this->$name; + } +} diff --git a/src/Object/Api/Mastodon/Tag.php b/src/Object/Api/Mastodon/Tag.php new file mode 100644 index 000000000..0cb910703 --- /dev/null +++ b/src/Object/Api/Mastodon/Tag.php @@ -0,0 +1,51 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon; + +use Friendica\App\BaseURL; +use Friendica\BaseEntity; + +/** + * Class Tag + * + * @see https://docs.joinmastodon.org/entities/tag + */ +class Tag extends BaseEntity +{ + /** @var string */ + protected $name; + /** @var string */ + protected $url = null; + + /** + * Creates a hashtag record from an tag-view record. + * + * @param BaseURL $baseUrl + * @param array $tag tag-view record + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function __construct(BaseURL $baseUrl, array $tag) + { + $this->name = $tag['name']; + $this->url = $baseUrl . '/search?tag=' . urlencode($tag['name']); + } +} From efcd76d3a71e8c7fada5ba25a2ddc52b0c8a7213 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 16:26:47 +0000 Subject: [PATCH 2/9] Spaces to tabs --- src/Object/Api/Mastodon/Status/Counts.php | 4 ++-- src/Object/Api/Mastodon/Status/UserAttributes.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Object/Api/Mastodon/Status/Counts.php b/src/Object/Api/Mastodon/Status/Counts.php index 2c446c36c..a0af517df 100644 --- a/src/Object/Api/Mastodon/Status/Counts.php +++ b/src/Object/Api/Mastodon/Status/Counts.php @@ -51,6 +51,6 @@ class Counts } public function __get($name) { - return $this->$name; - } + return $this->$name; + } } diff --git a/src/Object/Api/Mastodon/Status/UserAttributes.php b/src/Object/Api/Mastodon/Status/UserAttributes.php index f33cc5117..c1201c931 100644 --- a/src/Object/Api/Mastodon/Status/UserAttributes.php +++ b/src/Object/Api/Mastodon/Status/UserAttributes.php @@ -59,6 +59,6 @@ class UserAttributes } public function __get($name) { - return $this->$name; - } + return $this->$name; + } } From 13b14bff91734bcf3578570d9f464aa3056e55cd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 16:55:05 +0000 Subject: [PATCH 3/9] Return 'null' on empty card --- src/Object/Api/Mastodon/Card.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Object/Api/Mastodon/Card.php b/src/Object/Api/Mastodon/Card.php index 990f6a6bf..46aea3c28 100644 --- a/src/Object/Api/Mastodon/Card.php +++ b/src/Object/Api/Mastodon/Card.php @@ -59,4 +59,18 @@ class Card extends BaseEntity $this->type = $attachment['type'] ?? ''; $this->image = $attachment['image'] ?? ''; } + + /** + * Returns the current entity as an array + * + * @return array + */ + public function toArray() + { + if (empty($this->url)) { + return null; + } + + return parent::toArray(); + } } From 72efcc8169ef7d7b78cfb9846cfe3de2c61c875a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 16:59:38 +0000 Subject: [PATCH 4/9] "locked" is boolean --- src/Object/Api/Mastodon/Account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Object/Api/Mastodon/Account.php b/src/Object/Api/Mastodon/Account.php index 5bd2743b9..f6e66941a 100644 --- a/src/Object/Api/Mastodon/Account.php +++ b/src/Object/Api/Mastodon/Account.php @@ -99,7 +99,7 @@ class Account extends BaseEntity $publicContact['nick'] : $publicContact['addr']; $this->display_name = $publicContact['name']; - $this->locked = $publicContact['manually-approve'] ?? !empty($apcontact['manually-approve']); + $this->locked = (bool)$publicContact['manually-approve'] ?? !empty($apcontact['manually-approve']); $this->bot = ($publicContact['contact-type'] == Contact::TYPE_NEWS); $this->discoverable = !$publicContact['unsearchable']; $this->group = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY); From 825189e8e908a027c4292f4f8dd5d2e84f9ac810 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 17:42:42 +0000 Subject: [PATCH 5/9] Don't publish some fields --- src/Object/Api/Mastodon/Account.php | 16 ++++++++++++++++ src/Object/Api/Mastodon/Status.php | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Object/Api/Mastodon/Account.php b/src/Object/Api/Mastodon/Account.php index f6e66941a..587c6ce6d 100644 --- a/src/Object/Api/Mastodon/Account.php +++ b/src/Object/Api/Mastodon/Account.php @@ -132,4 +132,20 @@ class Account extends BaseEntity $this->fields = $fields->getArrayCopy(); } + + /** + * Returns the current entity as an array + * + * @return array + */ + public function toArray() + { + $account = parent::toArray(); + + if (empty($account['moved'])) { + unset($account['moved']); + } + + return $account; + } } diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index cc9108fc8..2d2beb583 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -137,4 +137,24 @@ class Status extends BaseEntity $this->card = $card->toArray(); $this->poll = null; } + + /** + * Returns the current entity as an array + * + * @return array + */ + public function toArray() + { + $status = parent::toArray(); + + if (!$status['pinned']) { + unset($status['pinned']); + } + + if (empty($status['application']['name'])) { + unset($status['application']); + } + + return $status; + } } From 463f8ee3f32f724b233316adb79c49e8225daa5d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 17:59:28 +0000 Subject: [PATCH 6/9] Use lowercase for tags --- src/Object/Api/Mastodon/Tag.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Object/Api/Mastodon/Tag.php b/src/Object/Api/Mastodon/Tag.php index 0cb910703..1e74eae00 100644 --- a/src/Object/Api/Mastodon/Tag.php +++ b/src/Object/Api/Mastodon/Tag.php @@ -45,7 +45,7 @@ class Tag extends BaseEntity */ public function __construct(BaseURL $baseUrl, array $tag) { - $this->name = $tag['name']; - $this->url = $baseUrl . '/search?tag=' . urlencode($tag['name']); + $this->name = strtolower($tag['name']); + $this->url = $baseUrl . '/search?tag=' . urlencode($this->name); } } From 319ceeda3ba994fe76d22262fef1f40ec8d779af Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 18:21:18 +0000 Subject: [PATCH 7/9] Publish the profile fields --- src/Factory/Api/Mastodon/Account.php | 5 ++++- src/Factory/Api/Mastodon/Field.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Factory/Api/Mastodon/Account.php b/src/Factory/Api/Mastodon/Account.php index b0c31c09b..a7aa64245 100644 --- a/src/Factory/Api/Mastodon/Account.php +++ b/src/Factory/Api/Mastodon/Account.php @@ -69,7 +69,10 @@ class Account extends BaseFactory $apcontact = APContact::getByURL($publicContact['url'], false); - return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, new Fields(), $apcontact, $userContact); + $profileFields = $this->profileField->select(['uid' => $uid, 'psid' => PermissionSet::PUBLIC]); + $fields = $this->mstdnField->createFromProfileFields($profileFields); + + return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact, $userContact); } /** diff --git a/src/Factory/Api/Mastodon/Field.php b/src/Factory/Api/Mastodon/Field.php index fdf0a4ef6..d357ee2fa 100644 --- a/src/Factory/Api/Mastodon/Field.php +++ b/src/Factory/Api/Mastodon/Field.php @@ -37,7 +37,7 @@ class Field extends BaseFactory */ public function createFromProfileField(ProfileField $profileField) { - return new \Friendica\Api\Entity\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, BBCode::ACTIVITYPUB)); + return new \Friendica\Object\Api\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, BBCode::ACTIVITYPUB)); } /** From d8d96e6e61325abab94f11eefce93185ff0605d2 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 20:32:45 +0000 Subject: [PATCH 8/9] Display the user fields for the admin account --- src/Factory/Api/Mastodon/Account.php | 8 ++++++-- src/Object/Api/Mastodon/Instance.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Factory/Api/Mastodon/Account.php b/src/Factory/Api/Mastodon/Account.php index a7aa64245..d7e94819e 100644 --- a/src/Factory/Api/Mastodon/Account.php +++ b/src/Factory/Api/Mastodon/Account.php @@ -69,8 +69,12 @@ class Account extends BaseFactory $apcontact = APContact::getByURL($publicContact['url'], false); - $profileFields = $this->profileField->select(['uid' => $uid, 'psid' => PermissionSet::PUBLIC]); - $fields = $this->mstdnField->createFromProfileFields($profileFields); + if (!empty($userContact['self'])) { + $profileFields = $this->profileField->select(['uid' => $uid, 'psid' => PermissionSet::PUBLIC]); + $fields = $this->mstdnField->createFromProfileFields($profileFields); + } else { + $fields = new Fields(); + } return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact, $userContact); } diff --git a/src/Object/Api/Mastodon/Instance.php b/src/Object/Api/Mastodon/Instance.php index 6105a8bee..c52e59f8a 100644 --- a/src/Object/Api/Mastodon/Instance.php +++ b/src/Object/Api/Mastodon/Instance.php @@ -93,8 +93,8 @@ class Instance extends BaseEntity $adminList = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email'))); $administrator = User::getByEmail($adminList[0], ['nickname']); if (!empty($administrator)) { - $adminContact = DBA::selectFirst('contact', ['id'], ['nick' => $administrator['nickname'], 'self' => true]); - $instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id']); + $adminContact = DBA::selectFirst('contact', ['id', 'uid'], ['nick' => $administrator['nickname'], 'self' => true]); + $instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id'], $adminContact['uid']); } } From 44a4b66539da5a701f0da50a0d5f9da6192ab5a1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Oct 2020 20:40:25 +0000 Subject: [PATCH 9/9] Improved self contact detection --- src/Factory/Api/Mastodon/Account.php | 5 +++-- src/Object/Api/Mastodon/Instance.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Factory/Api/Mastodon/Account.php b/src/Factory/Api/Mastodon/Account.php index d7e94819e..a2bd550a7 100644 --- a/src/Factory/Api/Mastodon/Account.php +++ b/src/Factory/Api/Mastodon/Account.php @@ -69,8 +69,9 @@ class Account extends BaseFactory $apcontact = APContact::getByURL($publicContact['url'], false); - if (!empty($userContact['self'])) { - $profileFields = $this->profileField->select(['uid' => $uid, 'psid' => PermissionSet::PUBLIC]); + $self_contact = Contact::selectFirst(['uid'], ['nurl' => $publicContact['nurl'], 'self' => true]); + if (!empty($self_contact['uid'])) { + $profileFields = $this->profileField->select(['uid' => $self_contact['uid'], 'psid' => PermissionSet::PUBLIC]); $fields = $this->mstdnField->createFromProfileFields($profileFields); } else { $fields = new Fields(); diff --git a/src/Object/Api/Mastodon/Instance.php b/src/Object/Api/Mastodon/Instance.php index c52e59f8a..6105a8bee 100644 --- a/src/Object/Api/Mastodon/Instance.php +++ b/src/Object/Api/Mastodon/Instance.php @@ -93,8 +93,8 @@ class Instance extends BaseEntity $adminList = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email'))); $administrator = User::getByEmail($adminList[0], ['nickname']); if (!empty($administrator)) { - $adminContact = DBA::selectFirst('contact', ['id', 'uid'], ['nick' => $administrator['nickname'], 'self' => true]); - $instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id'], $adminContact['uid']); + $adminContact = DBA::selectFirst('contact', ['id'], ['nick' => $administrator['nickname'], 'self' => true]); + $instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id']); } }