Update PrivacySettings, add domainBlocks

This commit is contained in:
Daniel Supernault 2023-12-16 05:42:56 -07:00
parent cef451e588
commit 28da44beec
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -14,6 +14,7 @@ use App\Util\Lexer\PrettyNumber;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Auth, Cache, DB; use Auth, Cache, DB;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserDomainBlock;
trait PrivacySettings trait PrivacySettings
{ {
@ -149,47 +150,25 @@ trait PrivacySettings
public function blockedInstances() public function blockedInstances()
{ {
$pid = Auth::user()->profile->id; // deprecated
$filters = UserFilter::whereUserId($pid) abort(404);
->whereFilterableType('App\Instance') }
->whereFilterType('block')
->orderByDesc('id') public function domainBlocks()
->paginate(10); {
return view('settings.privacy.blocked-instances', compact('filters')); return view('settings.privacy.domain-blocks');
} }
public function blockedInstanceStore(Request $request) public function blockedInstanceStore(Request $request)
{ {
$this->validate($request, [ // deprecated
'domain' => 'required|url|min:1|max:120' abort(404);
]);
$domain = $request->input('domain');
if(Helpers::validateUrl($domain) == false) {
return abort(400, 'Invalid domain');
}
$domain = parse_url($domain, PHP_URL_HOST);
$instance = Instance::firstOrCreate(['domain' => $domain]);
$filter = new UserFilter;
$filter->user_id = Auth::user()->profile->id;
$filter->filterable_id = $instance->id;
$filter->filterable_type = 'App\Instance';
$filter->filter_type = 'block';
$filter->save();
return response()->json(['msg' => 200]);
} }
public function blockedInstanceUnblock(Request $request) public function blockedInstanceUnblock(Request $request)
{ {
$this->validate($request, [ // deprecated
'id' => 'required|integer|min:1' abort(404);
]);
$pid = Auth::user()->profile->id;
$filter = UserFilter::whereFilterableType('App\Instance')
->whereUserId($pid)
->findOrFail($request->input('id'));
$filter->delete();
return redirect(route('settings.privacy.blocked-instances'));
} }
public function blockedKeywords() public function blockedKeywords()