Skip to content

Commit

Permalink
Update PublicApiController, use fUserFilterService in public timeline…
Browse files Browse the repository at this point in the history
… endpoint
  • Loading branch information
dansup committed Jul 16, 2021
1 parent 2fe676a commit ca6e491
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions app/Http/Controllers/PublicApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,7 @@ public function publicTimelineApi(Request $request)
$limit = $request->input('limit') ?? 3;
$user = $request->user();

$filtered = UserFilter::whereUserId($user->profile_id)
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id')->toArray();
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];

if($min || $max) {
$dir = $min ? '>' : '<';
Expand All @@ -305,7 +302,8 @@ public function publicTimelineApi(Request $request)
'type',
'scope',
'local'
)->where('id', $dir, $id)
)
->where('id', $dir, $id)
->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotIn('profile_id', $filtered)
->whereLocal(true)
Expand Down Expand Up @@ -339,7 +337,8 @@ public function publicTimelineApi(Request $request)
'likes_count',
'reblogs_count',
'updated_at'
)->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
)
->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotIn('profile_id', $filtered)
->with('profile', 'hashtags', 'mentions')
->whereLocal(true)
Expand Down Expand Up @@ -378,14 +377,14 @@ public function homeTimelineApi(Request $request)
$user = $request->user();

$key = 'user:last_active_at:id:'.$user->id;
$ttl = now()->addMinutes(5);
$ttl = now()->addMinutes(20);
Cache::remember($key, $ttl, function() use($user) {
$user->last_active_at = now();
$user->save();
return;
});

$pid = Auth::user()->profile_id;
$pid = $user->profile_id;

$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
$following = Follower::whereProfileId($pid)->pluck('following_id');
Expand All @@ -401,7 +400,7 @@ public function homeTimelineApi(Request $request)
});
}

$filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];

if($min || $max) {
$dir = $min ? '>' : '<';
Expand All @@ -425,7 +424,8 @@ public function homeTimelineApi(Request $request)
'reblogs_count',
'created_at',
'updated_at'
)->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
)
->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->with('profile', 'hashtags', 'mentions')
->where('id', $dir, $id)
->whereIn('profile_id', $following)
Expand Down Expand Up @@ -454,7 +454,8 @@ public function homeTimelineApi(Request $request)
'reblogs_count',
'created_at',
'updated_at'
)->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
)
->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->with('profile', 'hashtags', 'mentions')
->whereIn('profile_id', $following)
->whereNotIn('profile_id', $filtered)
Expand Down Expand Up @@ -495,6 +496,8 @@ public function networkTimelineApi(Request $request)
return;
});

$filtered = $user ? UserFilterService::filters($user->profile_id) : [];

if($min || $max) {
$dir = $min ? '>' : '<';
$id = $min ?? $max;
Expand All @@ -504,7 +507,9 @@ public function networkTimelineApi(Request $request)
'type',
'scope',
'created_at',
)->where('id', $dir, $id)
)
->where('id', $dir, $id)
->whereNotIn('profile_id', $filtered)
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotNull('uri')
->whereScope('public')
Expand All @@ -525,7 +530,9 @@ public function networkTimelineApi(Request $request)
'type',
'scope',
'created_at',
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
)
->whereNotIn('profile_id', $filtered)
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotNull('uri')
->whereScope('public')
->where('id', '>', $amin)
Expand Down

0 comments on commit ca6e491

Please sign in to comment.