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