Update PublicApiController, implement UserFilterService in timeline methods

pull/1661/head
Daniel Supernault 6 years ago
parent 66d6dfd189
commit 6dc8f140bd
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7

@ -22,6 +22,7 @@ use App\Transformer\Api\{
RelationshipTransformer, RelationshipTransformer,
StatusTransformer, StatusTransformer,
}; };
use App\Services\UserFilterService;
use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Jobs\StatusPipeline\NewStatusPipeline;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Pagination\IlluminatePaginatorAdapter;
@ -234,23 +235,27 @@ class PublicApiController extends Controller
$max = $request->input('max_id'); $max = $request->input('max_id');
$limit = $request->input('limit') ?? 3; $limit = $request->input('limit') ?? 3;
$private = Cache::remember('profiles:private', now()->addMinutes(1440), function() { // $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
return Profile::whereIsPrivate(true) // return Profile::whereIsPrivate(true)
->orWhere('unlisted', true) // ->orWhere('unlisted', true)
->orWhere('status', '!=', null) // ->orWhere('status', '!=', null)
->pluck('id'); // ->pluck('id');
}); // });
if(Auth::check()) { // if(Auth::check()) {
$pid = Auth::user()->profile->id; // // $pid = Auth::user()->profile->id;
$filters = UserFilter::whereUserId($pid) // // $filters = UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile') // // ->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block']) // // ->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id')->toArray(); // // ->pluck('filterable_id')->toArray();
$filtered = array_merge($private->toArray(), $filters); // // $filtered = array_merge($private->toArray(), $filters);
} else { // $filtered = UserFilterService::filters(Auth::user()->profile_id);
$filtered = $private->toArray(); // } else {
} // // $filtered = $private->toArray();
// $filtered = [];
// }
$filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
if($min || $max) { if($min || $max) {
$dir = $min ? '>' : '<'; $dir = $min ? '>' : '<';
@ -276,14 +281,12 @@ class PublicApiController extends Controller
->with('profile', 'hashtags', 'mentions') ->with('profile', 'hashtags', 'mentions')
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album']) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
->whereLocal(true) ->whereLocal(true)
->whereNull('uri')
->whereNotIn('profile_id', $filtered) ->whereNotIn('profile_id', $filtered)
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereVisibility('public') ->whereVisibility('public')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit($limit) ->limit($limit)
->get(); ->get();
//->toSql();
} else { } else {
$timeline = Status::select( $timeline = Status::select(
'id', 'id',
@ -305,17 +308,16 @@ class PublicApiController extends Controller
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album']) )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
->with('profile', 'hashtags', 'mentions') ->with('profile', 'hashtags', 'mentions')
->whereLocal(true) ->whereLocal(true)
->whereNull('uri')
->whereNotIn('profile_id', $filtered) ->whereNotIn('profile_id', $filtered)
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereVisibility('public') ->whereVisibility('public')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->simplePaginate($limit); ->simplePaginate($limit);
//->toSql();
} }
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer()); $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
$res = $this->fractal->createData($fractal)->toArray(); $res = $this->fractal->createData($fractal)->toArray();
// $res = $timeline;
return response()->json($res); return response()->json($res);
} }
@ -347,20 +349,22 @@ class PublicApiController extends Controller
return $following->push($pid)->toArray(); return $following->push($pid)->toArray();
}); });
$private = Cache::remember('profiles:private', now()->addMinutes(1440), function() { // $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
return Profile::whereIsPrivate(true) // return Profile::whereIsPrivate(true)
->orWhere('unlisted', true) // ->orWhere('unlisted', true)
->orWhere('status', '!=', null) // ->orWhere('status', '!=', null)
->pluck('id'); // ->pluck('id');
}); // });
$private = $private->diff($following)->flatten(); // $private = $private->diff($following)->flatten();
$filters = UserFilter::whereUserId($pid) // $filters = UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile') // ->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block']) // ->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id')->toArray(); // ->pluck('filterable_id')->toArray();
$filtered = array_merge($private->toArray(), $filters); // $filtered = array_merge($private->toArray(), $filters);
$filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
if($min || $max) { if($min || $max) {
$dir = $min ? '>' : '<'; $dir = $min ? '>' : '<';
@ -387,8 +391,6 @@ class PublicApiController extends Controller
->where('id', $dir, $id) ->where('id', $dir, $id)
->whereIn('profile_id', $following) ->whereIn('profile_id', $following)
->whereNotIn('profile_id', $filtered) ->whereNotIn('profile_id', $filtered)
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereIn('visibility',['public', 'unlisted', 'private']) ->whereIn('visibility',['public', 'unlisted', 'private'])
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit($limit) ->limit($limit)
@ -415,8 +417,6 @@ class PublicApiController extends Controller
->with('profile', 'hashtags', 'mentions') ->with('profile', 'hashtags', 'mentions')
->whereIn('profile_id', $following) ->whereIn('profile_id', $following)
->whereNotIn('profile_id', $filtered) ->whereNotIn('profile_id', $filtered)
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereIn('visibility',['public', 'unlisted', 'private']) ->whereIn('visibility',['public', 'unlisted', 'private'])
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->simplePaginate($limit); ->simplePaginate($limit);

Loading…
Cancel
Save