From 40ee96512a3073e0d0063d5202b3551bd27abe4b Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 17 Feb 2023 17:42:00 -0500 Subject: [PATCH 1/6] Add extension to Mastodon Status object for Friendica-specific things - first entry is the title --- src/Object/Api/Mastodon/Status.php | 4 ++ .../Mastodon/Status/FriendicaExtension.php | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/Object/Api/Mastodon/Status/FriendicaExtension.php diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index e3f322778..bcbe1deeb 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -25,6 +25,7 @@ use Friendica\BaseDataTransferObject; use Friendica\Content\Text\BBCode; use Friendica\Model\Item; use Friendica\Object\Api\Mastodon\Status\Counts; +use Friendica\Object\Api\Mastodon\Status\FriendicaExtension; use Friendica\Object\Api\Mastodon\Status\UserAttributes; use Friendica\Util\DateTimeFormat; @@ -95,6 +96,8 @@ class Status extends BaseDataTransferObject protected $card = null; /** @var Poll|null */ protected $poll = null; + /** @var FriendicaExtension|null */ + protected $friendica = null; /** * Creates a status record from an item record. @@ -148,6 +151,7 @@ class Status extends BaseDataTransferObject $this->emojis = []; $this->card = $card->toArray() ?: null; $this->poll = $poll; + $this->friendica = new FriendicaExtension($item['title']); } /** diff --git a/src/Object/Api/Mastodon/Status/FriendicaExtension.php b/src/Object/Api/Mastodon/Status/FriendicaExtension.php new file mode 100644 index 000000000..1a63f7606 --- /dev/null +++ b/src/Object/Api/Mastodon/Status/FriendicaExtension.php @@ -0,0 +1,53 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon\Status; + +use Friendica\BaseDataTransferObject; + +/** + * Class FriendicaExtension + * + * Additional fields on Mastodon Statuses for storing Friendica specific data + * + * @see https://docs.joinmastodon.org/entities/status + */ +class FriendicaExtension extends BaseDataTransferObject +{ + /** @var string */ + protected $title; + + /** + * Creates a status count object + * + * @param string $title + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function __construct(string $title) + { + $this->title = $title; + } + + public function __get($name) + { + return $this->$name; + } +} From f10821f915dda47aa5cc06b8a7bd46510d86d7cd Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 17 Feb 2023 17:42:55 -0500 Subject: [PATCH 2/6] Add friendica->title input to Mastodon Status POST API for explicitly setting title - update logic so that if it is provided with a spoiler text then the spoiler text is always used as actual spoiler text and the title is the title. --- src/Module/Api/Mastodon/Statuses.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index c803835d1..602087025 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -107,6 +107,7 @@ class Statuses extends BaseApi 'visibility' => '', // Visibility of the posted status. One of: "public", "unlisted", "private" or "direct". 'scheduled_at' => '', // ISO 8601 Datetime at which to schedule a status. Providing this paramter will cause ScheduledStatus to be returned instead of Status. Must be at least 5 minutes in the future. 'language' => '', // ISO 639 language code for this status. + 'friendica' => [], // Friendica extensions to the standard Mastodon API spec ], $request); $owner = User::getOwnerDataById($uid); @@ -208,8 +209,13 @@ class Statuses extends BaseApi $item['quote-uri-id'] = $request['quote_id']; } + $has_title = array_key_exists('title', $request['friendica']); + if ($has_title != null && !$request['in_reply_to_id']) { + $item['title'] = $request['friendica']['title']; + } + if (!empty($request['spoiler_text'])) { - if (!$request['in_reply_to_id'] && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { + if (!$has_title && !$request['in_reply_to_id'] && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { $item['title'] = $request['spoiler_text']; } else { $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body']; From 4b2ee284d8b5e4e8fd6193678b005670719557bc Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Sat, 18 Feb 2023 10:07:08 -0500 Subject: [PATCH 3/6] Change check for friendica-title key to use isa and always set --- src/Module/Api/Mastodon/Statuses.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 602087025..38eeb877c 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -209,13 +209,10 @@ class Statuses extends BaseApi $item['quote-uri-id'] = $request['quote_id']; } - $has_title = array_key_exists('title', $request['friendica']); - if ($has_title != null && !$request['in_reply_to_id']) { - $item['title'] = $request['friendica']['title']; - } + $item['title'] = $request['friendica']['title'] ?? ''; if (!empty($request['spoiler_text'])) { - if (!$has_title && !$request['in_reply_to_id'] && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { + if (!isset($request['friendica']['title']) && !$request['in_reply_to_id'] && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { $item['title'] = $request['spoiler_text']; } else { $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body']; From f1dbf82e5b43c9cb521ff689b46f1697d9c9e6a1 Mon Sep 17 00:00:00 2001 From: Hank G Date: Sun, 19 Feb 2023 07:50:39 -0500 Subject: [PATCH 4/6] Update src/Module/Api/Mastodon/Statuses.php Co-authored-by: Philipp --- src/Module/Api/Mastodon/Statuses.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 38eeb877c..01856b2d8 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -107,7 +107,7 @@ class Statuses extends BaseApi 'visibility' => '', // Visibility of the posted status. One of: "public", "unlisted", "private" or "direct". 'scheduled_at' => '', // ISO 8601 Datetime at which to schedule a status. Providing this paramter will cause ScheduledStatus to be returned instead of Status. Must be at least 5 minutes in the future. 'language' => '', // ISO 639 language code for this status. - 'friendica' => [], // Friendica extensions to the standard Mastodon API spec + 'friendica' => [], // Friendica extensions to the standard Mastodon API spec ], $request); $owner = User::getOwnerDataById($uid); From 3bb0bda880e7dd2bf47ef68fa8b48cd1799fc407 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Sun, 19 Feb 2023 07:58:10 -0500 Subject: [PATCH 5/6] Remove documentation stating friendica extensions can be null since always set --- src/Object/Api/Mastodon/Status.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index bcbe1deeb..51f0b1c39 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -96,8 +96,8 @@ class Status extends BaseDataTransferObject protected $card = null; /** @var Poll|null */ protected $poll = null; - /** @var FriendicaExtension|null */ - protected $friendica = null; + /** @var FriendicaExtension */ + protected $friendica; /** * Creates a status record from an item record. From cd957a7f66e2b8c4d19ef66ed3a8ff28454c3f4a Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Sun, 19 Feb 2023 07:59:53 -0500 Subject: [PATCH 6/6] Remove extraneous __get since needed capability found in parent class --- src/Object/Api/Mastodon/Status/FriendicaExtension.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Object/Api/Mastodon/Status/FriendicaExtension.php b/src/Object/Api/Mastodon/Status/FriendicaExtension.php index 1a63f7606..050c5a026 100644 --- a/src/Object/Api/Mastodon/Status/FriendicaExtension.php +++ b/src/Object/Api/Mastodon/Status/FriendicaExtension.php @@ -45,9 +45,4 @@ class FriendicaExtension extends BaseDataTransferObject { $this->title = $title; } - - public function __get($name) - { - return $this->$name; - } }