From 031ef6a05a243c616a00c24342345cf25dab7343 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Thu, 22 Jun 2023 21:56:38 -0400 Subject: [PATCH] Fix Mastodon API Status->Context endpoint so doesn't return deleted statuses --- src/Module/Api/Mastodon/Statuses/Context.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index 0b2e7bda6..c510fc9a8 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -56,6 +56,7 @@ class Context extends BaseApi $parents = []; $children = []; + $deleted = []; $parent = Post::selectOriginal(['uri-id', 'parent-uri-id'], ['uri-id' => $id]); if (DBA::isResult($parent)) { @@ -66,11 +67,11 @@ class Context extends BaseApi 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']; @@ -82,8 +83,8 @@ class Context extends BaseApi ["NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored`))", $uid] ); } - - $posts = Post::selectPosts(['uri-id', 'thr-parent-id'], $condition, $params); + + $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; @@ -93,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); @@ -117,7 +122,7 @@ class Context extends BaseApi $statuses = ['ancestors' => [], 'descendants' => []]; - $ancestors = self::getParents($id, $parents); + $ancestors = array_diff(self::getParents($id, $parents), $deleted); asort($ancestors); @@ -127,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);