Add LikeObserver

This commit is contained in:
Daniel Supernault 2021-07-02 01:33:49 -06:00
parent 447e44e5ac
commit d3157f2a2d
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 111 additions and 63 deletions

View file

@ -0,0 +1,64 @@
<?php
namespace App\Observers;
use App\Like;
use App\Services\LikeService;
class LikeObserver
{
/**
* Handle the Like "created" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function created(Like $like)
{
LikeService::add($like->profile_id, $like->status_id);
}
/**
* Handle the Like "updated" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function updated(Like $like)
{
//
}
/**
* Handle the Like "deleted" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function deleted(Like $like)
{
LikeService::remove($like->profile_id, $like->status_id);
}
/**
* Handle the Like "restored" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function restored(Like $like)
{
LikeService::add($like->profile_id, $like->status_id);
}
/**
* Handle the Like "force deleted" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function forceDeleted(Like $like)
{
LikeService::remove($like->profile_id, $like->status_id);
}
}

View file

@ -4,6 +4,7 @@ namespace App\Providers;
use App\Observers\{
AvatarObserver,
LikeObserver,
NotificationObserver,
ModLogObserver,
ProfileObserver,
@ -13,6 +14,7 @@ use App\Observers\{
};
use App\{
Avatar,
Like,
Notification,
ModLog,
Profile,
@ -37,36 +39,18 @@ class AppServiceProvider extends ServiceProvider
{
URL::forceScheme('https');
Schema::defaultStringLength(191);
Paginator::useBootstrap();
Avatar::observe(AvatarObserver::class);
Like::observe(LikeObserver::class);
Notification::observe(NotificationObserver::class);
ModLog::observe(ModLogObserver::class);
Profile::observe(ProfileObserver::class);
StatusHashtag::observe(StatusHashtagObserver::class);
User::observe(UserObserver::class);
UserFilter::observe(UserFilterObserver::class);
Horizon::auth(function ($request) {
return Auth::check() && $request->user()->is_admin;
});
Blade::directive('prettyNumber', function ($expression) {
$num = \App\Util\Lexer\PrettyNumber::convert($expression);
return "<?php echo $num; ?>";
});
Blade::directive('prettySize', function ($expression) {
$size = \App\Util\Lexer\PrettyNumber::size($expression);
return "<?php echo '$size'; ?>";
});
Blade::directive('maxFileSize', function () {
$value = config('pixelfed.max_photo_size');
return \App\Util\Lexer\PrettyNumber::size($value, true);
});
}
/**