CommentPipeline.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Jobs\CommentPipeline;
  3. use Cache, Log, Redis;
  4. use App\{Like, Notification, Status};
  5. use App\Util\Lexer\Hashtag as HashtagLexer;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Queue\SerializesModels;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. class CommentPipeline implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. protected $status;
  15. protected $comment;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct(Status $status, Status $comment)
  22. {
  23. $this->status = $status;
  24. $this->comment = $comment;
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. * @return void
  30. */
  31. public function handle()
  32. {
  33. $status = $this->status;
  34. $comment = $this->comment;
  35. $target = $status->profile;
  36. $actor = $comment->profile;
  37. if($actor->id === $target->id) {
  38. return true;
  39. }
  40. try {
  41. $notification = new Notification;
  42. $notification->profile_id = $target->id;
  43. $notification->actor_id = $actor->id;
  44. $notification->action = 'comment';
  45. $notification->message = $comment->replyToText();
  46. $notification->rendered = $comment->replyToHtml();
  47. $notification->item_id = $comment->id;
  48. $notification->item_type = "App\Status";
  49. $notification->save();
  50. Cache::forever('notification.' . $notification->id, $notification);
  51. $redis = Redis::connection();
  52. $nkey = config('cache.prefix').':user.' . $target->id . '.notifications';
  53. $redis->lpush($nkey, $notification->id);
  54. } catch (Exception $e) {
  55. Log::error($e);
  56. }
  57. }
  58. }