X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FApi%2FMastodon%2FStatuses%2FContext.php;h=6e35d717bf741d09bec7f51937beea1b1ff8edaa;hb=1b9ec3a2147fc10e4037ff1b2a7aac506cdf3b13;hp=76677de4ad292825a66a0a8e3d2961b09bc3422c;hpb=b6fcfebd566b0b6f5fdb97fad89c6c74b5cb57ca;p=friendica.git diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index 76677de4ad..6e35d717bf 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -41,40 +41,50 @@ class Context extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - DI::mstdnError()->UnprocessableEntity(); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $request = $this->getRequest([ - 'max_id' => 0, // Return results older than this id - 'since_id' => 0, // Return results newer than this id - 'min_id' => 0, // Return results immediately newer than this id - 'limit' => 40, // Maximum number of results to return. Defaults to 40. + 'max_id' => 0, // Return results older than this id + 'since_id' => 0, // Return results newer than this id + 'min_id' => 0, // Return results immediately newer than this id + 'limit' => 40, // Maximum number of results to return. Defaults to 40. + 'show_all' => false, // shows posts for all users including blocked and ignored users ], $request); $id = $this->parameters['id']; $parents = []; $children = []; + $deleted = []; - $parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]); + $parent = Post::selectOriginal(['uri-id', 'parent-uri-id'], ['uri-id' => $id]); if (DBA::isResult($parent)) { + $id = $parent['uri-id']; $params = ['order' => ['uri-id' => true]]; $condition = ['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]]; if (!empty($request['max_id'])) { $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]); } - + if (!empty($request['since_id'])) { $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]); } - + if (!empty($request['min_id'])) { $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]); $params['order'] = ['uri-id']; } - - $posts = Post::selectPosts(['uri-id', 'thr-parent-id'], $condition, $params); + + if (!empty($uid) && !$request['show_all']) { + $condition = DBA::mergeConditions( + $condition, + ["NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored`))", $uid] + ); + } + + $posts = Post::selectPosts(['uri-id', 'thr-parent-id', 'deleted'], $condition, $params); while ($post = Post::fetch($posts)) { if ($post['uri-id'] == $post['thr-parent-id']) { continue; @@ -84,6 +94,10 @@ class Context extends BaseApi $parents[$post['uri-id']] = $post['thr-parent-id']; $children[$post['thr-parent-id']][] = $post['uri-id']; + + if ($post['deleted']) { + $deleted[] = $post['uri-id']; + } } DBA::close($posts); @@ -102,13 +116,13 @@ class Context extends BaseApi } DBA::close($posts); } else { - DI::mstdnError()->RecordNotFound(); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } $statuses = ['ancestors' => [], 'descendants' => []]; - $ancestors = self::getParents($id, $parents); + $ancestors = array_diff(self::getParents($id, $parents), $deleted); asort($ancestors); @@ -118,7 +132,7 @@ class Context extends BaseApi $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid, $display_quotes); } - $descendants = self::getChildren($id, $children); + $descendants = array_diff(self::getChildren($id, $children), $deleted); asort($descendants); @@ -126,7 +140,7 @@ class Context extends BaseApi $statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid, $display_quotes); } - System::jsonExit($statuses); + $this->jsonExit($statuses); } private static function getParents(int $id, array $parents, array $list = [])