+ if (!empty($uid) && !$request['show_all']) {
+ $condition = DBA::mergeConditions(
+ $condition,
+ ["NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND (`blocked` OR `ignored`))", $uid]
+ );
+ }
+
+ $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;
+ }
+ self::setBoundaries($post['uri-id']);
+
+ $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);
+
+ self::setLinkHeader();
+ } else {
+ $parent = DBA::selectFirst('mail', ['parent-uri-id'], ['uri-id' => $id, 'uid' => $uid]);
+ if (DBA::isResult($parent)) {
+ $posts = DBA::select('mail', ['uri-id', 'thr-parent-id'], ['parent-uri-id' => $parent['parent-uri-id']]);
+ while ($post = DBA::fetch($posts)) {
+ if ($post['uri-id'] == $post['thr-parent-id']) {
+ continue;
+ }
+ $parents[$post['uri-id']] = $post['thr-parent-id'];
+
+ $children[$post['thr-parent-id']][] = $post['uri-id'];
+ }
+ DBA::close($posts);
+ } else {
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
+ }