diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-12-02 09:56:56 -0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2018-12-03 07:15:15 +0100 |
commit | bf4575799708cddf9ff0dfdb7d7531db27c4cbd1 (patch) | |
tree | 0b62df05551cd79638a9787aee5d0a05d54c0ec3 /lib/Controller/LocalController.php | |
parent | a6e705671e36fef0859dee30e5287eb438133da4 (diff) |
routes and methods
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Controller/LocalController.php')
-rw-r--r-- | lib/Controller/LocalController.php | 112 |
1 files changed, 81 insertions, 31 deletions
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index cc37a5eb..69bd259e 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -294,32 +294,16 @@ class LocalController extends Controller { * @NoAdminRequired * @NoSubAdminRequired * - * @param string $search + * @param string $account * * @return DataResponse - * @throws Exception */ - public function accountsSearch(string $search): DataResponse { - try { - $viewer = $this->actorService->getActorFromUserId($this->userId, true); - } catch (Exception $e) { - throw new Exception(); - } - - $this->personService->setViewerId($viewer->getId()); - - /* Look for an exactly matching account */ - $match = null; - try { - $match = $this->personService->getFromAccount($search, false); - $match->setCompleteDetails(true); - } catch (Exception $e) { - } - + public function actionFollow(string $account): DataResponse { try { - $accounts = $this->personService->searchCachedAccounts($search); + $actor = $this->actorService->getActorFromUserId($this->userId); + $this->followService->followAccount($actor, $account); - return $this->success(['accounts' => $accounts, 'exact' => $match]); + return $this->success([]); } catch (Exception $e) { return $this->fail($e); } @@ -338,10 +322,10 @@ class LocalController extends Controller { * * @return DataResponse */ - public function accountFollow(string $account): DataResponse { + public function actionUnfollow(string $account): DataResponse { try { $actor = $this->actorService->getActorFromUserId($this->userId); - $this->followService->followAccount($actor, $account); + $this->followService->unfollowAccount($actor, $account); return $this->success([]); } catch (Exception $e) { @@ -358,16 +342,14 @@ class LocalController extends Controller { * @NoAdminRequired * @NoSubAdminRequired * - * @param string $account - * * @return DataResponse */ - public function accountUnfollow(string $account): DataResponse { + public function currentInfo(): DataResponse { try { $actor = $this->actorService->getActorFromUserId($this->userId); - $this->followService->unfollowAccount($actor, $account); + $actor = $this->personService->getFromLocalAccount($actor->getPreferredUsername()); - return $this->success([]); + return $this->success(['account' => $actor]); } catch (Exception $e) { return $this->fail($e); } @@ -413,10 +395,36 @@ class LocalController extends Controller { /** + * + * // TODO: Delete the NoCSRF check + * * @NoCSRFRequired * @NoAdminRequired * @NoSubAdminRequired * + * @param string $username + * + * @return DataResponse + */ + public function accountInfo(string $username): DataResponse { + try { + $actor = $this->actorService->getActor($username); + $actor = $this->personService->getFromLocalAccount($actor->getPreferredUsername()); + + return $this->success(['account' => $actor]); + } catch (Exception $e) { + return $this->fail($e); + } + } + + + /** + * @NoCSRFRequired + * @NoAdminRequired + * @NoSubAdminRequired + * + * @param string $username + * * @return DataResponse */ public function accountFollowers(string $username): DataResponse { @@ -436,6 +444,8 @@ class LocalController extends Controller { * @NoAdminRequired * @NoSubAdminRequired * + * @param string $username + * * @return DataResponse */ public function accountFollowing(string $username): DataResponse { @@ -462,7 +472,7 @@ class LocalController extends Controller { * * @return DataResponse */ - public function accountInfo(string $account): DataResponse { + public function globalAccountInfo(string $account): DataResponse { try { $actor = $this->personService->getFromAccount($account); @@ -485,7 +495,7 @@ class LocalController extends Controller { * * @return DataResponse */ - public function actorInfo(string $id): DataResponse { + public function globalActorInfo(string $id): DataResponse { try { $actor = $this->personService->getFromId($id); @@ -504,7 +514,7 @@ class LocalController extends Controller { * * @return DataResponse */ - public function actorAvatar(string $id): Response { + public function globalActorAvatar(string $id): Response { try { $actor = $this->personService->getFromId($id); if ($actor->gotIcon()) { @@ -522,6 +532,46 @@ class LocalController extends Controller { /** + * + * // TODO: Delete the NoCSRF check + * + * @NoCSRFRequired + * @NoAdminRequired + * @NoSubAdminRequired + * + * @param string $search + * + * @return DataResponse + * @throws Exception + */ + public function globalAccountsSearch(string $search): DataResponse { + try { + $viewer = $this->actorService->getActorFromUserId($this->userId, true); + } catch (Exception $e) { + throw new Exception(); + } + + $this->personService->setViewerId($viewer->getId()); + + /* Look for an exactly matching account */ + $match = null; + try { + $match = $this->personService->getFromAccount($search, false); + $match->setCompleteDetails(true); + } catch (Exception $e) { + } + + try { + $accounts = $this->personService->searchCachedAccounts($search); + + return $this->success(['accounts' => $accounts, 'exact' => $match]); + } catch (Exception $e) { + return $this->fail($e); + } + } + + + /** * // TODO: Delete the NoCSRF check * * @NoCSRFRequired |