Update DiscoverController

This commit is contained in:
Daniel Supernault 2019-07-08 00:04:02 -06:00
parent e8b2eb6394
commit 5b713a1e0f
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -6,6 +6,7 @@ use App\{
DiscoverCategory, DiscoverCategory,
Follower, Follower,
Hashtag, Hashtag,
HashtagFollow,
Profile, Profile,
Status, Status,
StatusHashtag, StatusHashtag,
@ -37,7 +38,8 @@ class DiscoverController extends Controller
public function showTags(Request $request, $hashtag) public function showTags(Request $request, $hashtag)
{ {
abort_if(!Auth::check(), 403); abort_if(!config('instance.discover.tags.is_public') && !Auth::check(), 403);
$tag = Hashtag::whereSlug($hashtag)->firstOrFail(); $tag = Hashtag::whereSlug($hashtag)->firstOrFail();
$tagCount = StatusHashtagService::count($tag->id); $tagCount = StatusHashtagService::count($tag->id);
return view('discover.tags.show', compact('tag', 'tagCount')); return view('discover.tags.show', compact('tag', 'tagCount'));
@ -127,10 +129,12 @@ class DiscoverController extends Controller
public function getHashtags(Request $request) public function getHashtags(Request $request)
{ {
abort_if(!Auth::check(), 403); $auth = Auth::check();
abort_if(!config('instance.discover.tags.is_public') && $auth, 403);
$this->validate($request, [ $this->validate($request, [
'hashtag' => 'required|alphanum|min:2|max:124', 'hashtag' => 'required|alphanum|min:2|max:124',
'page' => 'nullable|integer|min:1|max:19' 'page' => 'nullable|integer|min:1|max:' . ($auth ? 19 : 3)
]); ]);
$page = $request->input('page') ?? '1'; $page = $request->input('page') ?? '1';
@ -138,7 +142,10 @@ class DiscoverController extends Controller
$tag = $request->input('hashtag'); $tag = $request->input('hashtag');
$hashtag = Hashtag::whereName($tag)->firstOrFail(); $hashtag = Hashtag::whereName($tag)->firstOrFail();
$res = StatusHashtagService::get($hashtag->id, $page, $end); $res['tags'] = StatusHashtagService::get($hashtag->id, $page, $end);
if($page == 1) {
$res['follows'] = HashtagFollow::whereUserId(Auth::id())->whereHashtagId($hashtag->id)->exists();
}
return $res; return $res;
} }
} }