From ec0e6253a78d8fb1f286ee80a2a9166c3ce71a85 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 5 Dec 2018 10:38:16 -0100 Subject: [PATCH 1/2] cleaning & fixing Signed-off-by: Maxence Lange --- lib/Controller/LocalController.php | 14 +++++++++++--- lib/Db/ActorsRequest.php | 1 + lib/Model/ActivityPub/Person.php | 4 ++++ lib/Service/ActivityPub/PersonService.php | 2 ++ lib/Service/ActivityService.php | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index 2e31350a..8ba1c6f7 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -465,9 +465,9 @@ class LocalController extends Controller { * @return DataResponse */ public function accountFollowers(string $username): DataResponse { - $this->initViewer(); - try { + $this->initViewer(); + $actor = $this->actorService->getActor($username); $followers = $this->followService->getFollowers($actor); @@ -574,7 +574,7 @@ class LocalController extends Controller { throw new InvalidResourceException('no avatar for this Actor'); } } catch (Exception $e) { - return $this->fail($e, [], Http::STATUS_NOT_FOUND); + return $this->fail($e, [], Http::STATUS_NOT_FOUND, false); } } @@ -595,6 +595,14 @@ class LocalController extends Controller { public function globalAccountsSearch(string $search): DataResponse { $this->initViewer(); + if (substr($search, 0, 1) === '@') { + $search = substr($search, 1); + } + + if ($search === '') { + return $this->success(['accounts' => [], 'exact' => []]); + } + /* Look for an exactly matching account */ $match = null; try { diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php index 00572296..30673b5a 100644 --- a/lib/Db/ActorsRequest.php +++ b/lib/Db/ActorsRequest.php @@ -97,6 +97,7 @@ class ActorsRequest extends ActorsRequestBuilder { public function getFromUsername(string $username): Person { $qb = $this->getActorsSelectSql(); $this->limitToPreferredUsername($qb, $username); + $this->limitToLocal($qb, true); $cursor = $qb->execute(); $data = $cursor->fetch(); diff --git a/lib/Model/ActivityPub/Person.php b/lib/Model/ActivityPub/Person.php index 91c584cf..6b40e0b0 100644 --- a/lib/Model/ActivityPub/Person.php +++ b/lib/Model/ActivityPub/Person.php @@ -246,6 +246,10 @@ class Person extends ACore implements JsonSerializable { * @return Person */ public function setAccount(string $account): Person { + if ($account !== '' && substr($account, 0, 1) === '@') { + $account = substr($account, 1); + } + $this->account = $account; return $this; diff --git a/lib/Service/ActivityPub/PersonService.php b/lib/Service/ActivityPub/PersonService.php index a3a6432d..9f0bd0f3 100644 --- a/lib/Service/ActivityPub/PersonService.php +++ b/lib/Service/ActivityPub/PersonService.php @@ -38,6 +38,7 @@ use OCA\Social\Db\CacheActorsRequest; use OCA\Social\Db\CacheDocumentsRequest; use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Exceptions\CacheDocumentDoesNotExistException; +use OCA\Social\Exceptions\InvalidResourceEntryException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\Request410Exception; use OCA\Social\Exceptions\RequestException; @@ -227,6 +228,7 @@ class PersonService implements ICoreService { * @throws InvalidResourceException * @throws SocialAppConfigException * @throws UrlCloudException + * @throws InvalidResourceEntryException */ private function generateActorFromObject(array $object) { diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php index 8e094e56..45f3aa20 100644 --- a/lib/Service/ActivityService.php +++ b/lib/Service/ActivityService.php @@ -543,7 +543,7 @@ class ActivityService { $target = ''; try { - $target = strtolower($request->getMethod()) . " " . $request->getPathInfo(); + $target = strtolower($request->getMethod()) . " " . $request->getRequestUri(); } catch (Exception $e) { } From dd2d591b68acf27e56025e1b3fcac040c4e1ce4f Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 5 Dec 2018 10:54:19 -0100 Subject: [PATCH 2/2] nevermind, regression Signed-off-by: Maxence Lange --- lib/Db/ActorsRequest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php index 30673b5a..00572296 100644 --- a/lib/Db/ActorsRequest.php +++ b/lib/Db/ActorsRequest.php @@ -97,7 +97,6 @@ class ActorsRequest extends ActorsRequestBuilder { public function getFromUsername(string $username): Person { $qb = $this->getActorsSelectSql(); $this->limitToPreferredUsername($qb, $username); - $this->limitToLocal($qb, true); $cursor = $qb->execute(); $data = $cursor->fetch();