FollowPipeline.php 1.6 KB

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