X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FApi%2FMastodon%2FLists.php;h=beb1a3b9a62455fd552f6a2022726c8d6eaa145d;hb=7486ebdc10715b7204b70ce262052d28cb61c69e;hp=67db0b81f2e78e16229476f4c3a7293014c8b195;hpb=452ed8aa8c040f683547e2635af8c9f16c450bd6;p=friendica.git diff --git a/src/Module/Api/Mastodon/Lists.php b/src/Module/Api/Mastodon/Lists.php index 67db0b81f2..beb1a3b9a6 100644 --- a/src/Module/Api/Mastodon/Lists.php +++ b/src/Module/Api/Mastodon/Lists.php @@ -1,6 +1,6 @@ checkAllowedScope(self::SCOPE_WRITE); $uid = self::getCurrentUserID(); - if (empty($parameters['id'])) { - DI::mstdnError()->UnprocessableEntity(); + if (empty($this->parameters['id'])) { + $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); } - if (!Group::exists($parameters['id'], $uid)) { - DI::mstdnError()->RecordNotFound(); + if (!Circle::exists($this->parameters['id'], $uid)) { + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } - if (!Group::remove($parameters['id'])) { + if (!Circle::remove($this->parameters['id'])) { DI::mstdnError()->InternalError(); } - System::jsonExit([]); + $this->jsonExit([]); } - public static function post(array $parameters = []) + protected function post(array $request = []) { - self::login(self::SCOPE_WRITE); - - $uid = self::getCurrentUserID(); + $this->checkAllowedScope(self::SCOPE_WRITE); + $uid = self::getCurrentUserID(); - $request = self::getRequest([ + $request = $this->getRequest([ 'title' => '', - ]); + ], $request); if (empty($request['title'])) { - DI::mstdnError()->UnprocessableEntity(); + $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); } - Group::create($uid, $request['title']); + Circle::create($uid, $request['title']); - $id = Group::getIdByName($uid, $request['title']); + $id = Circle::getIdByName($uid, $request['title']); if (!$id) { DI::mstdnError()->InternalError(); } - System::jsonExit(DI::mstdnList()->createFromGroupId($id)); + $this->jsonExit(DI::mstdnList()->createFromCircleId($id)); } - public static function put(array $parameters = []) + public function put(array $request = []) { - $request = self::getRequest([ + $request = $this->getRequest([ 'title' => '', // The title of the list to be updated. 'replies_policy' => '', // One of: "followed", "list", or "none". - ]); + ], $request); - if (empty($request['title']) || empty($parameters['id'])) { - DI::mstdnError()->UnprocessableEntity(); + if (empty($request['title']) || empty($this->parameters['id'])) { + $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); } - Group::update($parameters['id'], $request['title']); + Circle::update($this->parameters['id'], $request['title']); } /** - * @param array $parameters * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function rawContent(array $parameters = []) + protected function rawContent(array $request = []) { - self::login(self::SCOPE_READ); + $this->checkAllowedScope(self::SCOPE_READ); $uid = self::getCurrentUserID(); - if (empty($parameters['id'])) { + if (empty($this->parameters['id'])) { $lists = []; - $groups = Group::getByUserId($uid); - - foreach ($groups as $group) { - $lists[] = DI::mstdnList()->createFromGroupId($group['id']); + foreach (Circle::getByUserId($uid) as $circle) { + $lists[] = DI::mstdnList()->createFromCircleId($circle['id']); } } else { - $id = $parameters['id']; + $id = $this->parameters['id']; - if (!Group::exists($id, $uid)) { - DI::mstdnError()->RecordNotFound(); + if (!Circle::exists($id, $uid)) { + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } - $lists = DI::mstdnList()->createFromGroupId($id); + $lists = DI::mstdnList()->createFromCircleId($id); } - System::jsonExit($lists); + $this->jsonExit($lists); } }