Merge pull request #12894 from HankG/mastodon-status-edit-fix-tag-and-mentions

Fix tag and mention updates in Mastodon status edit endpoint
This commit is contained in:
Hypolite Petovan 2023-03-16 11:55:05 -04:00 committed by GitHub
commit b3d779ef7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,6 +34,7 @@ use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
@ -70,13 +71,23 @@ class Statuses extends BaseApi
'origin' => true,
];
$post = Post::selectFirst(['uri-id', 'id', 'gravity', 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], $condition);
$post = Post::selectFirst(['uri-id', 'id', 'gravity', 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'network'], $condition);
if (empty($post['id'])) {
throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.');
}
// The imput is defined as text. So we can use Markdown for some enhancements
$item = ['body' => Markdown::toBBCode($request['status']), 'app' => $this->getApp(), 'title' => ''];
$body = Markdown::toBBCode($request['status']);
if (DI::pConfig()->get($uid, 'system', 'api_auto_attach', false) && preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $body, $matches)) {
$body = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $body);
}
$item['title'] = '';
$item['uid'] = $post['uid'];
$item['body'] = $body;
$item['network'] = $post['network'];
$item['app'] = $this->getApp();
if (!empty($request['language'])) {
$item['language'] = json_encode([$request['language'] => 1]);
@ -97,6 +108,8 @@ class Statuses extends BaseApi
}
}
$item = DI::contentItem()->expandTags($item, $request['visibility'] == 'direct');
if (!empty($request['media_ids'])) {
/*
The provided ids in the request value consists of these two sources:
@ -135,10 +148,18 @@ class Statuses extends BaseApi
unset($item['attachments']);
}
if (!Item::isValid($item)) {
throw new \Exception('Missing parameters in definitien');
throw new \Exception('Missing parameters in definition');
}
Item::update($item, ['id' => $post['id']]);
foreach (Tag::getByURIId($post['uri-id']) as $tagToRemove) {
Tag::remove($post['uri-id'], $tagToRemove['type'], $tagToRemove['name'], $tagToRemove['url']);
}
// Store tags from the body if this hadn't been handled previously in the protocol classes
Tag::storeFromBody($post['uri-id'], Item::setHashtags($item['body']));
Item::updateDisplayCache($post['uri-id']);
System::jsonExit(DI::mstdnStatus()->createFromUriId($post['uri-id'], $uid, self::appSupportsQuotes()));