2018-09-17 01:45:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Settings;
|
|
|
|
|
2019-06-27 01:58:39 +00:00
|
|
|
use App\Follower;
|
2018-09-17 01:45:36 +00:00
|
|
|
use App\Profile;
|
2024-06-04 09:46:06 +00:00
|
|
|
use App\Services\AccountService;
|
2024-04-06 07:22:52 +00:00
|
|
|
use App\Services\RelationshipService;
|
2018-09-17 01:45:36 +00:00
|
|
|
use App\UserFilter;
|
2024-04-06 07:22:52 +00:00
|
|
|
use Auth;
|
|
|
|
use Cache;
|
|
|
|
use DB;
|
2018-09-17 01:45:36 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
trait PrivacySettings
|
|
|
|
{
|
|
|
|
public function privacy()
|
|
|
|
{
|
2023-08-25 05:31:33 +00:00
|
|
|
$user = Auth::user();
|
|
|
|
$settings = $user->settings;
|
|
|
|
$profile = $user->profile;
|
|
|
|
$is_private = $profile->is_private;
|
2024-06-04 09:46:06 +00:00
|
|
|
$cachedSettings = AccountService::getAccountSettings($profile->id);
|
2023-08-25 05:31:33 +00:00
|
|
|
$settings['is_private'] = (bool) $is_private;
|
2024-06-04 09:46:06 +00:00
|
|
|
if ($cachedSettings && isset($cachedSettings['disable_embeds'])) {
|
|
|
|
$settings['disable_embeds'] = (bool) $cachedSettings['disable_embeds'];
|
|
|
|
} else {
|
|
|
|
$settings['disable_embeds'] = false;
|
|
|
|
}
|
2018-09-17 01:45:36 +00:00
|
|
|
|
2023-08-25 05:31:33 +00:00
|
|
|
return view('settings.privacy', compact('settings', 'profile'));
|
2018-09-17 01:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function privacyStore(Request $request)
|
|
|
|
{
|
2019-09-11 06:15:27 +00:00
|
|
|
$settings = $request->user()->settings;
|
|
|
|
$profile = $request->user()->profile;
|
2024-06-04 09:46:06 +00:00
|
|
|
$other = $settings->other;
|
2018-09-17 01:45:36 +00:00
|
|
|
$fields = [
|
2024-04-06 07:22:52 +00:00
|
|
|
'is_private',
|
|
|
|
'crawlable',
|
|
|
|
'public_dm',
|
|
|
|
'show_profile_follower_count',
|
|
|
|
'show_profile_following_count',
|
|
|
|
'indexable',
|
|
|
|
'show_atom',
|
2019-09-11 06:15:27 +00:00
|
|
|
];
|
2023-04-10 02:21:40 +00:00
|
|
|
|
2023-08-25 05:31:33 +00:00
|
|
|
$profile->indexable = $request->input('indexable') == 'on';
|
|
|
|
$profile->is_suggestable = $request->input('is_suggestable') == 'on';
|
|
|
|
$profile->save();
|
2023-04-10 02:21:40 +00:00
|
|
|
|
2024-06-04 09:46:06 +00:00
|
|
|
if ($request->has('disable_embeds')) {
|
|
|
|
$other['disable_embeds'] = true;
|
|
|
|
$settings->other = $other;
|
|
|
|
$settings->save();
|
|
|
|
} else {
|
|
|
|
$other['disable_embeds'] = false;
|
|
|
|
$settings->other = $other;
|
|
|
|
$settings->save();
|
|
|
|
}
|
|
|
|
|
2018-09-17 01:45:36 +00:00
|
|
|
foreach ($fields as $field) {
|
|
|
|
$form = $request->input($field);
|
|
|
|
if ($field == 'is_private') {
|
|
|
|
if ($form == 'on') {
|
|
|
|
$profile->{$field} = true;
|
|
|
|
$settings->show_guests = false;
|
|
|
|
$settings->show_discover = false;
|
|
|
|
$profile->save();
|
|
|
|
} else {
|
|
|
|
$profile->{$field} = false;
|
|
|
|
$profile->save();
|
|
|
|
}
|
2019-02-25 06:22:06 +00:00
|
|
|
Cache::forget('profiles:private');
|
2018-09-17 01:45:36 +00:00
|
|
|
} elseif ($field == 'crawlable') {
|
|
|
|
if ($form == 'on') {
|
|
|
|
$settings->{$field} = false;
|
|
|
|
} else {
|
|
|
|
$settings->{$field} = true;
|
|
|
|
}
|
2024-04-06 07:22:52 +00:00
|
|
|
} elseif ($field == 'public_dm') {
|
2020-11-18 21:19:02 +00:00
|
|
|
if ($form == 'on') {
|
|
|
|
$settings->{$field} = true;
|
|
|
|
} else {
|
|
|
|
$settings->{$field} = false;
|
|
|
|
}
|
2023-08-25 05:31:33 +00:00
|
|
|
} elseif ($field == 'indexable') {
|
|
|
|
|
2018-09-17 01:45:36 +00:00
|
|
|
} else {
|
|
|
|
if ($form == 'on') {
|
|
|
|
$settings->{$field} = true;
|
|
|
|
} else {
|
|
|
|
$settings->{$field} = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$settings->save();
|
|
|
|
}
|
2024-02-29 11:59:13 +00:00
|
|
|
$pid = $profile->id;
|
2024-04-06 07:22:52 +00:00
|
|
|
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));
|
2024-06-04 09:46:06 +00:00
|
|
|
AccountService::forgetAccountSettings($profile->id);
|
2024-04-06 07:22:52 +00:00
|
|
|
|
2018-09-17 01:45:36 +00:00
|
|
|
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mutedUsers()
|
2024-04-06 07:22:52 +00:00
|
|
|
{
|
2018-09-17 01:45:36 +00:00
|
|
|
$pid = Auth::user()->profile->id;
|
|
|
|
$ids = (new UserFilter())->mutedUserIds($pid);
|
|
|
|
$users = Profile::whereIn('id', $ids)->simplePaginate(15);
|
2024-04-06 07:22:52 +00:00
|
|
|
|
2018-09-17 01:45:36 +00:00
|
|
|
return view('settings.privacy.muted', compact('users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mutedUsersUpdate(Request $request)
|
2024-04-06 07:22:52 +00:00
|
|
|
{
|
2018-09-17 01:45:36 +00:00
|
|
|
$this->validate($request, [
|
2024-04-06 07:22:52 +00:00
|
|
|
'profile_id' => 'required|integer|min:1',
|
2018-09-17 01:45:36 +00:00
|
|
|
]);
|
|
|
|
$fid = $request->input('profile_id');
|
|
|
|
$pid = Auth::user()->profile->id;
|
|
|
|
DB::transaction(function () use ($fid, $pid) {
|
|
|
|
$filter = UserFilter::whereUserId($pid)
|
|
|
|
->whereFilterableId($fid)
|
|
|
|
->whereFilterableType('App\Profile')
|
|
|
|
->whereFilterType('mute')
|
|
|
|
->firstOrFail();
|
|
|
|
$filter->delete();
|
|
|
|
});
|
2024-04-06 07:22:52 +00:00
|
|
|
RelationshipService::refresh($pid, $fid);
|
|
|
|
|
2018-09-17 01:45:36 +00:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function blockedUsers()
|
|
|
|
{
|
|
|
|
$pid = Auth::user()->profile->id;
|
|
|
|
$ids = (new UserFilter())->blockedUserIds($pid);
|
|
|
|
$users = Profile::whereIn('id', $ids)->simplePaginate(15);
|
2024-04-06 07:22:52 +00:00
|
|
|
|
2018-09-17 01:45:36 +00:00
|
|
|
return view('settings.privacy.blocked', compact('users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function blockedUsersUpdate(Request $request)
|
2024-04-06 07:22:52 +00:00
|
|
|
{
|
2018-09-17 01:45:36 +00:00
|
|
|
$this->validate($request, [
|
2024-04-06 07:22:52 +00:00
|
|
|
'profile_id' => 'required|integer|min:1',
|
2018-09-17 01:45:36 +00:00
|
|
|
]);
|
|
|
|
$fid = $request->input('profile_id');
|
|
|
|
$pid = Auth::user()->profile->id;
|
|
|
|
DB::transaction(function () use ($fid, $pid) {
|
|
|
|
$filter = UserFilter::whereUserId($pid)
|
|
|
|
->whereFilterableId($fid)
|
|
|
|
->whereFilterableType('App\Profile')
|
|
|
|
->whereFilterType('block')
|
|
|
|
->firstOrFail();
|
|
|
|
$filter->delete();
|
|
|
|
});
|
2024-04-06 07:22:52 +00:00
|
|
|
RelationshipService::refresh($pid, $fid);
|
|
|
|
|
2018-09-17 01:45:36 +00:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function blockedInstances()
|
|
|
|
{
|
2023-12-16 12:42:56 +00:00
|
|
|
// deprecated
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function domainBlocks()
|
|
|
|
{
|
|
|
|
return view('settings.privacy.domain-blocks');
|
2019-01-31 19:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function blockedInstanceStore(Request $request)
|
|
|
|
{
|
2023-12-16 12:42:56 +00:00
|
|
|
// deprecated
|
|
|
|
abort(404);
|
2019-01-31 19:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function blockedInstanceUnblock(Request $request)
|
|
|
|
{
|
2023-12-16 12:42:56 +00:00
|
|
|
// deprecated
|
|
|
|
abort(404);
|
2019-01-31 19:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function blockedKeywords()
|
|
|
|
{
|
|
|
|
return view('settings.privacy.blocked-keywords');
|
2018-09-17 01:45:36 +00:00
|
|
|
}
|
2019-06-27 01:58:39 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-04-06 07:22:52 +00:00
|
|
|
if ($mode !== 'keep-all') {
|
2019-06-27 01:58:39 +00:00
|
|
|
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;
|
2024-04-06 07:22:52 +00:00
|
|
|
|
2019-06-27 01:58:39 +00:00
|
|
|
default:
|
2024-04-06 07:22:52 +00:00
|
|
|
// code...
|
2019-06-27 01:58:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$profile->is_private = true;
|
|
|
|
$settings->show_guests = false;
|
|
|
|
$settings->show_discover = false;
|
|
|
|
$settings->save();
|
|
|
|
$profile->save();
|
|
|
|
Cache::forget('profiles:private');
|
2024-04-06 07:22:52 +00:00
|
|
|
|
2019-06-27 01:58:39 +00:00
|
|
|
return [200];
|
|
|
|
}
|
2022-01-08 11:02:14 +00:00
|
|
|
}
|