mirror of
https://github.com/friendica/friendica
synced 2024-11-11 08:22:54 +00:00
Merge pull request #10360 from annando/limit-context
API: Limit the elements for the context
This commit is contained in:
commit
b47ae829f7
1 changed files with 12 additions and 8 deletions
|
@ -44,6 +44,10 @@ class Context extends BaseApi
|
|||
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]);
|
||||
|
@ -70,22 +74,22 @@ class Context extends BaseApi
|
|||
|
||||
$ancestors = [];
|
||||
foreach (self::getParents($id, $parents) as $ancestor) {
|
||||
$ancestors[$ancestor] = DI::mstdnStatus()->createFromUriId($ancestor, $uid);
|
||||
$ancestors[] = $ancestor;
|
||||
}
|
||||
|
||||
ksort($ancestors);
|
||||
foreach ($ancestors as $ancestor) {
|
||||
$statuses['ancestors'][] = $ancestor;
|
||||
asort($ancestors);
|
||||
foreach (array_slice($ancestors, 0, $request['limit']) as $ancestor) {
|
||||
$statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid);;
|
||||
}
|
||||
|
||||
$descendants = [];
|
||||
foreach (self::getChildren($id, $children) as $descendant) {
|
||||
$descendants[] = DI::mstdnStatus()->createFromUriId($descendant, $uid);
|
||||
$descendants[] = $descendant;
|
||||
}
|
||||
|
||||
ksort($descendants);
|
||||
foreach ($descendants as $descendant) {
|
||||
$statuses['descendants'][] = $descendant;
|
||||
asort($descendants);
|
||||
foreach (array_slice($descendants, 0, $request['limit']) as $descendant) {
|
||||
$statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid);
|
||||
}
|
||||
|
||||
System::jsonExit($statuses);
|
||||
|
|
Loading…
Reference in a new issue