mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update UserObserver, add default domain blocks logic
This commit is contained in:
parent
519c7a3735
commit
fa0380ac3b
1 changed files with 131 additions and 76 deletions
|
@ -7,6 +7,9 @@ use App\Follower;
|
|||
use App\Profile;
|
||||
use App\User;
|
||||
use App\UserSetting;
|
||||
use App\Services\UserFilterService;
|
||||
use App\Models\DefaultDomainBlock;
|
||||
use App\Models\UserDomainBlock;
|
||||
use App\Jobs\FollowPipeline\FollowPipeline;
|
||||
use DB;
|
||||
use App\Services\FollowerService;
|
||||
|
@ -14,7 +17,18 @@ use App\Services\FollowerService;
|
|||
class UserObserver
|
||||
{
|
||||
/**
|
||||
* Listen to the User created event.
|
||||
* Handle the notification "created" event.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return void
|
||||
*/
|
||||
public function created(User $user): void
|
||||
{
|
||||
$this->handleUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to the User saved event.
|
||||
*
|
||||
* @param \App\User $user
|
||||
*
|
||||
|
@ -22,7 +36,38 @@ class UserObserver
|
|||
*/
|
||||
public function saved(User $user)
|
||||
{
|
||||
if($user->status == 'deleted') {
|
||||
$this->handleUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to the User updated event.
|
||||
*
|
||||
* @param \App\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updated(User $user): void
|
||||
{
|
||||
$this->handleUser($user);
|
||||
if($user->profile) {
|
||||
$this->applyDefaultDomainBlocks($user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the user "deleted" event.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return void
|
||||
*/
|
||||
public function deleted(User $user)
|
||||
{
|
||||
FollowerService::delCache($user->profile_id);
|
||||
}
|
||||
|
||||
protected function handleUser($user)
|
||||
{
|
||||
if(in_array($user->status, ['deleted', 'delete'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -49,9 +94,11 @@ class UserObserver
|
|||
$profile->private_key = $pki_private;
|
||||
$profile->public_key = $pki_public;
|
||||
$profile->save();
|
||||
$this->applyDefaultDomainBlocks($user);
|
||||
return $profile;
|
||||
});
|
||||
|
||||
|
||||
DB::transaction(function() use($user, $profile) {
|
||||
$user = User::findOrFail($user->id);
|
||||
$user->profile_id = $profile->id;
|
||||
|
@ -92,14 +139,22 @@ class UserObserver
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the user "deleted" event.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return void
|
||||
*/
|
||||
public function deleted(User $user)
|
||||
protected function applyDefaultDomainBlocks($user)
|
||||
{
|
||||
FollowerService::delCache($user->profile_id);
|
||||
if($user->profile_id == null) {
|
||||
return;
|
||||
}
|
||||
$defaultDomainBlocks = DefaultDomainBlock::pluck('domain')->toArray();
|
||||
|
||||
if(!$defaultDomainBlocks || !count($defaultDomainBlocks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($defaultDomainBlocks as $domain) {
|
||||
UserDomainBlock::updateOrCreate([
|
||||
'profile_id' => $user->profile_id,
|
||||
'domain' => strtolower(trim($domain))
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue