Update DomainBlockController, dispatch jobies

This commit is contained in:
Daniel Supernault 2023-12-19 06:24:51 -07:00
parent 54adbeb059
commit 87bba03d23
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -6,6 +6,12 @@ use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\UserDomainBlock; use App\Models\UserDomainBlock;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Cache;
use App\Jobs\HomeFeedPipeline\FeedRemoveDomainPipeline;
use App\Jobs\ProfilePipeline\ProfilePurgeNotificationsByDomain;
use App\Jobs\ProfilePipeline\ProfilePurgeFollowersByDomain;
class DomainBlockController extends Controller class DomainBlockController extends Controller
{ {
@ -59,7 +65,7 @@ class DomainBlockController extends Controller
return abort(500, 'Invalid domain or already blocked by server admins'); return abort(500, 'Invalid domain or already blocked by server admins');
} }
$domain = parse_url($domain, PHP_URL_HOST); $domain = strtolower(parse_url($domain, PHP_URL_HOST));
abort_if(config_cache('pixelfed.domain.app') == $domain, 400, 'Cannot ban your own server'); abort_if(config_cache('pixelfed.domain.app') == $domain, 400, 'Cannot ban your own server');
@ -69,11 +75,23 @@ class DomainBlockController extends Controller
abort_if($existingCount >= $maxLimit, 400, $errorMsg); abort_if($existingCount >= $maxLimit, 400, $errorMsg);
$block = UserDomainBlock::updateOrInsert([ $block = UserDomainBlock::updateOrCreate([
'profile_id' => $pid, 'profile_id' => $pid,
'domain' => $domain 'domain' => $domain
]); ]);
if($block->wasRecentlyCreated) {
Bus::batch([
[
new FeedRemoveDomainPipeline($pid, $domain),
new ProfilePurgeNotificationsByDomain($pid, $domain),
new ProfilePurgeFollowersByDomain($pid, $domain)
]
])->allowFailures()->onQueue('feed')->dispatch();
Cache::forget('profile:following:' . $pid);
}
return $this->json([]); return $this->json([]);
} }
@ -87,7 +105,7 @@ class DomainBlockController extends Controller
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
$domain = trim($request->input('domain')); $domain = strtolower(trim($request->input('domain')));
$filters = UserDomainBlock::whereProfileId($pid)->whereDomain($domain)->delete(); $filters = UserDomainBlock::whereProfileId($pid)->whereDomain($domain)->delete();