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 = [];
$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);