]> git.mxchange.org Git - friendica.git/commitdiff
Suggestions are now supported as well
authorMichael <heluecht@pirati.ca>
Sat, 8 May 2021 11:03:50 +0000 (11:03 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 8 May 2021 11:03:50 +0000 (11:03 +0000)
doc/API-Mastodon.md
src/Model/Post/Media.php
src/Module/Api/Mastodon/Suggestions.php [new file with mode: 0644]
static/routes.config.php

index e72b0c31a7ec1c7df14ed0672377cfb941ef003b..574c5eb7f9d0561e291f7c4eda5ad5812fb04340 100644 (file)
@@ -38,6 +38,7 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en
 - [`GET /api/v1/instance`](https://docs.joinmastodon.org/methods/instance#fetch-instance)
 - [`GET /api/v1/instance/peers`](https://docs.joinmastodon.org/methods/instance#list-of-connected-domains)
 - [`GET /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/)
+- [`GET /api/v1/suggestions`](https://docs.joinmastodon.org/methods/accounts/suggestions/)
 - [`GET /api/v1/timelines/home`](https://docs.joinmastodon.org/methods/timelines/)
 - [`GET /api/v1/timelines/list/:id`](https://docs.joinmastodon.org/methods/timelines/)
 - [`GET /api/v1/timelines/public`](https://docs.joinmastodon.org/methods/timelines/)
index b975a09022a31186dbd10783b88e8f8cf8a64712..6f78b09051a7de8f838db6e6ef4d14868f0778ad 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Model\Post;
 
-use Friendica\Content\PageInfo;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
@@ -67,6 +66,11 @@ class Media
                        return;
                }
 
+               if (DBA::exists('post-media', ['uri-id' => $media['uri-id'], 'preview' => $media['url']])) {
+                       Logger::info('Media already exists as preview', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'callstack' => System::callstack()]);
+                       return;
+               }
+
                // "document" has got the lowest priority. So when the same file is both attached as document
                // and embedded as picture then we only store the picture or replace the document
                $found = DBA::selectFirst('post-media', ['type'], ['uri-id' => $media['uri-id'], 'url' => $media['url']]);
@@ -499,6 +503,7 @@ class Media
 
                $height = 0;
                $selected = '';
+               $previews = [];
 
                foreach ($media as $medium) {
                        foreach ($links as $link) {
@@ -507,6 +512,17 @@ class Media
                                }
                        }
 
+                       // Avoid adding separate media entries for previews
+                       foreach ($previews as $preview) {
+                               if (Strings::compareLink($preview, $medium['url'])) {
+                                       continue 2;
+                               }
+                       }
+                       
+                       if (!empty($medium['preview'])) {
+                               $previews[] = $medium['preview'];
+                       }
+
                        $type = explode('/', current(explode(';', $medium['mimetype'])));
                        if (count($type) < 2) {
                                Logger::info('Unknown MimeType', ['type' => $type, 'media' => $medium]);
diff --git a/src/Module/Api/Mastodon/Suggestions.php b/src/Module/Api/Mastodon/Suggestions.php
new file mode 100644 (file)
index 0000000..97cfa11
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon;
+
+use Friendica\Core\System;
+use Friendica\DI;
+use Friendica\Model\Contact;
+use Friendica\Module\BaseApi;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/accounts/suggestions/
+ */
+class Suggestions extends BaseApi
+{
+       /**
+        * @param array $parameters
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       public static function rawContent(array $parameters = [])
+       {
+               self::login();
+               $uid = self::getCurrentUserID();
+
+               // Maximum number of results to return. Defaults to 40.
+               $limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit'];
+
+               $suggestions = Contact\Relation::getSuggestions($uid, 0, $limit);
+
+               $accounts = [];
+
+               foreach ($suggestions as $suggestion) {
+                       $accounts[] = DI::mstdnAccount()->createFromContactId($suggestion['id'], $uid);
+               }
+
+               System::jsonExit($accounts);
+       }
+}
index 40c17912b47a330eb2584eeb27ec27563a12e4b9..6ca57082e5d4b24c51f6dab452245f5e27d2ab88 100644 (file)
@@ -140,7 +140,7 @@ return [
                        '/statuses/{id:\d+}/unmute'          => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]],
                        '/statuses/{id:\d+}/pin'             => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]],
                        '/statuses/{id:\d+}/unpin'           => [Module\Api\Mastodon\Unimplemented::class,            [        R::POST]],
-                       '/suggestions'                       => [Module\Api\Mastodon\Unimplemented::class,            [R::GET         ]],
+                       '/suggestions'                       => [Module\Api\Mastodon\Suggestions::class,              [R::GET         ]],
                        '/suggestions/{id:\d+}'              => [Module\Api\Mastodon\Unimplemented::class,            [R::DELETE      ]],
                        '/timelines/home'                    => [Module\Api\Mastodon\Timelines\Home::class,           [R::GET         ]],
                        '/timelines/list/{id:\d+}'           => [Module\Api\Mastodon\Timelines\ListTimeline::class,   [R::GET         ]],