Add StatusObserver

This commit is contained in:
Daniel Supernault 2022-09-12 21:26:54 -06:00
parent 4d95d2cb7f
commit d122c2d042
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 70 additions and 1 deletions

View file

@ -0,0 +1,66 @@
<?php
namespace App\Observers;
use App\Status;
use App\Services\ProfileStatusService;
class StatusObserver
{
/**
* Handle the Status "created" event.
*
* @param \App\Status $status
* @return void
*/
public function created(Status $status)
{
//
}
/**
* Handle the Status "updated" event.
*
* @param \App\Status $status
* @return void
*/
public function updated(Status $status)
{
if(in_array($status->scope, ['public', 'unlisted']) && in_array($status->type, ['photo', 'photo:album', 'video'])) {
ProfileStatusService::add($status->profile_id, $status->id);
}
}
/**
* Handle the Status "deleted" event.
*
* @param \App\Status $status
* @return void
*/
public function deleted(Status $status)
{
ProfileStatusService::delete($status->profile_id, $status->id);
}
/**
* Handle the Status "restored" event.
*
* @param \App\Status $status
* @return void
*/
public function restored(Status $status)
{
//
}
/**
* Handle the Status "force deleted" event.
*
* @param \App\Status $status
* @return void
*/
public function forceDeleted(Status $status)
{
//
}
}

View file

@ -8,7 +8,8 @@ use App\Observers\{
NotificationObserver,
ModLogObserver,
ProfileObserver,
StatusHashtagObserver,
StatusHashtagObserver,
StatusObserver,
UserObserver,
UserFilterObserver,
};
@ -19,6 +20,7 @@ use App\{
ModLog,
Profile,
StatusHashtag,
Status,
User,
UserFilter
};
@ -47,6 +49,7 @@ class AppServiceProvider extends ServiceProvider
Profile::observe(ProfileObserver::class);
StatusHashtag::observe(StatusHashtagObserver::class);
User::observe(UserObserver::class);
Status::observe(StatusObserver::class);
UserFilter::observe(UserFilterObserver::class);
Horizon::auth(function ($request) {
return Auth::check() && $request->user()->is_admin;