Browse Source

Update PrivacySettings

Daniel Supernault 6 năm trước cách đây
mục cha
commit
d34224f216
1 tập tin đã thay đổi với 44 bổ sung0 xóa
  1. 44 0
      app/Http/Controllers/Settings/PrivacySettings.php

+ 44 - 0
app/Http/Controllers/Settings/PrivacySettings.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Settings;
 use App\AccountLog;
 use App\EmailVerification;
 use App\Instance;
+use App\Follower;
 use App\Media;
 use App\Profile;
 use App\User;
@@ -170,4 +171,47 @@ trait PrivacySettings
     {
         return view('settings.privacy.blocked-keywords');
     }
+
+    public function privateAccountOptions(Request $request)
+    {
+        $this->validate($request, [
+            'mode' => 'required|string|in:keep-all,mutual-only,only-followers,remove-all',
+            'duration' => 'required|integer|min:60|max:525600',
+        ]);
+        $mode = $request->input('mode');
+        $duration = $request->input('duration');
+        // $newRequests = $request->input('newrequests');
+
+        $profile = Auth::user()->profile;
+        $settings = Auth::user()->settings;
+
+        if($mode !== 'keep-all') {
+            switch ($mode) {
+                case 'mutual-only':
+                    $following = $profile->following()->pluck('profiles.id');
+                    Follower::whereFollowingId($profile->id)->whereNotIn('profile_id', $following)->delete();
+                    break;
+
+                case 'only-followers':
+                    $ts = now()->subMinutes($duration);
+                    Follower::whereFollowingId($profile->id)->where('created_at', '>', $ts)->delete();
+                    break;
+
+                case 'remove-all':
+                    Follower::whereFollowingId($profile->id)->delete();
+                    break;
+                
+                default:
+                    # code...
+                    break;
+            }
+        }
+        $profile->is_private = true;
+        $settings->show_guests = false;
+        $settings->show_discover = false;
+        $settings->save();
+        $profile->save();
+        Cache::forget('profiles:private');
+        return [200];
+    }
 }