X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FApi%2FMastodon%2FAccounts.php;h=6b88b84ef3fac571fc365743abdfbd1e8888cda8;hb=7486ebdc10715b7204b70ce262052d28cb61c69e;hp=0d48744a40afd258a65a8f4488ba762df94ff3f9;hpb=e6a8e842533605581fe847205a1609bbfd6ecb94;p=friendica.git diff --git a/src/Module/Api/Mastodon/Accounts.php b/src/Module/Api/Mastodon/Accounts.php index 0d48744a40..6b88b84ef3 100644 --- a/src/Module/Api/Mastodon/Accounts.php +++ b/src/Module/Api/Mastodon/Accounts.php @@ -1,6 +1,6 @@ RecordNotFound(); + $uid = self::getCurrentUserID(); + + if (empty($this->parameters['id']) && empty($this->parameters['name'])) { + $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); } - $id = $parameters['id']; - if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + if (!empty($this->parameters['id'])) { + $id = $this->parameters['id']; + if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + } + } else { + $contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]); + if (!empty($contact['id'])) { + $id = $contact['id']; + } elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) { + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + } } - $account = DI::mstdnAccount()->createFromContactId($id, self::getCurrentUserID()); - System::jsonExit($account); + $account = DI::mstdnAccount()->createFromContactId($id, $uid); + $this->jsonExit($account); } }