From d34224f21612b8affb65e09941a24346aa187043 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 26 Jun 2019 19:58:39 -0600 Subject: [PATCH] Update PrivacySettings --- .../Controllers/Settings/PrivacySettings.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/app/Http/Controllers/Settings/PrivacySettings.php b/app/Http/Controllers/Settings/PrivacySettings.php index 8e987ab6..99f7d410 100644 --- a/app/Http/Controllers/Settings/PrivacySettings.php +++ b/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]; + } } \ No newline at end of file