2019-07-01 04:38:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
2022-12-27 11:16:34 +00:00
|
|
|
use DB;
|
2019-07-01 04:38:26 +00:00
|
|
|
use App\StatusHashtag;
|
|
|
|
use App\Services\StatusHashtagService;
|
2023-11-11 12:47:52 +00:00
|
|
|
use App\Jobs\HomeFeedPipeline\HashtagInsertFanoutPipeline;
|
|
|
|
use App\Jobs\HomeFeedPipeline\HashtagRemoveFanoutPipeline;
|
|
|
|
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;
|
2019-07-01 04:38:26 +00:00
|
|
|
|
2023-11-11 12:47:52 +00:00
|
|
|
class StatusHashtagObserver implements ShouldHandleEventsAfterCommit
|
2019-07-01 04:38:26 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle the notification "created" event.
|
|
|
|
*
|
2023-11-11 12:47:52 +00:00
|
|
|
* @param \App\StatusHashtag $hashtag
|
2019-07-01 04:38:26 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function created(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id);
|
2022-12-27 11:16:34 +00:00
|
|
|
DB::table('hashtags')->where('id', $hashtag->hashtag_id)->increment('cached_count');
|
2023-11-11 12:47:52 +00:00
|
|
|
if($hashtag->status_visibility && $hashtag->status_visibility === 'public') {
|
|
|
|
HashtagInsertFanoutPipeline::dispatch($hashtag)->onQueue('feed');
|
|
|
|
}
|
2019-07-01 04:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the notification "updated" event.
|
|
|
|
*
|
2023-11-11 12:47:52 +00:00
|
|
|
* @param \App\StatusHashtag $hashtag
|
2019-07-01 04:38:26 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function updated(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-13 12:29:38 +00:00
|
|
|
* Handle the notification "deleted" event.
|
2019-07-01 04:38:26 +00:00
|
|
|
*
|
2023-11-11 12:47:52 +00:00
|
|
|
* @param \App\StatusHashtag $hashtag
|
2019-07-01 04:38:26 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2023-11-13 12:29:38 +00:00
|
|
|
public function deleted(StatusHashtag $hashtag)
|
2019-07-01 04:38:26 +00:00
|
|
|
{
|
|
|
|
StatusHashtagService::del($hashtag->hashtag_id, $hashtag->status_id);
|
2022-12-27 11:16:34 +00:00
|
|
|
DB::table('hashtags')->where('id', $hashtag->hashtag_id)->decrement('cached_count');
|
2023-11-11 12:47:52 +00:00
|
|
|
if($hashtag->status_visibility && $hashtag->status_visibility === 'public') {
|
|
|
|
HashtagRemoveFanoutPipeline::dispatch($hashtag->status_id, $hashtag->hashtag_id)->onQueue('feed');
|
|
|
|
}
|
2019-07-01 04:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the notification "restored" event.
|
|
|
|
*
|
2023-11-11 12:47:52 +00:00
|
|
|
* @param \App\StatusHashtag $hashtag
|
2019-07-01 04:38:26 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function restored(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the notification "force deleted" event.
|
|
|
|
*
|
2023-11-11 12:47:52 +00:00
|
|
|
* @param \App\StatusHashtag $hashtag
|
2019-07-01 04:38:26 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function forceDeleted(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::del($hashtag->hashtag_id, $hashtag->status_id);
|
|
|
|
}
|
|
|
|
}
|