From b7322b68740038fe67925da1e4815f0ae344f15d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 6 Apr 2024 01:22:52 -0600 Subject: [PATCH] Update PrivacySettings controller, refresh RelationshipService when unmute/unblocking --- .../Controllers/Settings/PrivacySettings.php | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/Settings/PrivacySettings.php b/app/Http/Controllers/Settings/PrivacySettings.php index 6509071e0..f4cc07178 100644 --- a/app/Http/Controllers/Settings/PrivacySettings.php +++ b/app/Http/Controllers/Settings/PrivacySettings.php @@ -2,23 +2,17 @@ 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; +use App\Services\RelationshipService; use App\UserFilter; -use App\Util\Lexer\PrettyNumber; -use App\Util\ActivityPub\Helpers; -use Auth, Cache, DB; +use Auth; +use Cache; +use DB; use Illuminate\Http\Request; -use App\Models\UserDomainBlock; trait PrivacySettings { - public function privacy() { $user = Auth::user(); @@ -35,13 +29,13 @@ trait PrivacySettings $settings = $request->user()->settings; $profile = $request->user()->profile; $fields = [ - 'is_private', - 'crawlable', - 'public_dm', - 'show_profile_follower_count', - 'show_profile_following_count', - 'indexable', - 'show_atom', + 'is_private', + 'crawlable', + 'public_dm', + 'show_profile_follower_count', + 'show_profile_following_count', + 'indexable', + 'show_atom', ]; $profile->indexable = $request->input('indexable') == 'on'; @@ -67,7 +61,7 @@ trait PrivacySettings } else { $settings->{$field} = true; } - } elseif ($field == 'public_dm') { + } elseif ($field == 'public_dm') { if ($form == 'on') { $settings->{$field} = true; } else { @@ -85,33 +79,35 @@ trait PrivacySettings $settings->save(); } $pid = $profile->id; - Cache::forget('profile:settings:' . $pid); - Cache::forget('user:account:id:' . $profile->user_id); - Cache::forget('profile:follower_count:' . $pid); - Cache::forget('profile:following_count:' . $pid); - Cache::forget('profile:atom:enabled:' . $pid); - Cache::forget('profile:embed:' . $pid); - Cache::forget('pf:acct:settings:hidden-followers:' . $pid); - Cache::forget('pf:acct:settings:hidden-following:' . $pid); - Cache::forget('pf:acct-trans:hideFollowing:' . $pid); - Cache::forget('pf:acct-trans:hideFollowers:' . $pid); - Cache::forget('pfc:cached-user:wt:' . strtolower($profile->username)); - Cache::forget('pfc:cached-user:wot:' . strtolower($profile->username)); + Cache::forget('profile:settings:'.$pid); + Cache::forget('user:account:id:'.$profile->user_id); + Cache::forget('profile:follower_count:'.$pid); + Cache::forget('profile:following_count:'.$pid); + Cache::forget('profile:atom:enabled:'.$pid); + Cache::forget('profile:embed:'.$pid); + Cache::forget('pf:acct:settings:hidden-followers:'.$pid); + Cache::forget('pf:acct:settings:hidden-following:'.$pid); + Cache::forget('pf:acct-trans:hideFollowing:'.$pid); + Cache::forget('pf:acct-trans:hideFollowers:'.$pid); + Cache::forget('pfc:cached-user:wt:'.strtolower($profile->username)); + Cache::forget('pfc:cached-user:wot:'.strtolower($profile->username)); + return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!'); } public function mutedUsers() - { + { $pid = Auth::user()->profile->id; $ids = (new UserFilter())->mutedUserIds($pid); $users = Profile::whereIn('id', $ids)->simplePaginate(15); + return view('settings.privacy.muted', compact('users')); } public function mutedUsersUpdate(Request $request) - { + { $this->validate($request, [ - 'profile_id' => 'required|integer|min:1' + 'profile_id' => 'required|integer|min:1', ]); $fid = $request->input('profile_id'); $pid = Auth::user()->profile->id; @@ -123,6 +119,8 @@ trait PrivacySettings ->firstOrFail(); $filter->delete(); }); + RelationshipService::refresh($pid, $fid); + return redirect()->back(); } @@ -131,14 +129,14 @@ trait PrivacySettings $pid = Auth::user()->profile->id; $ids = (new UserFilter())->blockedUserIds($pid); $users = Profile::whereIn('id', $ids)->simplePaginate(15); + return view('settings.privacy.blocked', compact('users')); } - public function blockedUsersUpdate(Request $request) - { + { $this->validate($request, [ - 'profile_id' => 'required|integer|min:1' + 'profile_id' => 'required|integer|min:1', ]); $fid = $request->input('profile_id'); $pid = Auth::user()->profile->id; @@ -150,6 +148,8 @@ trait PrivacySettings ->firstOrFail(); $filter->delete(); }); + RelationshipService::refresh($pid, $fid); + return redirect()->back(); } @@ -194,7 +194,7 @@ trait PrivacySettings $profile = Auth::user()->profile; $settings = Auth::user()->settings; - if($mode !== 'keep-all') { + if ($mode !== 'keep-all') { switch ($mode) { case 'mutual-only': $following = $profile->following()->pluck('profiles.id'); @@ -209,9 +209,9 @@ trait PrivacySettings case 'remove-all': Follower::whereFollowingId($profile->id)->delete(); break; - + default: - # code... + // code... break; } } @@ -221,6 +221,7 @@ trait PrivacySettings $settings->save(); $profile->save(); Cache::forget('profiles:private'); + return [200]; } }