]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Api/Mastodon/Tags/Unfollow.php
Move jsonError out of Factory\Api\Mastodon\Error->UnprocessableEntity
[friendica.git] / src / Module / Api / Mastodon / Tags / Unfollow.php
index a20b824b8d3547a2dfbe70a1e53eabbf21c1c50e..07b93d95a2dedc8c2cf3a4feb752f5445f556235 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -21,7 +21,8 @@
 
 namespace Friendica\Module\Api\Mastodon\Tags;
 
-use Friendica\App\Router;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Module\BaseApi;
 
@@ -32,13 +33,18 @@ class Unfollow extends BaseApi
 {
        protected function post(array $request = [])
        {
-               self::checkAllowedScope(self::SCOPE_WRITE);
+               $this->checkAllowedScope(self::SCOPE_WRITE);
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['hashtag'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
-               $this->response->unsupported(Router::POST, $request);
+               $term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
+
+               DBA::delete('search', $term);
+
+               $hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, ['name' => ltrim($this->parameters['hashtag'])], [], false);
+               $this->jsonExit($hashtag->toArray());
        }
 }