Merge pull request #13229 from HankG/fix-mastodon-status-context-returning-deleted-statuses

Fix Mastodon API Status->Context endpoint so doesn't return deleted statuses
This commit is contained in:
Hypolite Petovan 2023-06-22 23:40:43 -04:00 committed by GitHub
commit 2bdb492834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,6 +56,7 @@ class Context extends BaseApi
$parents = []; $parents = [];
$children = []; $children = [];
$deleted = [];
$parent = Post::selectOriginal(['uri-id', 'parent-uri-id'], ['uri-id' => $id]); $parent = Post::selectOriginal(['uri-id', 'parent-uri-id'], ['uri-id' => $id]);
if (DBA::isResult($parent)) { if (DBA::isResult($parent)) {
@ -83,7 +84,7 @@ class Context extends BaseApi
); );
} }
$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)) { while ($post = Post::fetch($posts)) {
if ($post['uri-id'] == $post['thr-parent-id']) { if ($post['uri-id'] == $post['thr-parent-id']) {
continue; continue;
@ -93,6 +94,10 @@ class Context extends BaseApi
$parents[$post['uri-id']] = $post['thr-parent-id']; $parents[$post['uri-id']] = $post['thr-parent-id'];
$children[$post['thr-parent-id']][] = $post['uri-id']; $children[$post['thr-parent-id']][] = $post['uri-id'];
if ($post['deleted']) {
$deleted[] = $post['uri-id'];
}
} }
DBA::close($posts); DBA::close($posts);
@ -117,7 +122,7 @@ class Context extends BaseApi
$statuses = ['ancestors' => [], 'descendants' => []]; $statuses = ['ancestors' => [], 'descendants' => []];
$ancestors = self::getParents($id, $parents); $ancestors = array_diff(self::getParents($id, $parents), $deleted);
asort($ancestors); asort($ancestors);
@ -127,7 +132,7 @@ class Context extends BaseApi
$statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid, $display_quotes); $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid, $display_quotes);
} }
$descendants = self::getChildren($id, $children); $descendants = array_diff(self::getChildren($id, $children), $deleted);
asort($descendants); asort($descendants);