diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index f0583a5ce..e492bd1cb 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -139,6 +139,9 @@ class AdminController extends Controller $appeal->appeal_handled_at = now(); $appeal->save(); + Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $status->profile_id); + Cache::forget('pf:bouncer_v0:recent_by_pid:' . $status->profile_id); + return redirect('/i/admin/reports/autospam'); } @@ -151,6 +154,9 @@ class AdminController extends Controller $appeal->appeal_handled_at = now(); $appeal->save(); + Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $status->profile_id); + Cache::forget('pf:bouncer_v0:recent_by_pid:' . $status->profile_id); + return redirect('/i/admin/reports/autospam'); } diff --git a/app/Util/Sentiment/Bouncer.php b/app/Util/Sentiment/Bouncer.php index 30df941bd..5841cb4d1 100644 --- a/app/Util/Sentiment/Bouncer.php +++ b/app/Util/Sentiment/Bouncer.php @@ -15,12 +15,50 @@ class Bouncer { return; } - $recentKey = 'pf:bouncer:recent_by_pid:' . $status->profile_id; - $recentTtl = now()->addMinutes(5); - $recent = Cache::remember($recentKey, $recentTtl, function() use($status) { - return $status->profile->created_at->gt(now()->subMonths(2)) || $status->profile->statuses()->count() == 0; + $exemptionKey = 'pf:bouncer_v0:exemption_by_pid:' . $status->profile_id; + $exemptionTtl = now()->addDays(12); + + $exemption = Cache::remember($exemptionKey, $exemptionTtl, function() use($status) { + $uid = $status->profile->user_id; + $ids = AccountInterstitial::whereUserId($uid) + ->whereType('post.autospam') + ->whereItemType('App\Status') + ->whereNotNull('appeal_handled_at') + ->latest() + ->take(5) + ->pluck('item_id'); + + if($ids->count() == 0) { + return false; + } + + $count = Status::select('id', 'scope') + ->whereScope('public') + ->find($ids) + ->count(); + + return $count >= 1 ? true : false; }); + if($exemption == true) { + return; + } + + $recentKey = 'pf:bouncer_v0:recent_by_pid:' . $status->profile_id; + $recentTtl = now()->addHours(28); + + $recent = Cache::remember($recentKey, $recentTtl, function() use($status) { + return $status + ->profile + ->created_at + ->gt(now()->subMonths(6)) || + $status + ->profile + ->statuses() + ->whereScope('public') + ->count() == 0; + }); + if(!$recent) { return; } @@ -29,7 +67,16 @@ class Bouncer { return; } - if(!Str::contains($status->caption, ['https://', 'http://', 'hxxps://', 'hxxp://', 'www.', '.com', '.net', '.org'])) { + if(!Str::contains($status->caption, [ + 'https://', + 'http://', + 'hxxps://', + 'hxxp://', + 'www.', + '.com', + '.net', + '.org' + ])) { return; } @@ -74,6 +121,8 @@ class Bouncer { $status->is_nsfw = true; $status->save(); + Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $status->profile_id); + Cache::forget('pf:bouncer_v0:recent_by_pid:' . $status->profile_id); } } \ No newline at end of file