From 9c5f3ae58f0d77fe3fe1f85f9e1f3f97209337be Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Wed, 22 Feb 2023 11:02:52 -0500 Subject: [PATCH] Simply Timeline Home temporal endpoint to reuse min_id and max_id --- src/Module/Api/Mastodon/Timelines/Home.php | 8 +++---- src/Module/BaseApi.php | 22 +++++++++---------- .../Api/Mastodon/TimelineOrderByTypes.php | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Module/Api/Mastodon/Timelines/Home.php b/src/Module/Api/Mastodon/Timelines/Home.php index 379e175d4..2d646e428 100644 --- a/src/Module/Api/Mastodon/Timelines/Home.php +++ b/src/Module/Api/Mastodon/Timelines/Home.php @@ -45,17 +45,15 @@ class Home extends BaseApi $uid = self::getCurrentUserID(); $request = $this->getRequest([ - 'max_id' => 0, // Return results older than id + '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 + '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 - 'min_time' => '', - 'max_time' => '', 'friendica_order' => TimelineOrderByTypes::ID, ], $request); @@ -91,7 +89,7 @@ class Home extends BaseApi try { $status = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes); switch ($request['friendica_order']) { - case TimelineOrderByTypes::CREATED_AT: + case TimelineOrderByTypes::CREATED: self::setBoundaries($status->createdAtTimestamp()); break; case TimelineOrderByTypes::ID: diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 1deb81735..bdcced59f 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -118,31 +118,31 @@ class BaseApi extends BaseModule $requested_order = $request['friendica_order']; if ($requested_order == TimelineOrderByTypes::ID) { if (!empty($request['max_id'])) { - $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]); + $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", intval($request['max_id'])]); } if (!empty($request['since_id'])) { - $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]); + $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", intval($request['since_id'])]); } if (!empty($request['min_id'])) { - $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]); + $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", intval($request['min_id'])]); } } else { switch ($requested_order) { - case TimelineOrderByTypes::CREATED_AT: + case TimelineOrderByTypes::CREATED: $order_field = 'created'; break; default: $order_field = 'uri-id'; } - if (!empty($request['max_time'])) { - $condition = DBA::mergeConditions($condition, ["`$order_field` < ?", DateTimeFormat::convert($request['max_time'], DateTimeFormat::MYSQL)]); + if (!empty($request['max_id'])) { + $condition = DBA::mergeConditions($condition, ["`$order_field` < ?", DateTimeFormat::convert($request['max_id'], DateTimeFormat::MYSQL)]); } - if (!empty($request['min_time'])) { - $condition = DBA::mergeConditions($condition, ["`$order_field` > ?", DateTimeFormat::convert($request['min_time'], DateTimeFormat::MYSQL)]); + if (!empty($request['min_id'])) { + $condition = DBA::mergeConditions($condition, ["`$order_field` > ?", DateTimeFormat::convert($request['min_id'], DateTimeFormat::MYSQL)]); $params['order'] = [$order_field]; } @@ -204,8 +204,6 @@ class BaseApi extends BaseModule unset($request['min_id']); unset($request['max_id']); unset($request['since_id']); - unset($request['min_time']); - unset($request['max_time']); $prev_request = $next_request = $request; @@ -214,8 +212,8 @@ class BaseApi extends BaseModule $max_date->setTimestamp(self::$boundaries['max']); $min_date = new DateTime(); $min_date->setTimestamp(self::$boundaries['min']); - $prev_request['min_time'] = $max_date->format(DateTimeFormat::JSON); - $next_request['max_time'] = $min_date->format(DateTimeFormat::JSON); + $prev_request['min_id'] = $max_date->format(DateTimeFormat::JSON); + $next_request['max_id'] = $min_date->format(DateTimeFormat::JSON); } else { $prev_request['min_id'] = self::$boundaries['max']; $next_request['max_id'] = self::$boundaries['min']; diff --git a/src/Object/Api/Mastodon/TimelineOrderByTypes.php b/src/Object/Api/Mastodon/TimelineOrderByTypes.php index a42d2c060..196933c1f 100644 --- a/src/Object/Api/Mastodon/TimelineOrderByTypes.php +++ b/src/Object/Api/Mastodon/TimelineOrderByTypes.php @@ -28,5 +28,5 @@ namespace Friendica\Object\Api\Mastodon; abstract class TimelineOrderByTypes { const ID = 'id'; - const CREATED_AT = 'created_at'; + const CREATED = 'created'; }