فهرست منبع

Update AdminController

Daniel Supernault 4 سال پیش
والد
کامیت
6d078377f1
2فایلهای تغییر یافته به همراه60 افزوده شده و 5 حذف شده
  1. 6 0
      app/Http/Controllers/AdminController.php
  2. 54 5
      app/Util/Sentiment/Bouncer.php

+ 6 - 0
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');
 	}
 

+ 54 - 5
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);
 	}
 
 }