1
0
Fork 0

Update PrivacySettings controller, refresh RelationshipService when unmute/unblocking

This commit is contained in:
Daniel Supernault 2024-04-06 01:22:52 -06:00
parent 8c6936409d
commit b7322b6874
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1
1 changed files with 40 additions and 39 deletions

View File

@ -2,23 +2,17 @@
namespace App\Http\Controllers\Settings; namespace App\Http\Controllers\Settings;
use App\AccountLog;
use App\EmailVerification;
use App\Instance;
use App\Follower; use App\Follower;
use App\Media;
use App\Profile; use App\Profile;
use App\User; use App\Services\RelationshipService;
use App\UserFilter; use App\UserFilter;
use App\Util\Lexer\PrettyNumber; use Auth;
use App\Util\ActivityPub\Helpers; use Cache;
use Auth, Cache, DB; use DB;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserDomainBlock;
trait PrivacySettings trait PrivacySettings
{ {
public function privacy() public function privacy()
{ {
$user = Auth::user(); $user = Auth::user();
@ -35,13 +29,13 @@ trait PrivacySettings
$settings = $request->user()->settings; $settings = $request->user()->settings;
$profile = $request->user()->profile; $profile = $request->user()->profile;
$fields = [ $fields = [
'is_private', 'is_private',
'crawlable', 'crawlable',
'public_dm', 'public_dm',
'show_profile_follower_count', 'show_profile_follower_count',
'show_profile_following_count', 'show_profile_following_count',
'indexable', 'indexable',
'show_atom', 'show_atom',
]; ];
$profile->indexable = $request->input('indexable') == 'on'; $profile->indexable = $request->input('indexable') == 'on';
@ -67,7 +61,7 @@ trait PrivacySettings
} else { } else {
$settings->{$field} = true; $settings->{$field} = true;
} }
} elseif ($field == 'public_dm') { } elseif ($field == 'public_dm') {
if ($form == 'on') { if ($form == 'on') {
$settings->{$field} = true; $settings->{$field} = true;
} else { } else {
@ -85,33 +79,35 @@ trait PrivacySettings
$settings->save(); $settings->save();
} }
$pid = $profile->id; $pid = $profile->id;
Cache::forget('profile:settings:' . $pid); Cache::forget('profile:settings:'.$pid);
Cache::forget('user:account:id:' . $profile->user_id); Cache::forget('user:account:id:'.$profile->user_id);
Cache::forget('profile:follower_count:' . $pid); Cache::forget('profile:follower_count:'.$pid);
Cache::forget('profile:following_count:' . $pid); Cache::forget('profile:following_count:'.$pid);
Cache::forget('profile:atom:enabled:' . $pid); Cache::forget('profile:atom:enabled:'.$pid);
Cache::forget('profile:embed:' . $pid); Cache::forget('profile:embed:'.$pid);
Cache::forget('pf:acct:settings:hidden-followers:' . $pid); Cache::forget('pf:acct:settings:hidden-followers:'.$pid);
Cache::forget('pf:acct:settings:hidden-following:' . $pid); Cache::forget('pf:acct:settings:hidden-following:'.$pid);
Cache::forget('pf:acct-trans:hideFollowing:' . $pid); Cache::forget('pf:acct-trans:hideFollowing:'.$pid);
Cache::forget('pf:acct-trans:hideFollowers:' . $pid); Cache::forget('pf:acct-trans:hideFollowers:'.$pid);
Cache::forget('pfc:cached-user:wt:' . strtolower($profile->username)); Cache::forget('pfc:cached-user:wt:'.strtolower($profile->username));
Cache::forget('pfc:cached-user:wot:' . strtolower($profile->username)); Cache::forget('pfc:cached-user:wot:'.strtolower($profile->username));
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!'); return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
} }
public function mutedUsers() public function mutedUsers()
{ {
$pid = Auth::user()->profile->id; $pid = Auth::user()->profile->id;
$ids = (new UserFilter())->mutedUserIds($pid); $ids = (new UserFilter())->mutedUserIds($pid);
$users = Profile::whereIn('id', $ids)->simplePaginate(15); $users = Profile::whereIn('id', $ids)->simplePaginate(15);
return view('settings.privacy.muted', compact('users')); return view('settings.privacy.muted', compact('users'));
} }
public function mutedUsersUpdate(Request $request) public function mutedUsersUpdate(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'profile_id' => 'required|integer|min:1' 'profile_id' => 'required|integer|min:1',
]); ]);
$fid = $request->input('profile_id'); $fid = $request->input('profile_id');
$pid = Auth::user()->profile->id; $pid = Auth::user()->profile->id;
@ -123,6 +119,8 @@ trait PrivacySettings
->firstOrFail(); ->firstOrFail();
$filter->delete(); $filter->delete();
}); });
RelationshipService::refresh($pid, $fid);
return redirect()->back(); return redirect()->back();
} }
@ -131,14 +129,14 @@ trait PrivacySettings
$pid = Auth::user()->profile->id; $pid = Auth::user()->profile->id;
$ids = (new UserFilter())->blockedUserIds($pid); $ids = (new UserFilter())->blockedUserIds($pid);
$users = Profile::whereIn('id', $ids)->simplePaginate(15); $users = Profile::whereIn('id', $ids)->simplePaginate(15);
return view('settings.privacy.blocked', compact('users')); return view('settings.privacy.blocked', compact('users'));
} }
public function blockedUsersUpdate(Request $request) public function blockedUsersUpdate(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'profile_id' => 'required|integer|min:1' 'profile_id' => 'required|integer|min:1',
]); ]);
$fid = $request->input('profile_id'); $fid = $request->input('profile_id');
$pid = Auth::user()->profile->id; $pid = Auth::user()->profile->id;
@ -150,6 +148,8 @@ trait PrivacySettings
->firstOrFail(); ->firstOrFail();
$filter->delete(); $filter->delete();
}); });
RelationshipService::refresh($pid, $fid);
return redirect()->back(); return redirect()->back();
} }
@ -194,7 +194,7 @@ trait PrivacySettings
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
$settings = Auth::user()->settings; $settings = Auth::user()->settings;
if($mode !== 'keep-all') { if ($mode !== 'keep-all') {
switch ($mode) { switch ($mode) {
case 'mutual-only': case 'mutual-only':
$following = $profile->following()->pluck('profiles.id'); $following = $profile->following()->pluck('profiles.id');
@ -209,9 +209,9 @@ trait PrivacySettings
case 'remove-all': case 'remove-all':
Follower::whereFollowingId($profile->id)->delete(); Follower::whereFollowingId($profile->id)->delete();
break; break;
default: default:
# code... // code...
break; break;
} }
} }
@ -221,6 +221,7 @@ trait PrivacySettings
$settings->save(); $settings->save();
$profile->save(); $profile->save();
Cache::forget('profiles:private'); Cache::forget('profiles:private');
return [200]; return [200];
} }
} }