Merge pull request #12878 from HankG/mastodon-edit-title-spoiler-update

Mastodon edit title spoiler update
This commit is contained in:
Hypolite Petovan 2023-03-12 14:39:35 -04:00 committed by GitHub
commit 7ac5c1eee8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@
namespace Friendica\Module\Api\Mastodon; namespace Friendica\Module\Api\Mastodon;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown; use Friendica\Content\Text\Markdown;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
@ -50,9 +51,9 @@ class Statuses extends BaseApi
$request = $this->getRequest([ $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. '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. '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. 'language' => '', // ISO 639 language code for this status.
'friendica' => [],
], $request); ], $request);
$owner = User::getOwnerDataById($uid); $owner = User::getOwnerDataById($uid);
@ -65,7 +66,7 @@ class Statuses extends BaseApi
'origin' => true, 'origin' => true,
]; ];
$post = Post::selectFirst(['uri-id', 'id'], $condition); $post = Post::selectFirst(['uri-id', 'id', 'gravity'], $condition);
if (empty($post['id'])) { if (empty($post['id'])) {
throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.'); 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]); $item['language'] = json_encode([$request['language'] => 1]);
} }
if (!empty($request['spoiler_text'])) { if ($post['gravity'] == Item::GRAVITY_PARENT) {
if (($request['in_reply_to_id'] == $post['uri-id']) && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { $item['title'] = $request['friendica']['title'] ?? '';
$item['title'] = $request['spoiler_text']; }
$spoiler_text = $request['spoiler_text'];
if (!empty($spoiler_text)) {
if (!isset($request['friendica']['title']) && $post['gravity'] == Item::GRAVITY_PARENT && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) {
$item['title'] = $spoiler_text;
} else { } 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::update($item, ['id' => $post['id']]);
Item::updateDisplayCache($post['uri-id']); Item::updateDisplayCache($post['uri-id']);