FeedUnfollowPipeline.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 App\Services\AccountService;
  12. use App\Services\StatusService;
  13. use App\Services\HomeTimelineService;
  14. class FeedUnfollowPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. protected $actorId;
  18. protected $followingId;
  19. public $timeout = 900;
  20. public $tries = 3;
  21. public $maxExceptions = 1;
  22. public $failOnTimeout = true;
  23. /**
  24. * The number of seconds after which the job's unique lock will be released.
  25. *
  26. * @var int
  27. */
  28. public $uniqueFor = 3600;
  29. /**
  30. * Get the unique ID for the job.
  31. */
  32. public function uniqueId(): string
  33. {
  34. return 'hts:feed:remove:follows:aid:' . $this->actorId . ':fid:' . $this->followingId;
  35. }
  36. /**
  37. * Get the middleware the job should pass through.
  38. *
  39. * @return array<int, object>
  40. */
  41. public function middleware(): array
  42. {
  43. return [(new WithoutOverlapping("hts:feed:remove:follows:aid:{$this->actorId}:fid:{$this->followingId}"))->shared()->dontRelease()];
  44. }
  45. /**
  46. * Create a new job instance.
  47. */
  48. public function __construct($actorId, $followingId)
  49. {
  50. $this->actorId = $actorId;
  51. $this->followingId = $followingId;
  52. }
  53. /**
  54. * Execute the job.
  55. */
  56. public function handle(): void
  57. {
  58. $actorId = $this->actorId;
  59. $followingId = $this->followingId;
  60. $ids = HomeTimelineService::get($actorId, 0, -1);
  61. foreach($ids as $id) {
  62. $status = StatusService::get($id, false);
  63. if($status && isset($status['account'], $status['account']['id'])) {
  64. if($status['account']['id'] == $followingId) {
  65. HomeTimelineService::rem($actorId, $id);
  66. }
  67. }
  68. }
  69. }
  70. }