2018-05-26 22:49:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-09-22 05:23:16 +00:00
|
|
|
use App\{
|
|
|
|
Follower,
|
|
|
|
Hashtag,
|
|
|
|
Profile,
|
|
|
|
Status,
|
|
|
|
UserFilter
|
|
|
|
};
|
|
|
|
use Auth, DB, Cache;
|
2018-08-28 03:07:36 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-05-26 22:49:39 +00:00
|
|
|
|
|
|
|
class DiscoverController extends Controller
|
|
|
|
{
|
2018-05-30 03:04:26 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
$this->middleware('auth');
|
2018-05-30 03:04:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 05:31:21 +00:00
|
|
|
public function home(Request $request)
|
2018-05-26 22:49:39 +00:00
|
|
|
{
|
2018-09-22 05:31:21 +00:00
|
|
|
$this->validate($request, [
|
|
|
|
'page' => 'nullable|integer|max:50'
|
|
|
|
]);
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
$pid = Auth::user()->profile->id;
|
2018-08-10 02:58:52 +00:00
|
|
|
|
2018-09-22 05:23:16 +00:00
|
|
|
$following = Cache::remember('feature:discover:following:'.$pid, 15, function() use($pid) {
|
|
|
|
$following = Follower::whereProfileId($pid)
|
2018-08-10 02:58:52 +00:00
|
|
|
->pluck('following_id');
|
2018-09-22 05:23:16 +00:00
|
|
|
$filtered = UserFilter::whereUserId($pid)
|
|
|
|
->whereFilterableType('App\Profile')
|
|
|
|
->whereIn('filter_type', ['mute', 'block'])
|
|
|
|
->pluck('filterable_id');
|
|
|
|
$following->push($pid);
|
|
|
|
|
|
|
|
if($filtered->count() > 0) {
|
|
|
|
$following->push($filtered);
|
|
|
|
}
|
|
|
|
return $following;
|
|
|
|
});
|
2018-08-31 04:18:43 +00:00
|
|
|
|
2018-09-22 05:23:16 +00:00
|
|
|
$people = Cache::remember('feature:discover:people:'.$pid, 15, function() use($following) {
|
|
|
|
return Profile::inRandomOrder()
|
|
|
|
->whereHas('statuses')
|
|
|
|
->whereNull('domain')
|
|
|
|
->whereNotIn('id', $following)
|
|
|
|
->whereIsPrivate(false)
|
|
|
|
->take(3)
|
|
|
|
->get();
|
|
|
|
});
|
2018-08-10 02:58:52 +00:00
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
$posts = Status::whereHas('media')
|
2018-09-22 05:23:16 +00:00
|
|
|
->whereHas('profile', function($q) {
|
|
|
|
$q->where('is_private', false);
|
|
|
|
})
|
2018-09-22 05:31:21 +00:00
|
|
|
->whereIsNsfw(false)
|
2018-09-09 02:42:35 +00:00
|
|
|
->whereVisibility('public')
|
2018-08-10 02:58:52 +00:00
|
|
|
->where('profile_id', '!=', $pid)
|
|
|
|
->whereNotIn('profile_id', $following)
|
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
->simplePaginate(21);
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
return view('discover.home', compact('people', 'posts'));
|
2018-05-26 22:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function showTags(Request $request, $hashtag)
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
$this->validate($request, [
|
|
|
|
'page' => 'nullable|integer|min:1|max:10',
|
2018-08-10 02:58:52 +00:00
|
|
|
]);
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
$tag = Hashtag::with('posts')
|
2018-08-10 02:58:52 +00:00
|
|
|
->withCount('posts')
|
|
|
|
->whereSlug($hashtag)
|
|
|
|
->firstOrFail();
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
$posts = $tag->posts()
|
2018-08-10 02:58:52 +00:00
|
|
|
->whereIsNsfw(false)
|
|
|
|
->whereVisibility('public')
|
|
|
|
->has('media')
|
2018-08-28 03:07:36 +00:00
|
|
|
->orderBy('id', 'desc')
|
2018-08-10 02:58:52 +00:00
|
|
|
->simplePaginate(12);
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
return view('discover.tags.show', compact('tag', 'posts'));
|
2018-05-26 22:49:39 +00:00
|
|
|
}
|
|
|
|
}
|