CommentPipeline.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. try {
  38. $notification = new Notification;
  39. $notification->profile_id = $target->id;
  40. $notification->actor_id = $actor->id;
  41. $notification->action = 'comment';
  42. $notification->message = $comment->replyToText();
  43. $notification->rendered = $comment->replyToHtml();
  44. $notification->item_id = $comment->id;
  45. $notification->item_type = "App\Status";
  46. $notification->save();
  47. Cache::forever('notification.' . $notification->id, $notification);
  48. $redis = Redis::connection();
  49. $nkey = config('cache.prefix').':user.' . $target->id . '.notifications';
  50. $redis->lpush($nkey, $notification->id);
  51. } catch (Exception $e) {
  52. Log::error($e);
  53. }
  54. }
  55. }