]> git.mxchange.org Git - friendica.git/commitdiff
Fix Mastodon API Status->Context endpoint so doesn't return deleted statuses
authorHank Grabowski <hankgrabowski@gmail.com>
Fri, 23 Jun 2023 01:56:38 +0000 (21:56 -0400)
committerHank Grabowski <hankgrabowski@gmail.com>
Fri, 23 Jun 2023 01:56:38 +0000 (21:56 -0400)
src/Module/Api/Mastodon/Statuses/Context.php

index 0b2e7bda6d6b3c1c2b3e9e0c3545e71ab7b2421f..c510fc9a8c4db6a967ae9f701fbfccd9bd3160a7 100644 (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);