CommentPipeline.php 2.5 KB

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