pixelfed/app/Observers/StatusObserver.php

100 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2022-09-13 03:26:54 +00:00
<?php
namespace App\Observers;
use App\Status;
use App\Services\ProfileStatusService;
2022-12-16 07:43:20 +00:00
use Cache;
2023-06-26 11:38:29 +00:00
use App\Models\ImportPost;
use App\Services\ImportService;
2023-11-13 03:54:32 +00:00
use App\Jobs\HomeFeedPipeline\FeedRemovePipeline;
use App\Jobs\HomeFeedPipeline\FeedRemoveRemotePipeline;
2022-09-13 03:26:54 +00:00
class StatusObserver
{
/**
* Handle events after all transactions are committed.
*
* @var bool
*/
public $afterCommit = true;
2022-09-13 03:26:54 +00:00
/**
* 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)
{
2022-12-16 07:43:20 +00:00
if(config('instance.timeline.home.cached')) {
Cache::forget('pf:timelines:home:' . $status->profile_id);
}
2022-09-13 03:26:54 +00:00
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)
{
2022-12-16 07:43:20 +00:00
if(config('instance.timeline.home.cached')) {
Cache::forget('pf:timelines:home:' . $status->profile_id);
}
2022-09-13 03:26:54 +00:00
ProfileStatusService::delete($status->profile_id, $status->id);
if($status->uri == null) {
ImportPost::whereProfileId($status->profile_id)->whereStatusId($status->id)->delete();
ImportService::clearImportedFiles($status->profile_id);
}
2023-11-13 03:54:32 +00:00
if(config('exp.cached_home_timeline')) {
if($status->uri) {
FeedRemoveRemotePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
} else {
FeedRemovePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
}
2023-11-13 03:54:32 +00:00
}
2022-09-13 03:26:54 +00:00
}
/**
* 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)
{
//
}
}