$uid = self::getCurrentUserID();
if (empty($parameters['id'])) {
- DI::mstdnError()->RecordNotFound();
+ DI::mstdnError()->UnprocessableEntity();
}
+ $request = self::getRequest([
+ 'limit' => 40, // Maximum number of results to return. Defaults to 40.
+ ]);
+
$id = $parameters['id'];
+
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
if (!DBA::isResult($parent)) {
DI::mstdnError()->RecordNotFound();
}
- $parents = [];
+ $parents = [];
$children = [];
- $posts = Post::select(['uri-id', 'thr-parent-id'], ['parent-uri-id' => $parent['parent-uri-id']], [], false);
+
+ $posts = Post::selectPosts(['uri-id', 'thr-parent-id'],
+ ['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]], []);
while ($post = Post::fetch($posts)) {
if ($post['uri-id'] == $post['thr-parent-id']) {
continue;
$statuses = ['ancestors' => [], 'descendants' => []];
- foreach (self::getParents($id, $parents) as $ancestor) {
- $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid);
+ $ancestors = self::getParents($id, $parents);
+
+ asort($ancestors);
+
+ foreach (array_slice($ancestors, 0, $request['limit']) as $ancestor) {
+ $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid);;
}
- foreach (self::getChildren($id, $children) as $descendant) {
+ $descendants = self::getChildren($id, $children);
+
+ asort($descendants);
+
+ foreach (array_slice($descendants, 0, $request['limit']) as $descendant) {
$statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid);
}