]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Api/Mastodon/Statuses.php
Merge pull request #13176 from MrPetovan/bug/warnings
[friendica.git] / src / Module / Api / Mastodon / Statuses.php
index a73a38da2883004055d73dd44bc140908a5baee9..dad0451fc424ad00c16fb7ad5eaffac4cb64524b 100644 (file)
@@ -30,7 +30,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
-use Friendica\Model\Group;
+use Friendica\Model\Circle;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
@@ -71,7 +71,7 @@ class Statuses extends BaseApi
                        'origin'     => true,
                ];
 
-               $post = Post::selectFirst(['uri-id', 'id', 'gravity', 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'network'], $condition);
+               $post = Post::selectFirst(['uri-id', 'id', 'gravity', 'verb', '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 . '.');
                }
@@ -87,6 +87,8 @@ class Statuses extends BaseApi
                $item['uid']        = $post['uid'];
                $item['body']       = $body;
                $item['network']    = $post['network'];
+               $item['gravity']    = $post['gravity'];
+               $item['verb']       = $post['verb'];
                $item['app']        = $this->getApp();
 
                if (!empty($request['language'])) {
@@ -108,45 +110,44 @@ class Statuses extends BaseApi
                        }
                }
 
-               $item = DI::contentItem()->expandTags($item, $request['visibility'] == 'direct');
+               $item = DI::contentItem()->expandTags($item);
 
-               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;
-                               }
+               /*
+               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);
-                               }
+               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));
+               $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']);
+               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 definition');
                }
@@ -182,7 +183,7 @@ class Statuses extends BaseApi
                        'sensitive'      => false, // Mark status and attached media as sensitive?
                        'spoiler_text'   => '',    // Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field.
                        '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.
+                       'scheduled_at'   => '',    // ISO 8601 Datetime at which to schedule a status. Providing this parameter 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);
@@ -229,7 +230,7 @@ class Statuses extends BaseApi
                                        $item['deny_gid']  = $owner['deny_gid'];
                                } else {
                                        $item['allow_cid'] = '';
-                                       $item['allow_gid'] = '<' . Group::FOLLOWERS . '>';
+                                       $item['allow_gid'] = '<' . Circle::FOLLOWERS . '>';
                                        $item['deny_cid']  = '';
                                        $item['deny_gid']  = '';
                                }
@@ -240,7 +241,7 @@ class Statuses extends BaseApi
                                // The permissions are assigned in "expandTags"
                                break;
                        default:
-                               if (is_numeric($request['visibility']) && Group::exists($request['visibility'], $uid)) {
+                               if (is_numeric($request['visibility']) && Circle::exists($request['visibility'], $uid)) {
                                        $item['allow_cid'] = '';
                                        $item['allow_gid'] = '<' . $request['visibility'] . '>';
                                        $item['deny_cid']  = '';
@@ -267,15 +268,14 @@ class Statuses extends BaseApi
                }
 
                if ($request['in_reply_to_id']) {
-                       $parent = Post::selectFirst(['uri', 'private'], ['uri-id' => $request['in_reply_to_id'], 'uid' => [0, $uid]]);
+                       $parent = Post::selectOriginal(['uri'], ['uri-id' => $request['in_reply_to_id'], 'uid' => [0, $uid]]);
+                       if (empty($parent)) {
+                               throw new HTTPException\NotFoundException('Item with URI ID ' . $request['in_reply_to_id'] . ' not found for user ' . $uid . '.');
+                       }
 
                        $item['thr-parent']  = $parent['uri'];
                        $item['gravity']     = Item::GRAVITY_COMMENT;
                        $item['object-type'] = Activity\ObjectType::COMMENT;
-
-                       if (in_array($parent['private'], [Item::UNLISTED, Item::PUBLIC]) && ($item['private'] == Item::PRIVATE)) {
-                               throw new HTTPException\NotImplementedException('Private replies for public posts are not implemented.');
-                       }
                } else {
                        self::checkThrottleLimit();
 
@@ -393,9 +393,8 @@ class Statuses extends BaseApi
                                continue;
                        }
 
-                       Photo::setPermissionForRessource($media[0]['resource-id'], $item['uid'], $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid']);
+                       Photo::setPermissionForResource($media[0]['resource-id'], $item['uid'], $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid']);
 
-                       $ressources[] = $media[0]['resource-id'];
                        $phototypes = Images::supportedTypes();
                        $ext = $phototypes[$media[0]['type']];