From 19233cc9763ee5ec80a2ccc7a7d6065689c5ae63 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 15 Nov 2023 22:16:23 -0700 Subject: [PATCH] Update HashtagFollowObserver --- app/Http/Controllers/Api/ApiV1Controller.php | 2 +- .../HomeFeedPipeline/HashtagUnfollowPipeline.php | 16 ++++++++++++++-- app/Observers/HashtagFollowObserver.php | 2 -- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index f750503aa..7711726ae 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -3831,7 +3831,7 @@ class ApiV1Controller extends Controller if($follows) { HashtagService::unfollow($pid, $tag->id); HashtagFollowService::unfollow($tag->id, $pid); - HashtagUnfollowPipeline::dispatch($tag->id, $pid)->onQueue('feed'); + HashtagUnfollowPipeline::dispatch($tag->id, $pid, $tag->slug)->onQueue('feed'); $follows->delete(); } diff --git a/app/Jobs/HomeFeedPipeline/HashtagUnfollowPipeline.php b/app/Jobs/HomeFeedPipeline/HashtagUnfollowPipeline.php index ece5dbf8f..69573f410 100644 --- a/app/Jobs/HomeFeedPipeline/HashtagUnfollowPipeline.php +++ b/app/Jobs/HomeFeedPipeline/HashtagUnfollowPipeline.php @@ -24,6 +24,7 @@ class HashtagUnfollowPipeline implements ShouldQueue protected $pid; protected $hid; + protected $slug; public $timeout = 900; public $tries = 3; @@ -33,10 +34,11 @@ class HashtagUnfollowPipeline implements ShouldQueue /** * Create a new job instance. */ - public function __construct($hid, $pid) + public function __construct($hid, $pid, $slug) { $this->hid = $hid; $this->pid = $pid; + $this->slug = $slug; } /** @@ -46,6 +48,7 @@ class HashtagUnfollowPipeline implements ShouldQueue { $hid = $this->hid; $pid = $this->pid; + $slug = $this->slug; $statusIds = HomeTimelineService::get($pid, 0, -1); @@ -60,7 +63,16 @@ class HashtagUnfollowPipeline implements ShouldQueue HomeTimelineService::rem($pid, $id); continue; } - if(!in_array($status['account']['id'], $followingIds)) { + $following = in_array($status['account']['id'], $followingIds); + if($following || !isset($status['tags'])) { + continue; + } + + $tags = collect($status['tags'])->filter(function($tag) { + return $tag['name']; + })->toArray(); + + if(in_array($slug, $tags)) { HomeTimelineService::rem($pid, $id); } } diff --git a/app/Observers/HashtagFollowObserver.php b/app/Observers/HashtagFollowObserver.php index 822ee0805..56158c21a 100644 --- a/app/Observers/HashtagFollowObserver.php +++ b/app/Observers/HashtagFollowObserver.php @@ -31,7 +31,6 @@ class HashtagFollowObserver implements ShouldHandleEventsAfterCommit public function deleting(HashtagFollow $hashtagFollow): void { HashtagFollowService::unfollow($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); - HashtagUnfollowPipeline::dispatch($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); } /** @@ -48,6 +47,5 @@ class HashtagFollowObserver implements ShouldHandleEventsAfterCommit public function forceDeleted(HashtagFollow $hashtagFollow): void { HashtagFollowService::unfollow($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); - HashtagUnfollowPipeline::dispatch($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); } }