]> git.mxchange.org Git - friendica.git/commitdiff
Simply Timeline Home temporal endpoint to reuse min_id and max_id
authorHank Grabowski <hankgrabowski@gmail.com>
Wed, 22 Feb 2023 16:02:52 +0000 (11:02 -0500)
committerHank Grabowski <hankgrabowski@gmail.com>
Wed, 22 Feb 2023 16:02:52 +0000 (11:02 -0500)
src/Module/Api/Mastodon/Timelines/Home.php
src/Module/BaseApi.php
src/Object/Api/Mastodon/TimelineOrderByTypes.php

index 379e175d453a9040ce8e12bf6fec266e10083f79..2d646e428a2c2f9b7f42a6aaaaa87a515e56e517 100644 (file)
@@ -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:
index 1deb81735ab2b8bcf5a4ab1f40461d72b9844ef7..bdcced59f43b630907857c9bb6796fd8625c53f1 100644 (file)
@@ -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'];
index a42d2c0605b5a805c7f07bdcbfb889be374bfa44..196933c1fe6a173a33e6589fd8e5b8672f38e52f 100644 (file)
@@ -28,5 +28,5 @@ namespace Friendica\Object\Api\Mastodon;
 abstract class TimelineOrderByTypes
 {
        const ID         = 'id';
-       const CREATED_AT = 'created_at';
+       const CREATED    = 'created';
 }