CommentPipeline.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. /**
  28. * Create a new job instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct(Status $status, Status $comment)
  33. {
  34. $this->status = $status;
  35. $this->comment = $comment;
  36. }
  37. /**
  38. * Execute the job.
  39. *
  40. * @return void
  41. */
  42. public function handle()
  43. {
  44. $status = $this->status;
  45. $comment = $this->comment;
  46. $target = $status->profile;
  47. $actor = $comment->profile;
  48. if ($actor->id === $target->id || $status->comments_disabled == true) {
  49. return true;
  50. }
  51. $filtered = UserFilter::whereUserId($target->id)
  52. ->whereFilterableType('App\Profile')
  53. ->whereIn('filter_type', ['mute', 'block'])
  54. ->whereFilterableId($actor->id)
  55. ->exists();
  56. if($filtered == true) {
  57. return;
  58. }
  59. DB::transaction(function() use($target, $actor, $comment) {
  60. $notification = new Notification();
  61. $notification->profile_id = $target->id;
  62. $notification->actor_id = $actor->id;
  63. $notification->action = 'comment';
  64. $notification->message = $comment->replyToText();
  65. $notification->rendered = $comment->replyToHtml();
  66. $notification->item_id = $comment->id;
  67. $notification->item_type = "App\Status";
  68. $notification->save();
  69. NotificationService::setNotification($notification);
  70. NotificationService::set($notification->profile_id, $notification->id);
  71. });
  72. }
  73. }