From a76f3b0e2e534f22c91dd08be2f5c6bfa3655388 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 23 Jul 2024 01:29:56 -0600 Subject: [PATCH] Update GroupsSearchController.php --- .../Groups/GroupsSearchController.php | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Groups/GroupsSearchController.php b/app/Http/Controllers/Groups/GroupsSearchController.php index 90cc7ccdf..560436f46 100644 --- a/app/Http/Controllers/Groups/GroupsSearchController.php +++ b/app/Http/Controllers/Groups/GroupsSearchController.php @@ -13,6 +13,8 @@ use App\Profile; use App\Models\Group; use App\Models\GroupMember; use App\Models\GroupInvitation; +use App\Util\ActivityPub\Helpers; +use App\Services\Groups\GroupActivityPubService; class GroupsSearchController extends Controller { @@ -118,32 +120,34 @@ class GroupsSearchController extends Controller { abort_if(!$request->user(), 404); $this->validate($request, [ - 'q' => 'required|min:2|max:40', + 'q' => 'required|min:2|max:140', 'v' => 'required|in:0.2' ]); $q = $request->input('q'); - $key = 'groups:search:global:by_name:' . hash('sha256', $q); - if(RateLimiter::tooManyAttempts('groups:search:global:'.$request->user()->id, 25) ) { - return response()->json([ - 'error' => [ - 'message' => 'Too many attempts, please try again later' - ] - ], 422); + if(str_starts_with($q, 'https://')) { + $res = Helpers::getSignedFetch($q); + if($res && $res = json_decode($res, true)) { + + } + if($res && isset($res['type']) && in_array($res['type'], ['Group', 'Note', 'Page'])) { + if($res['type'] === 'Group') { + return GroupActivityPubService::fetchGroup($q, true); + } + $resp = GroupActivityPubService::fetchGroupPost($q, true); + $resp['name'] = 'Group Post'; + $resp['url'] = '/groups/' . $resp['group_id'] . '/p/' . $resp['id']; + return [$resp]; + } } - - RateLimiter::hit('groups:search:global:'.$request->user()->id); - - return Cache::remember($key, 3600, function() use($q) { - return Group::whereNull('status') - ->where('name', 'like', '%' . $q . '%') - ->orderBy('id') - ->take(10) - ->pluck('id') - ->map(function($group) { - return GroupService::get($group); - }); - }); + return Group::whereNull('status') + ->where('name', 'like', '%' . $q . '%') + ->orderBy('id') + ->take(10) + ->pluck('id') + ->map(function($group) { + return GroupService::get($group); + }); } public function searchLocalAutocomplete(Request $request)