From: Michael Date: Mon, 13 Mar 2023 05:33:32 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/develop' into api-edit X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=59c436b442112344c3e2fa01b1b7e824df6c1e06;p=friendica.git Merge remote-tracking branch 'upstream/develop' into api-edit --- 59c436b442112344c3e2fa01b1b7e824df6c1e06 diff --cc src/Module/Api/Mastodon/Statuses.php index 943fc7514f,64fba420dd..65563b6462 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@@ -50,10 -51,9 +51,11 @@@ class Statuses extends BaseAp $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. + 'media_ids' => [], // Array of Attachment ids to be attached as media. If provided, status becomes optional, and poll cannot be used. + '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); @@@ -66,7 -66,7 +68,7 @@@ 'origin' => true, ]; - $post = Post::selectFirst(['uri-id', 'id', 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], $condition); - $post = Post::selectFirst(['uri-id', 'id', 'gravity'], $condition); ++ $post = Post::selectFirst(['uri-id', 'id', 'gravity', 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], $condition); if (empty($post['id'])) { throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.'); } @@@ -86,43 -93,9 +95,46 @@@ } } + if (!empty($request['media_ids'])) { + /* + The provided ids in the request value consists of these two sources: + - The id in the "photo" table for newly uploaded media + - The id in the "post-media" table for already attached media + + Because of this we have to add all media that isn't already attached. + Also we have to delete all media that isn't provided anymore. + + There is a possible situation where the newly uploaded media + could have the same id as an existing, but deleted media. + + We can't do anything about this, but the probability for this is extremely low. + */ + $media_ids = []; + $existing_media = array_column(Post\Media::getByURIId($post['uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE]), 'id'); + + foreach ($request['media_ids'] as $media) { + if (!in_array($media, $existing_media)) { + $media_ids[] = $media; + } + } + + foreach ($existing_media as $media) { + if (!in_array($media, $request['media_ids'])) { + Post\Media::deleteById($media); + } + } + + $item = $this->storeMediaIds($media_ids, array_merge($post, $item)); + + foreach ($item['attachments'] as $attachment) { + $attachment['uri-id'] = $post['uri-id']; + Post\Media::insert($attachment); + } + unset($item['attachments']); + } + if (!Item::isValid($item)) { + throw new \Exception('Missing parameters in definitien'); + } Item::update($item, ['id' => $post['id']]); Item::updateDisplayCache($post['uri-id']);