StoryVerb.php 947 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Transformer\ActivityPub\Verb;
  3. use Storage;
  4. use App\Story;
  5. use League\Fractal;
  6. use Illuminate\Support\Str;
  7. class StoryVerb extends Fractal\TransformerAbstract
  8. {
  9. public function transform(Story $story)
  10. {
  11. $type = $story->type == 'photo' ? 'Image' :
  12. ( $story->type == 'video' ? 'Video' :
  13. 'Document' );
  14. return [
  15. '@context' => 'https://www.w3.org/ns/activitystreams',
  16. 'id' => $story->url(),
  17. 'type' => 'Story',
  18. 'to' => [
  19. $story->profile->permalink('/followers')
  20. ],
  21. 'cc' => [],
  22. 'attributedTo' => $story->profile->permalink(),
  23. 'published' => $story->created_at->toAtomString(),
  24. 'expiresAt' => $story->expires_at->toAtomString(),
  25. 'duration' => $story->duration,
  26. 'can_reply' => (bool) $story->can_reply,
  27. 'can_react' => (bool) $story->can_react,
  28. 'attachment' => [
  29. 'type' => $type,
  30. 'url' => url(Storage::url($story->path)),
  31. 'mediaType' => $story->mime,
  32. ],
  33. ];
  34. }
  35. }