CommentPipeline.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Jobs\CommentPipeline;
  3. use App\{
  4. Notification,
  5. Status,
  6. UserFilter
  7. };
  8. use App\Services\NotificationService;
  9. use DB, Cache, Log;
  10. use Illuminate\Support\Facades\Redis;
  11. use Illuminate\Bus\Queueable;
  12. use Illuminate\Contracts\Queue\ShouldQueue;
  13. use Illuminate\Foundation\Bus\Dispatchable;
  14. use Illuminate\Queue\InteractsWithQueue;
  15. use Illuminate\Queue\SerializesModels;
  16. class CommentPipeline implements ShouldQueue
  17. {
  18. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  19. protected $status;
  20. protected $comment;
  21. /**
  22. * Delete the job if its models no longer exist.
  23. *
  24. * @var bool
  25. */
  26. public $deleteWhenMissingModels = true;
  27. public $timeout = 5;
  28. public $tries = 1;
  29. /**
  30. * Create a new job instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct(Status $status, Status $comment)
  35. {
  36. $this->status = $status;
  37. $this->comment = $comment;
  38. }
  39. /**
  40. * Execute the job.
  41. *
  42. * @return void
  43. */
  44. public function handle()
  45. {
  46. $status = $this->status;
  47. $comment = $this->comment;
  48. $target = $status->profile;
  49. $actor = $comment->profile;
  50. if ($actor->id === $target->id || $status->comments_disabled == true) {
  51. return true;
  52. }
  53. $filtered = UserFilter::whereUserId($target->id)
  54. ->whereFilterableType('App\Profile')
  55. ->whereIn('filter_type', ['mute', 'block'])
  56. ->whereFilterableId($actor->id)
  57. ->exists();
  58. if($filtered == true) {
  59. return;
  60. }
  61. DB::transaction(function() use($target, $actor, $comment) {
  62. $notification = new Notification();
  63. $notification->profile_id = $target->id;
  64. $notification->actor_id = $actor->id;
  65. $notification->action = 'comment';
  66. $notification->message = $comment->replyToText();
  67. $notification->rendered = $comment->replyToHtml();
  68. $notification->item_id = $comment->id;
  69. $notification->item_type = "App\Status";
  70. $notification->save();
  71. NotificationService::setNotification($notification);
  72. NotificationService::set($notification->profile_id, $notification->id);
  73. });
  74. }
  75. }