CommentPipeline.php 2.2 KB

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