1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-26 01:36:43 +00:00

Update DiscoverController

This commit is contained in:
Daniel Supernault 2019-07-04 20:21:20 -06:00
parent eab5fceb9f
commit 6f783cac66
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -17,6 +17,7 @@ use App\Transformer\Api\StatusStatelessTransformer;
use League\Fractal; use League\Fractal;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Services\StatusHashtagService;
class DiscoverController extends Controller class DiscoverController extends Controller
{ {
@ -37,56 +38,9 @@ class DiscoverController extends Controller
public function showTags(Request $request, $hashtag) public function showTags(Request $request, $hashtag)
{ {
abort_if(!Auth::check(), 403); abort_if(!Auth::check(), 403);
$tag = Hashtag::whereSlug($hashtag)->firstOrFail();
$tag = Hashtag::whereSlug($hashtag) $tagCount = StatusHashtagService::count($tag->id);
->firstOrFail(); return view('discover.tags.show', compact('tag', 'tagCount'));
$page = 1;
$key = 'discover:tag-'.$tag->id.':page-'.$page;
$keyMinutes = 15;
$posts = Cache::remember($key, now()->addMinutes($keyMinutes), function() use ($tag, $request) {
$tags = StatusHashtag::select('status_id')
->whereHashtagId($tag->id)
->orderByDesc('id')
->take(48)
->pluck('status_id');
return Status::select(
'id',
'uri',
'caption',
'rendered',
'profile_id',
'type',
'in_reply_to_id',
'reblog_of_id',
'is_nsfw',
'scope',
'local',
'created_at',
'updated_at'
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
->with('media')
->whereLocal(true)
->whereNull('uri')
->whereIn('id', $tags)
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereNull('url')
->whereNull('uri')
->withCount(['likes', 'comments'])
->whereIsNsfw(false)
->whereVisibility('public')
->orderBy('id', 'desc')
->get();
});
if($posts->count() == 0) {
abort(404);
}
return view('discover.tags.show', compact('tag', 'posts'));
} }
public function showCategory(Request $request, $slug) public function showCategory(Request $request, $slug)
@ -156,7 +110,6 @@ class DiscoverController extends Controller
return $res; return $res;
} }
public function loopWatch(Request $request) public function loopWatch(Request $request)
{ {
abort_if(!Auth::check(), 403); abort_if(!Auth::check(), 403);
@ -171,4 +124,21 @@ class DiscoverController extends Controller
return response()->json(200); return response()->json(200);
} }
public function getHashtags(Request $request)
{
abort_if(!Auth::check(), 403);
$this->validate($request, [
'hashtag' => 'required|alphanum|min:2|max:124',
'page' => 'nullable|integer|min:1|max:19'
]);
$page = $request->input('page') ?? '1';
$end = $page > 1 ? $page * 9 : 0;
$tag = $request->input('hashtag');
$hashtag = Hashtag::whereName($tag)->firstOrFail();
$res = StatusHashtagService::get($hashtag->id, $page, $end);
return $res;
}
} }