mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Story transformers
This commit is contained in:
parent
37054e8393
commit
f808b7b19d
3 changed files with 93 additions and 0 deletions
29
app/Transformer/ActivityPub/Verb/CreateStory.php
Normal file
29
app/Transformer/ActivityPub/Verb/CreateStory.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Transformer\ActivityPub\Verb;
|
||||||
|
|
||||||
|
use Storage;
|
||||||
|
use App\Story;
|
||||||
|
use League\Fractal;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class CreateStory extends Fractal\TransformerAbstract
|
||||||
|
{
|
||||||
|
public function transform(Story $story)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id' => $story->permalink(),
|
||||||
|
'type' => 'Add',
|
||||||
|
'actor' => $story->profile->permalink(),
|
||||||
|
'to' => [
|
||||||
|
$story->profile->permalink('/followers')
|
||||||
|
],
|
||||||
|
'object' => [
|
||||||
|
'id' => $story->url(),
|
||||||
|
'type' => 'Story',
|
||||||
|
'object' => $story->bearcapUrl(),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
25
app/Transformer/ActivityPub/Verb/DeleteStory.php
Normal file
25
app/Transformer/ActivityPub/Verb/DeleteStory.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Transformer\ActivityPub\Verb;
|
||||||
|
|
||||||
|
use Storage;
|
||||||
|
use App\Story;
|
||||||
|
use League\Fractal;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class DeleteStory extends Fractal\TransformerAbstract
|
||||||
|
{
|
||||||
|
public function transform(Story $story)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id' => $story->url() . '#delete',
|
||||||
|
'type' => 'Delete',
|
||||||
|
'actor' => $story->profile->permalink(),
|
||||||
|
'object' => [
|
||||||
|
'id' => $story->url(),
|
||||||
|
'type' => 'Story',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
39
app/Transformer/ActivityPub/Verb/StoryVerb.php
Normal file
39
app/Transformer/ActivityPub/Verb/StoryVerb.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Transformer\ActivityPub\Verb;
|
||||||
|
|
||||||
|
use Storage;
|
||||||
|
use App\Story;
|
||||||
|
use League\Fractal;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class StoryVerb extends Fractal\TransformerAbstract
|
||||||
|
{
|
||||||
|
public function transform(Story $story)
|
||||||
|
{
|
||||||
|
$type = $story->type == 'photo' ? 'Image' :
|
||||||
|
( $story->type == 'video' ? 'Video' :
|
||||||
|
'Document' );
|
||||||
|
|
||||||
|
return [
|
||||||
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id' => $story->url(),
|
||||||
|
'type' => 'Story',
|
||||||
|
'to' => [
|
||||||
|
$story->profile->permalink('/followers')
|
||||||
|
],
|
||||||
|
'cc' => [],
|
||||||
|
'attributedTo' => $story->profile->permalink(),
|
||||||
|
'published' => $story->created_at->toAtomString(),
|
||||||
|
'expiresAt' => $story->expires_at->toAtomString(),
|
||||||
|
'duration' => $story->duration,
|
||||||
|
'can_reply' => (bool) $story->can_reply,
|
||||||
|
'can_react' => (bool) $story->can_react,
|
||||||
|
'attachment' => [
|
||||||
|
'type' => $type,
|
||||||
|
'url' => url(Storage::url($story->path)),
|
||||||
|
'mediaType' => $story->mime,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue