]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Api/Mastodon/Blocks.php
Merge pull request #10600 from nupplaphil/bug/update_autoinstall_doc
[friendica.git] / src / Module / Api / Mastodon / Blocks.php
index 7f968f64b66a8c4a36ee32e5ffdec491b8ba9a6e..305914c1aadca10a1846bd99e54fddc50b1d8af2 100644 (file)
@@ -37,11 +37,11 @@ class Blocks extends BaseApi
         */
        public static function rawContent(array $parameters = [])
        {
-               self::login();
+               self::checkAllowedScope(self::SCOPE_READ);
                $uid = self::getCurrentUserID();
 
                if (empty($parameters['id'])) {
-                       DI::mstdnError()->RecordNotFound();
+                       DI::mstdnError()->UnprocessableEntity();
                }
 
                $id = $parameters['id'];
@@ -49,23 +49,22 @@ class Blocks extends BaseApi
                        DI::mstdnError()->RecordNotFound();
                }
 
-               // Return results older than this id
-               $max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id'];
-               // Return results newer than this id
-               $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
-               // Maximum number of results. Defaults to 40.
-               $limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit'];
+               $request = self::getRequest([
+                       'max_id'   => 0,  // Return results older than this id
+                       'since_id' => 0,  // Return results newer than this id
+                       'limit'    => 40, // Maximum number of results. Defaults to 40.
+               ]);
 
-               $params = ['order' => ['cid' => true], 'limit' => $limit];
+               $params = ['order' => ['cid' => true], 'limit' => $request['limit']];
 
                $condition = ['cid' => $id, 'blocked' => true, 'uid' => $uid];
 
-               if (!empty($max_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]);
+               if (!empty($request['max_id'])) {
+                       $condition = DBA::mergeConditions($condition, ["`cid` < ?", $request['max_id']]);
                }
 
-               if (!empty($since_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]);
+               if (!empty($request['since_id'])) {
+                       $condition = DBA::mergeConditions($condition, ["`cid` > ?", $request['since_id']]);
                }
 
                if (!empty($min_id)) {
@@ -76,10 +75,16 @@ class Blocks extends BaseApi
 
                $followers = DBA::select('user-contact', ['cid'], $condition, $parameters);
                while ($follower = DBA::fetch($followers)) {
+                       self::setBoundaries($follower['cid']);
                        $accounts[] = DI::mstdnAccount()->createFromContactId($follower['cid'], $uid);
                }
                DBA::close($followers);
 
+               if (!empty($min_id)) {
+                       array_reverse($accounts);
+               }
+
+               self::setLinkHeader();
                System::jsonExit($accounts);
        }
 }