From 7ccc978bc5c51b784af8b94ffb1e4da08849cc29 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Tue, 28 Feb 2023 15:35:37 -0500 Subject: [PATCH 1/2] Add title/spoiler text handling and capturing invalid update to Mastodon edit --- src/Module/Api/Mastodon/Statuses.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 01856b2d8b..bf5c9aa6a2 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon; +use Friendica\Content\Text\BBCode; use Friendica\Content\Text\Markdown; use Friendica\Core\Protocol; use Friendica\Core\System; @@ -50,9 +51,9 @@ class Statuses extends BaseApi $request = $this->getRequest([ 'status' => '', // Text content of the status. If media_ids is provided, this becomes optional. Attaching a poll is optional while status is provided. - 'in_reply_to_id' => 0, // ID of the status being replied to, if status is a reply 'spoiler_text' => '', // Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field. 'language' => '', // ISO 639 language code for this status. + 'friendica' => [], ], $request); $owner = User::getOwnerDataById($uid); @@ -65,7 +66,7 @@ class Statuses extends BaseApi 'origin' => true, ]; - $post = Post::selectFirst(['uri-id', 'id'], $condition); + $post = Post::selectFirst(['uri-id', 'id', 'gravity'], $condition); if (empty($post['id'])) { throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.'); } @@ -77,14 +78,25 @@ class Statuses extends BaseApi $item['language'] = json_encode([$request['language'] => 1]); } - if (!empty($request['spoiler_text'])) { - if (($request['in_reply_to_id'] == $post['uri-id']) && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { - $item['title'] = $request['spoiler_text']; + if ($post['gravity'] == 0) { + $item['title'] = $request['friendica']['title'] ?? ''; + } + + $spoiler_text = $request['spoiler_text']; + + if (!empty($spoiler_text)) { + if (!isset($request['friendica']['title']) && $post['gravity'] == 0 && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { + $item['title'] = $spoiler_text; } else { - $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body']; + $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body']; + $item['content-warning'] = BBCode::toPlaintext($spoiler_text); } } + if (!Item::isValid($item)) { + throw new \Exception('Missing parameters in definitien'); + } + Item::update($item, ['id' => $post['id']]); Item::updateDisplayCache($post['uri-id']); From a6e9f9c89e7716e969e9958ba761195e3fefb864 Mon Sep 17 00:00:00 2001 From: Hank G Date: Sun, 12 Mar 2023 11:43:59 -0400 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- src/Module/Api/Mastodon/Statuses.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index bf5c9aa6a2..64fba420dd 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -78,14 +78,14 @@ class Statuses extends BaseApi $item['language'] = json_encode([$request['language'] => 1]); } - if ($post['gravity'] == 0) { + if ($post['gravity'] == Item::GRAVITY_PARENT) { $item['title'] = $request['friendica']['title'] ?? ''; } $spoiler_text = $request['spoiler_text']; if (!empty($spoiler_text)) { - if (!isset($request['friendica']['title']) && $post['gravity'] == 0 && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { + if (!isset($request['friendica']['title']) && $post['gravity'] == Item::GRAVITY_PARENT && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { $item['title'] = $spoiler_text; } else { $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body'];