]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Api/Mastodon/Notifications/Dismiss.php
Rename BaseApi->logErrorAndJsonExit to logAndJsonError to better match the functionality
[friendica.git] / src / Module / Api / Mastodon / Notifications / Dismiss.php
index 8900a2d43f9eff288595e0b76259b0583962851e..9771f1df6fd0aefbffee77f79eeecad8f2a9b7e6 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -25,23 +25,27 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Module\BaseApi;
+use Friendica\Network\HTTPException\ForbiddenException;
 
 /**
  * @see https://docs.joinmastodon.org/methods/notifications/
  */
 class Dismiss extends BaseApi
 {
-       public static function post(array $parameters = [])
+       protected function post(array $request = [])
        {
-               self::checkAllowedScope(self::SCOPE_WRITE);
+               $this->checkAllowedScope(self::SCOPE_WRITE);
                $uid = self::getCurrentUserID();
 
-               if (empty($parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+               if (empty($this->parameters['id'])) {
+                       $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
                }
 
-               DBA::update('notification', ['seen' => true], ['uid' => $uid, 'id' => $parameters['id']]);
+               $condition = ['id' => $this->parameters['id']];
+               $Notification = DI::notification()->selectOneForUser($uid, $condition);
+               $Notification->setDismissed();
+               DI::notification()->save($Notification);
 
-               System::jsonExit([]);
+               $this->jsonExit([]);
        }
 }