StoryReplyDeliver.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Jobs\StoryPipeline;
  3. use App\Story;
  4. use App\Status;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. use App\Util\ActivityPub\Helpers;
  11. class StoryReplyDeliver implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. protected $story;
  15. protected $status;
  16. /**
  17. * Delete the job if its models no longer exist.
  18. *
  19. * @var bool
  20. */
  21. public $deleteWhenMissingModels = true;
  22. /**
  23. * Create a new job instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct(Story $story, Status $status)
  28. {
  29. $this->story = $story;
  30. $this->status = $status;
  31. }
  32. /**
  33. * Execute the job.
  34. *
  35. * @return void
  36. */
  37. public function handle()
  38. {
  39. $story = $this->story;
  40. $status = $this->status;
  41. if($story->local == true) {
  42. return;
  43. }
  44. $target = $story->profile;
  45. $actor = $status->profile;
  46. $to = $target->inbox_url;
  47. $payload = [
  48. '@context' => 'https://www.w3.org/ns/activitystreams',
  49. 'id' => $status->permalink(),
  50. 'type' => 'Story:Reply',
  51. 'to' => $target->permalink(),
  52. 'actor' => $actor->permalink(),
  53. 'content' => $status->caption,
  54. 'inReplyTo' => $story->object_id,
  55. 'published' => $status->created_at->toAtomString()
  56. ];
  57. Helpers::sendSignedObject($actor, $to, $payload);
  58. }
  59. }