CommentPipeline.php 1.9 KB

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