From aa5233f526707868683e2ec7fa5997bf660e3952 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 30 Jul 2019 18:42:42 -0100 Subject: [PATCH] new route tags/search Signed-off-by: Maxence Lange --- appinfo/routes.php | 1 + lib/Controller/LocalController.php | 44 +++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 85578a5d..cc94f93c 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -96,6 +96,7 @@ return [ ['name' => 'Local#globalActorInfo', 'url' => '/api/v1/global/actor/info', 'verb' => 'GET'], ['name' => 'Local#globalActorAvatar', 'url' => '/api/v1/global/actor/avatar', 'verb' => 'GET'], ['name' => 'Local#globalAccountsSearch', 'url' => '/api/v1/global/accounts/search', 'verb' => 'GET'], + ['name' => 'Local#globalTagsSearch', 'url' => '/api/v1/global/tags/search', 'verb' => 'GET'], // ['name' => 'Local#documentsCache', 'url' => '/api/v1/documents/cache', 'verb' => 'POST'], diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index 69a1a720..85ca430c 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -45,6 +45,7 @@ use OCA\Social\Service\BoostService; use OCA\Social\Service\CacheActorService; use OCA\Social\Service\DocumentService; use OCA\Social\Service\FollowService; +use OCA\Social\Service\HashtagService; use OCA\Social\Service\LikeService; use OCA\Social\Service\MiscService; use OCA\Social\Service\NoteService; @@ -76,6 +77,9 @@ class LocalController extends Controller { /** @var CacheActorService */ private $cacheActorService; + /** @var HashtagService */ + private $hashtagService; + /** @var FollowService */ private $followService; @@ -115,6 +119,7 @@ class LocalController extends Controller { * @param string $userId * @param AccountService $accountService * @param CacheActorService $cacheActorService + * @param HashtagService $hashtagService * @param FollowService $followService * @param PostService $postService * @param NoteService $noteService @@ -126,7 +131,8 @@ class LocalController extends Controller { */ public function __construct( IRequest $request, $userId, AccountService $accountService, - CacheActorService $cacheActorService, FollowService $followService, + CacheActorService $cacheActorService, HashtagService $hashtagService, + FollowService $followService, PostService $postService, NoteService $noteService, SearchService $searchService, BoostService $boostService, LikeService $likeService, DocumentService $documentService, MiscService $miscService @@ -135,6 +141,7 @@ class LocalController extends Controller { $this->userId = $userId; $this->cacheActorService = $cacheActorService; + $this->hashtagService = $hashtagService; $this->accountService = $accountService; $this->noteService = $noteService; $this->searchService = $searchService; @@ -760,6 +767,41 @@ class LocalController extends Controller { } /* Look for an exactly matching account */ + $match = null; + try { + $match = $this->hashtagService->getHashtag($search); + } catch (Exception $e) { + } + + try { + $tags = $this->hashtagService->searchHashtags($search); + + return $this->success(['tags' => $tags, 'exact' => $match]); + } catch (Exception $e) { + return $this->fail($e); + } + } + + + /** + * @NoAdminRequired + * + * @param string $search + * + * @return DataResponse + * @throws Exception + */ + public function globalTagsSearch(string $search): DataResponse { + $this->initViewer(); + + if (substr($search, 0, 1) === '#') { + $search = substr($search, 1); + } + + if ($search === '') { + return $this->success(['accounts' => [], 'exact' => []]); + } + $match = null; try { $match = $this->cacheActorService->getFromAccount($search, false);