HashtagUnfollowPipeline.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Jobs\HomeFeedPipeline;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldBeUnique;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use Illuminate\Queue\Middleware\WithoutOverlapping;
  10. use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
  11. use Illuminate\Support\Facades\Cache;
  12. use App\Follower;
  13. use App\Hashtag;
  14. use App\StatusHashtag;
  15. use App\Services\HashtagFollowService;
  16. use App\Services\StatusService;
  17. use App\Services\HomeTimelineService;
  18. class HashtagUnfollowPipeline implements ShouldQueue
  19. {
  20. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  21. protected $pid;
  22. protected $hid;
  23. protected $slug;
  24. public $timeout = 900;
  25. public $tries = 3;
  26. public $maxExceptions = 1;
  27. public $failOnTimeout = true;
  28. /**
  29. * Create a new job instance.
  30. */
  31. public function __construct($hid, $pid, $slug)
  32. {
  33. $this->hid = $hid;
  34. $this->pid = $pid;
  35. $this->slug = $slug;
  36. }
  37. /**
  38. * Execute the job.
  39. */
  40. public function handle(): void
  41. {
  42. $hid = $this->hid;
  43. $pid = $this->pid;
  44. $slug = strtolower($this->slug);
  45. $statusIds = HomeTimelineService::get($pid, 0, -1);
  46. $followingIds = Cache::remember('profile:following:'.$pid, 1209600, function() use($pid) {
  47. $following = Follower::whereProfileId($pid)->pluck('following_id');
  48. return $following->push($pid)->toArray();
  49. });
  50. foreach($statusIds as $id) {
  51. $status = StatusService::get($id, false);
  52. if(!$status || empty($status['tags'])) {
  53. HomeTimelineService::rem($pid, $id);
  54. continue;
  55. }
  56. $following = in_array((int) $status['account']['id'], $followingIds);
  57. if($following === true) {
  58. continue;
  59. }
  60. $tags = collect($status['tags'])->map(function($tag) {
  61. return strtolower($tag['name']);
  62. })->filter()->values()->toArray();
  63. if(in_array($slug, $tags)) {
  64. HomeTimelineService::rem($pid, $id);
  65. }
  66. }
  67. }
  68. }