]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/BaseApi.php
Channels: Larger fields, better error handling
[friendica.git] / src / Module / BaseApi.php
index 10e64044f31a987141d04b188d9d6168900262b8..c73f90aba62676a1eecd7f05c483d74b4bac9550 100644 (file)
@@ -221,8 +221,8 @@ class BaseApi extends BaseModule
                                        }
                                        break;
                                case TimelineOrderByTypes::EDITED:
-                                       if (!empty($status->friendicaExtension()->editedAt())) {
-                                               self::setBoundaries(new DateTime(DateTimeFormat::utc($status->friendicaExtension()->editedAt(), DateTimeFormat::JSON)));
+                                       if (!empty($status->editedAt())) {
+                                               self::setBoundaries(new DateTime(DateTimeFormat::utc($status->editedAt(), DateTimeFormat::JSON)));
                                        }
                                        break;
                                case TimelineOrderByTypes::RECEIVED:
@@ -372,7 +372,7 @@ class BaseApi extends BaseModule
         */
        public static function appSupportsQuotes(): bool
        {
-               $token = self::getCurrentApplication();
+               $token = OAuth::getCurrentApplicationToken();
                return (!empty($token['name']) && in_array($token['name'], ['Fedilab']));
        }
 
@@ -434,7 +434,7 @@ class BaseApi extends BaseModule
                }
        }
 
-       public static function checkThrottleLimit()
+       public function checkThrottleLimit()
        {
                $uid = self::getCurrentUserID();
 
@@ -447,11 +447,11 @@ class BaseApi extends BaseModule
                        $posts_day = Post::countThread($condition);
 
                        if ($posts_day > $throttle_day) {
-                               Logger::notice('Daily posting limit reached', ['uid' => $uid, 'posts' => $posts_day, 'limit' => $throttle_day]);
-                               $error = DI::l10n()->t('Too Many Requests');
-                               $error_description = DI::l10n()->tt("Daily posting limit of %d post reached. The post was rejected.", "Daily posting limit of %d posts reached. The post was rejected.", $throttle_day);
+                               $this->logger->notice('Daily posting limit reached', ['uid' => $uid, 'posts' => $posts_day, 'limit' => $throttle_day]);
+                               $error = $this->t('Too Many Requests');
+                               $error_description = $this->tt("Daily posting limit of %d post reached. The post was rejected.", "Daily posting limit of %d posts reached. The post was rejected.", $throttle_day);
                                $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
-                               System::jsonError(429, $errorobj->toArray());
+                               $this->jsonError(429, $errorobj->toArray());
                        }
                }
 
@@ -464,10 +464,10 @@ class BaseApi extends BaseModule
 
                        if ($posts_week > $throttle_week) {
                                Logger::notice('Weekly posting limit reached', ['uid' => $uid, 'posts' => $posts_week, 'limit' => $throttle_week]);
-                               $error = DI::l10n()->t('Too Many Requests');
-                               $error_description = DI::l10n()->tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week);
+                               $error = $this->t('Too Many Requests');
+                               $error_description = $this->tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week);
                                $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
-                               System::jsonError(429, $errorobj->toArray());
+                               $this->jsonError(429, $errorobj->toArray());
                        }
                }
 
@@ -480,10 +480,10 @@ class BaseApi extends BaseModule
 
                        if ($posts_month > $throttle_month) {
                                Logger::notice('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);
-                               $error = DI::l10n()->t('Too Many Requests');
-                               $error_description = DI::l10n()->tt('Monthly posting limit of %d post reached. The post was rejected.', 'Monthly posting limit of %d posts reached. The post was rejected.', $throttle_month);
+                               $error = $this->t('Too Many Requests');
+                               $error_description = $this->tt('Monthly posting limit of %d post reached. The post was rejected.', 'Monthly posting limit of %d posts reached. The post was rejected.', $throttle_month);
                                $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
-                               System::jsonError(429, $errorobj->toArray());
+                               $this->jsonError(429, $errorobj->toArray());
                        }
                }
        }