Harmonized API parameters for all timeline endpoints

This commit is contained in:
Michael 2021-05-19 06:55:08 +00:00
parent e3d227f3c9
commit 50ca38a0f7
4 changed files with 52 additions and 37 deletions

View file

@ -43,15 +43,15 @@ class Home extends BaseApi
$uid = self::getCurrentUserID();
$request = self::getRequest([
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id
'min_id' => 0, // Return results immediately newer than id
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'local' => false, // Return only local statuses?
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'local' => false, // Show only local statuses? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id
'min_id' => 0, // Return results immediately newer than id
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'local' => false, // Return only local statuses?
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'exclude_replies' => false, // Don't show comments
]);
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
@ -81,14 +81,14 @@ class Home extends BaseApi
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
}
if ($request['local']) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
}
if ($request['remote']) {
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
}
if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
}
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
$statuses = [];

View file

@ -47,14 +47,15 @@ class ListTimeline extends BaseApi
}
$request = self::getRequest([
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id
'min_id' => 0, // Return results immediately newer than id
'limit' => 20, // Maximum number of results to return. Defaults to 20.Return results older than this ID.
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'local' => false, // Show only local statuses? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id
'min_id' => 0, // Return results immediately newer than id
'limit' => 20, // Maximum number of results to return. Defaults to 20.Return results older than this ID.
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'local' => false, // Show only local statuses? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'exclude_replies' => false, // Don't show comments
]);
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
@ -81,6 +82,10 @@ class ListTimeline extends BaseApi
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
}
if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
}
if ($request['local']) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
}

View file

@ -42,14 +42,15 @@ class PublicTimeline extends BaseApi
public static function rawContent(array $parameters = [])
{
$request = self::getRequest([
'local' => false, // Show only local statuses? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than this id
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'local' => false, // Show only local statuses? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than this id
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'exclude_replies' => false, // Don't show comments
]);
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
@ -83,6 +84,10 @@ class PublicTimeline extends BaseApi
$params['order'] = ['uri-id'];
}
if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
}
$items = Post::selectForUser(0, ['uri-id', 'uid'], $condition, $params);
$statuses = [];

View file

@ -48,14 +48,15 @@ class Tag extends BaseApi
}
$request = self::getRequest([
'local' => false, // If true, return only local statuses. Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'only_media' => false, // If true, return only statuses with media attachments. Defaults to false.
'max_id' => 0, // Return results older than this ID.
'since_id' => 0, // Return results newer than this ID.
'min_id' => 0, // Return results immediately newer than this ID.
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'local' => false, // If true, return only local statuses. Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'only_media' => false, // If true, return only statuses with media attachments. Defaults to false.
'max_id' => 0, // Return results older than this ID.
'since_id' => 0, // Return results newer than this ID.
'min_id' => 0, // Return results immediately newer than this ID.
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'exclude_replies' => false, // Don't show comments
]);
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
@ -77,6 +78,10 @@ class Tag extends BaseApi
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
}
if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
}
if (!empty($request['max_id'])) {
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
}