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:
commit
2bdb492834
1 changed files with 11 additions and 6 deletions
|
@ -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)) {
|
||||||
|
@ -66,11 +67,11 @@ class Context extends BaseApi
|
||||||
if (!empty($request['max_id'])) {
|
if (!empty($request['max_id'])) {
|
||||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
|
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($request['since_id'])) {
|
if (!empty($request['since_id'])) {
|
||||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]);
|
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($request['min_id'])) {
|
if (!empty($request['min_id'])) {
|
||||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
|
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
|
||||||
$params['order'] = ['uri-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]
|
["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)) {
|
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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue