API: Lim it the elements for the context
This commit is contained in:
parent
1088376172
commit
a2be7e386f
|
@ -44,6 +44,10 @@ class Context extends BaseApi
|
||||||
DI::mstdnError()->UnprocessableEntity();
|
DI::mstdnError()->UnprocessableEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$request = self::getRequest([
|
||||||
|
'limit' => 40, // Maximum number of results to return. Defaults to 40.
|
||||||
|
]);
|
||||||
|
|
||||||
$id = $parameters['id'];
|
$id = $parameters['id'];
|
||||||
|
|
||||||
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
|
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
|
||||||
|
@ -70,22 +74,22 @@ class Context extends BaseApi
|
||||||
|
|
||||||
$ancestors = [];
|
$ancestors = [];
|
||||||
foreach (self::getParents($id, $parents) as $ancestor) {
|
foreach (self::getParents($id, $parents) as $ancestor) {
|
||||||
$ancestors[$ancestor] = DI::mstdnStatus()->createFromUriId($ancestor, $uid);
|
$ancestors[] = $ancestor;
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($ancestors);
|
asort($ancestors);
|
||||||
foreach ($ancestors as $ancestor) {
|
foreach (array_slice($ancestors, 0, $request['limit']) as $ancestor) {
|
||||||
$statuses['ancestors'][] = $ancestor;
|
$statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid);;
|
||||||
}
|
}
|
||||||
|
|
||||||
$descendants = [];
|
$descendants = [];
|
||||||
foreach (self::getChildren($id, $children) as $descendant) {
|
foreach (self::getChildren($id, $children) as $descendant) {
|
||||||
$descendants[] = DI::mstdnStatus()->createFromUriId($descendant, $uid);
|
$descendants[] = $descendant;
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($descendants);
|
asort($descendants);
|
||||||
foreach ($descendants as $descendant) {
|
foreach (array_slice($descendants, 0, $request['limit']) as $descendant) {
|
||||||
$statuses['descendants'][] = $descendant;
|
$statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
System::jsonExit($statuses);
|
System::jsonExit($statuses);
|
||||||
|
|
Loading…
Reference in a new issue