mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 08:13:16 +00:00
Update Status caption render logic
This commit is contained in:
parent
0917953dbc
commit
fb8dbb95db
9 changed files with 719 additions and 708 deletions
|
@ -2,18 +2,17 @@
|
|||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Cache;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\LikeService;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\MediaTagService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\StatusLabelService;
|
||||
use App\Services\StatusMentionService;
|
||||
use App\Services\PollService;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\StatusMentionService;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class StatusStateless extends JsonResource
|
||||
{
|
||||
|
@ -28,49 +27,50 @@ class StatusStateless extends JsonResource
|
|||
$status = $this;
|
||||
$taggedPeople = MediaTagService::get($status->id);
|
||||
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
||||
$autoLink = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'_v' => 1,
|
||||
'id' => (string) $status->id,
|
||||
'_v' => 1,
|
||||
'id' => (string) $status->id,
|
||||
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
||||
'shortcode' => HashidService::encode($status->id),
|
||||
'uri' => $status->url(),
|
||||
'url' => $status->url(),
|
||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||
'reblog' => null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
'emojis' => CustomEmoji::scan($status->caption),
|
||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => null,
|
||||
'favourited' => null,
|
||||
'muted' => null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->scope ?? $status->visibility,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null
|
||||
],
|
||||
'language' => null,
|
||||
'mentions' => StatusMentionService::get($status->id),
|
||||
'pf_type' => $status->type ?? $status->setType(),
|
||||
'reply_count' => (int) $status->reply_count,
|
||||
'comments_disabled' => (bool) $status->comments_disabled,
|
||||
'thread' => false,
|
||||
'replies' => [],
|
||||
'parent' => [],
|
||||
'place' => $status->place,
|
||||
'local' => (bool) $status->local,
|
||||
'taggedPeople' => $taggedPeople,
|
||||
'liked_by' => LikeService::likedBy($status),
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => AccountService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
'poll' => $poll
|
||||
'shortcode' => HashidService::encode($status->id),
|
||||
'uri' => $status->url(),
|
||||
'url' => $status->url(),
|
||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||
'reblog' => null,
|
||||
'content' => $autoLink,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
'emojis' => CustomEmoji::scan($status->caption),
|
||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => null,
|
||||
'favourited' => null,
|
||||
'muted' => null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->scope ?? $status->visibility,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null,
|
||||
],
|
||||
'language' => null,
|
||||
'mentions' => StatusMentionService::get($status->id),
|
||||
'pf_type' => $status->type ?? $status->setType(),
|
||||
'reply_count' => (int) $status->reply_count,
|
||||
'comments_disabled' => (bool) $status->comments_disabled,
|
||||
'thread' => false,
|
||||
'replies' => [],
|
||||
'parent' => [],
|
||||
'place' => $status->place,
|
||||
'local' => (bool) $status->local,
|
||||
'taggedPeople' => $taggedPeople,
|
||||
'liked_by' => LikeService::likedBy($status),
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => AccountService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
'poll' => $poll,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,59 +2,62 @@
|
|||
|
||||
namespace App\Transformer\ActivityPub;
|
||||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use App\Services\MediaService;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use League\Fractal;
|
||||
|
||||
class StatusTransformer extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
[
|
||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||
'featured' => [
|
||||
'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
|
||||
],
|
||||
'@context' => [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
[
|
||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||
'featured' => [
|
||||
'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'id' => $status->url(),
|
||||
'id' => $status->url(),
|
||||
|
||||
// TODO: handle other types
|
||||
'type' => 'Note',
|
||||
// TODO: handle other types
|
||||
'type' => 'Note',
|
||||
|
||||
// XXX: CW Title
|
||||
'summary' => null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'inReplyTo' => null,
|
||||
// XXX: CW Title
|
||||
'summary' => null,
|
||||
'content' => $content,
|
||||
'inReplyTo' => null,
|
||||
|
||||
// TODO: fix date format
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => [
|
||||
// TODO: handle proper scope
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
],
|
||||
'cc' => [
|
||||
// TODO: add cc's
|
||||
$status->profile->permalink('/followers'),
|
||||
],
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'atomUri' => $status->url(),
|
||||
'inReplyToAtomUri' => null,
|
||||
'attachment' => MediaService::activitypub($status->id),
|
||||
'tag' => [],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country
|
||||
// TODO: fix date format
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => [
|
||||
// TODO: handle proper scope
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
],
|
||||
'cc' => [
|
||||
// TODO: add cc's
|
||||
$status->profile->permalink('/followers'),
|
||||
],
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'atomUri' => $status->url(),
|
||||
'inReplyToAtomUri' => null,
|
||||
'attachment' => MediaService::activitypub($status->id),
|
||||
'tag' => [],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country,
|
||||
] : null,
|
||||
];
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,140 +2,144 @@
|
|||
|
||||
namespace App\Transformer\ActivityPub\Verb;
|
||||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Fractal;
|
||||
|
||||
class CreateNote extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@' . $webfinger;
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name
|
||||
];
|
||||
})->toArray();
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@'.$webfinger;
|
||||
|
||||
if($status->in_reply_to_id != null) {
|
||||
$parent = $status->parent()->profile;
|
||||
if($parent) {
|
||||
$webfinger = $parent->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@' . $webfinger;
|
||||
$reply = [
|
||||
'type' => 'Mention',
|
||||
'href' => $parent->permalink(),
|
||||
'name' => $name
|
||||
];
|
||||
$mentions = array_merge($reply, $mentions);
|
||||
}
|
||||
}
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
if ($status->in_reply_to_id != null) {
|
||||
$parent = $status->parent()->profile;
|
||||
if ($parent) {
|
||||
$webfinger = $parent->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@'.$webfinger;
|
||||
$reply = [
|
||||
'type' => 'Mention',
|
||||
'href' => $parent->permalink(),
|
||||
'name' => $name,
|
||||
];
|
||||
$mentions = array_merge($reply, $mentions);
|
||||
}
|
||||
}
|
||||
|
||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||
$emoji = array_merge($emojis, $mentions);
|
||||
$tags = array_merge($emoji, $hashtags);
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean'
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set'
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji',
|
||||
'blurhash' => 'toot:blurhash',
|
||||
]
|
||||
],
|
||||
'id' => $status->permalink(),
|
||||
'type' => 'Create',
|
||||
'actor' => $status->profile->permalink(),
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'object' => [
|
||||
'id' => $status->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||
$res = [
|
||||
'type' => $media->activityVerb(),
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => $media->caption,
|
||||
];
|
||||
if($media->blurhash) {
|
||||
$res['blurhash'] = $media->blurhash;
|
||||
}
|
||||
if($media->width) {
|
||||
$res['width'] = $media->width;
|
||||
}
|
||||
if($media->height) {
|
||||
$res['height'] = $media->height;
|
||||
}
|
||||
return $res;
|
||||
})->toArray(),
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country
|
||||
] : null,
|
||||
]
|
||||
];
|
||||
}
|
||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||
$emoji = array_merge($emojis, $mentions);
|
||||
$tags = array_merge($emoji, $hashtags);
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean',
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set',
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji',
|
||||
'blurhash' => 'toot:blurhash',
|
||||
],
|
||||
],
|
||||
'id' => $status->permalink(),
|
||||
'type' => 'Create',
|
||||
'actor' => $status->profile->permalink(),
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'object' => [
|
||||
'id' => $status->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||
'content' => $content,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||
$res = [
|
||||
'type' => $media->activityVerb(),
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => $media->caption,
|
||||
];
|
||||
if ($media->blurhash) {
|
||||
$res['blurhash'] = $media->blurhash;
|
||||
}
|
||||
if ($media->width) {
|
||||
$res['width'] = $media->width;
|
||||
}
|
||||
if ($media->height) {
|
||||
$res['height'] = $media->height;
|
||||
}
|
||||
|
||||
return $res;
|
||||
})->toArray(),
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country,
|
||||
] : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,133 +2,137 @@
|
|||
|
||||
namespace App\Transformer\ActivityPub\Verb;
|
||||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Fractal;
|
||||
|
||||
class Note extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@' . $webfinger;
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name
|
||||
];
|
||||
})->toArray();
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@'.$webfinger;
|
||||
|
||||
if($status->in_reply_to_id != null) {
|
||||
$parent = $status->parent()->profile;
|
||||
if($parent) {
|
||||
$webfinger = $parent->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@' . $webfinger;
|
||||
$reply = [
|
||||
'type' => 'Mention',
|
||||
'href' => $parent->permalink(),
|
||||
'name' => $name
|
||||
];
|
||||
array_push($mentions, $reply);
|
||||
}
|
||||
}
|
||||
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||
$emoji = array_merge($emojis, $mentions);
|
||||
$tags = array_merge($emoji, $hashtags);
|
||||
if ($status->in_reply_to_id != null) {
|
||||
$parent = $status->parent()->profile;
|
||||
if ($parent) {
|
||||
$webfinger = $parent->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@'.$webfinger;
|
||||
$reply = [
|
||||
'type' => 'Mention',
|
||||
'href' => $parent->permalink(),
|
||||
'name' => $name,
|
||||
];
|
||||
array_push($mentions, $reply);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean'
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set'
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji',
|
||||
'blurhash' => 'toot:blurhash',
|
||||
]
|
||||
],
|
||||
'id' => $status->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||
$res = [
|
||||
'type' => $media->activityVerb(),
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => $media->caption,
|
||||
];
|
||||
if($media->blurhash) {
|
||||
$res['blurhash'] = $media->blurhash;
|
||||
}
|
||||
if($media->width) {
|
||||
$res['width'] = $media->width;
|
||||
}
|
||||
if($media->height) {
|
||||
$res['height'] = $media->height;
|
||||
}
|
||||
return $res;
|
||||
})->toArray(),
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||
$emoji = array_merge($emojis, $mentions);
|
||||
$tags = array_merge($emoji, $hashtags);
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean',
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set',
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji',
|
||||
'blurhash' => 'toot:blurhash',
|
||||
],
|
||||
],
|
||||
'id' => $status->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||
'content' => $content,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||
$res = [
|
||||
'type' => $media->activityVerb(),
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => $media->caption,
|
||||
];
|
||||
if ($media->blurhash) {
|
||||
$res['blurhash'] = $media->blurhash;
|
||||
}
|
||||
if ($media->width) {
|
||||
$res['width'] = $media->width;
|
||||
}
|
||||
if ($media->height) {
|
||||
$res['height'] = $media->height;
|
||||
}
|
||||
|
||||
return $res;
|
||||
})->toArray(),
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country,
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,104 +3,107 @@
|
|||
namespace App\Transformer\ActivityPub\Verb;
|
||||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Fractal;
|
||||
|
||||
class Question extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@' . $webfinger;
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name
|
||||
];
|
||||
})->toArray();
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@'.$webfinger;
|
||||
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
$tags = array_merge($mentions, $hashtags);
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean'
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set'
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji'
|
||||
]
|
||||
],
|
||||
'id' => $status->url(),
|
||||
'type' => 'Question',
|
||||
'summary' => null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => [],
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country
|
||||
] : null,
|
||||
'endTime' => $status->poll->expires_at->toAtomString(),
|
||||
'oneOf' => collect($status->poll->poll_options)->map(function($option, $index) use($status) {
|
||||
return [
|
||||
'type' => 'Note',
|
||||
'name' => $option,
|
||||
'replies' => [
|
||||
'type' => 'Collection',
|
||||
'totalItems' => $status->poll->cached_tallies[$index]
|
||||
]
|
||||
];
|
||||
})
|
||||
];
|
||||
}
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
$tags = array_merge($mentions, $hashtags);
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean',
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set',
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji',
|
||||
],
|
||||
],
|
||||
'id' => $status->url(),
|
||||
'type' => 'Question',
|
||||
'summary' => null,
|
||||
'content' => $content,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => [],
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country,
|
||||
] : null,
|
||||
'endTime' => $status->poll->expires_at->toAtomString(),
|
||||
'oneOf' => collect($status->poll->poll_options)->map(function ($option, $index) use ($status) {
|
||||
return [
|
||||
'type' => 'Note',
|
||||
'name' => $option,
|
||||
'replies' => [
|
||||
'type' => 'Collection',
|
||||
'totalItems' => $status->poll->cached_tallies[$index],
|
||||
],
|
||||
];
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,132 +2,135 @@
|
|||
|
||||
namespace App\Transformer\ActivityPub\Verb;
|
||||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Fractal;
|
||||
|
||||
class UpdateNote extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@' . $webfinger;
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name
|
||||
];
|
||||
})->toArray();
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$mentions = $status->mentions->map(function ($mention) {
|
||||
$webfinger = $mention->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@'.$webfinger;
|
||||
|
||||
if($status->in_reply_to_id != null) {
|
||||
$parent = $status->parent()->profile;
|
||||
if($parent) {
|
||||
$webfinger = $parent->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@' . $webfinger;
|
||||
$reply = [
|
||||
'type' => 'Mention',
|
||||
'href' => $parent->permalink(),
|
||||
'name' => $name
|
||||
];
|
||||
$mentions = array_merge($reply, $mentions);
|
||||
}
|
||||
}
|
||||
return [
|
||||
'type' => 'Mention',
|
||||
'href' => $mention->permalink(),
|
||||
'name' => $name,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
if ($status->in_reply_to_id != null) {
|
||||
$parent = $status->parent()->profile;
|
||||
if ($parent) {
|
||||
$webfinger = $parent->emailUrl();
|
||||
$name = Str::startsWith($webfinger, '@') ?
|
||||
$webfinger :
|
||||
'@'.$webfinger;
|
||||
$reply = [
|
||||
'type' => 'Mention',
|
||||
'href' => $parent->permalink(),
|
||||
'name' => $name,
|
||||
];
|
||||
$mentions = array_merge($reply, $mentions);
|
||||
}
|
||||
}
|
||||
|
||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||
$emoji = array_merge($emojis, $mentions);
|
||||
$tags = array_merge($emoji, $hashtags);
|
||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||
return [
|
||||
'type' => 'Hashtag',
|
||||
'href' => $hashtag->url(),
|
||||
'name' => "#{$hashtag->name}",
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
$latestEdit = $status->edits()->latest()->first();
|
||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||
$emoji = array_merge($emojis, $mentions);
|
||||
$tags = array_merge($emoji, $hashtags);
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean'
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set'
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id'
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji'
|
||||
]
|
||||
],
|
||||
'id' => $status->permalink('#updates/' . $latestEdit->id),
|
||||
'type' => 'Update',
|
||||
'actor' => $status->profile->permalink(),
|
||||
'published' => $latestEdit->created_at->toAtomString(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'object' => [
|
||||
'id' => $status->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||
return [
|
||||
'type' => $media->activityVerb(),
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => $media->caption,
|
||||
];
|
||||
})->toArray(),
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
||||
'updated' => $latestEdit->created_at->toAtomString(),
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country
|
||||
] : null,
|
||||
]
|
||||
];
|
||||
}
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
$latestEdit = $status->edits()->latest()->first();
|
||||
|
||||
return [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
[
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'schema' => 'http://schema.org/',
|
||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||
'commentsEnabled' => [
|
||||
'@id' => 'pixelfed:commentsEnabled',
|
||||
'@type' => 'schema:Boolean',
|
||||
],
|
||||
'capabilities' => [
|
||||
'@id' => 'pixelfed:capabilities',
|
||||
'@container' => '@set',
|
||||
],
|
||||
'announce' => [
|
||||
'@id' => 'pixelfed:canAnnounce',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'like' => [
|
||||
'@id' => 'pixelfed:canLike',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'reply' => [
|
||||
'@id' => 'pixelfed:canReply',
|
||||
'@type' => '@id',
|
||||
],
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'Emoji' => 'toot:Emoji',
|
||||
],
|
||||
],
|
||||
'id' => $status->permalink('#updates/'.$latestEdit->id),
|
||||
'type' => 'Update',
|
||||
'actor' => $status->profile->permalink(),
|
||||
'published' => $latestEdit->created_at->toAtomString(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'object' => [
|
||||
'id' => $status->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||
'content' => $content,
|
||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
'url' => $status->url(),
|
||||
'attributedTo' => $status->profile->permalink(),
|
||||
'to' => $status->scopeToAudience('to'),
|
||||
'cc' => $status->scopeToAudience('cc'),
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||
return [
|
||||
'type' => $media->activityVerb(),
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => $media->caption,
|
||||
];
|
||||
})->toArray(),
|
||||
'tag' => $tags,
|
||||
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||
'updated' => $latestEdit->created_at->toAtomString(),
|
||||
'capabilities' => [
|
||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||
],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
'name' => $status->place->name,
|
||||
'longitude' => $status->place->long,
|
||||
'latitude' => $status->place->lat,
|
||||
'country' => $status->place->country,
|
||||
] : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,48 +2,50 @@
|
|||
|
||||
namespace App\Transformer\Api\Mastodon\v1;
|
||||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use Cache;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\ProfileService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use League\Fractal;
|
||||
|
||||
class StatusTransformer extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
return [
|
||||
'id' => (string) $status->id,
|
||||
'created_at' => $status->created_at->toJSON(),
|
||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->visibility ?? $status->scope,
|
||||
'language' => 'en',
|
||||
'uri' => $status->permalink(''),
|
||||
'url' => $status->url(),
|
||||
'replies_count' => $status->reply_count ?? 0,
|
||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => $status->shared(),
|
||||
'favourited' => $status->liked(),
|
||||
'muted' => false,
|
||||
'bookmarked' => false,
|
||||
'content' => $status->rendered ?? $status->caption ?? '',
|
||||
'reblog' => null,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null
|
||||
],
|
||||
'mentions' => [],
|
||||
'emojis' => [],
|
||||
'card' => null,
|
||||
'poll' => null,
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => ProfileService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
];
|
||||
}
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'id' => (string) $status->id,
|
||||
'created_at' => $status->created_at->toJSON(),
|
||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->visibility ?? $status->scope,
|
||||
'language' => 'en',
|
||||
'uri' => $status->permalink(''),
|
||||
'url' => $status->url(),
|
||||
'replies_count' => $status->reply_count ?? 0,
|
||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => $status->shared(),
|
||||
'favourited' => $status->liked(),
|
||||
'muted' => false,
|
||||
'bookmarked' => false,
|
||||
'content' => $content,
|
||||
'reblog' => null,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null,
|
||||
],
|
||||
'mentions' => [],
|
||||
'emojis' => [],
|
||||
'card' => null,
|
||||
'poll' => null,
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => ProfileService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,76 +2,73 @@
|
|||
|
||||
namespace App\Transformer\Api;
|
||||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use Cache;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\LikeService;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\MediaTagService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\PollService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\StatusLabelService;
|
||||
use App\Services\StatusMentionService;
|
||||
use App\Services\PollService;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use League\Fractal;
|
||||
|
||||
class StatusStatelessTransformer extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$taggedPeople = MediaTagService::get($status->id);
|
||||
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
||||
$rendered = config('exp.autolink') ?
|
||||
( $status->caption ? Autolink::create()->autolink($status->caption) : '' ) :
|
||||
( $status->rendered ?? $status->caption );
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$taggedPeople = MediaTagService::get($status->id);
|
||||
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
||||
$rendered = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'_v' => 1,
|
||||
'id' => (string) $status->id,
|
||||
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
||||
'shortcode' => HashidService::encode($status->id),
|
||||
'uri' => $status->url(),
|
||||
'url' => $status->url(),
|
||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id, false) : null,
|
||||
'content' => $rendered,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
'emojis' => CustomEmoji::scan($status->caption),
|
||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => null,
|
||||
'favourited' => null,
|
||||
'muted' => null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->scope ?? $status->visibility,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null
|
||||
],
|
||||
'language' => null,
|
||||
'mentions' => StatusMentionService::get($status->id),
|
||||
'pf_type' => $status->type ?? $status->setType(),
|
||||
'reply_count' => (int) $status->reply_count,
|
||||
'comments_disabled' => (bool) $status->comments_disabled,
|
||||
'thread' => false,
|
||||
'replies' => [],
|
||||
'parent' => [],
|
||||
'place' => $status->place,
|
||||
'local' => (bool) $status->local,
|
||||
'taggedPeople' => $taggedPeople,
|
||||
'label' => StatusLabelService::get($status),
|
||||
'liked_by' => LikeService::likedBy($status),
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => AccountService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
'poll' => $poll,
|
||||
'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
|
||||
];
|
||||
}
|
||||
return [
|
||||
'_v' => 1,
|
||||
'id' => (string) $status->id,
|
||||
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
||||
'shortcode' => HashidService::encode($status->id),
|
||||
'uri' => $status->url(),
|
||||
'url' => $status->url(),
|
||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id, false) : null,
|
||||
'content' => $rendered,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
'emojis' => CustomEmoji::scan($status->caption),
|
||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => null,
|
||||
'favourited' => null,
|
||||
'muted' => null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->scope ?? $status->visibility,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null,
|
||||
],
|
||||
'language' => null,
|
||||
'mentions' => StatusMentionService::get($status->id),
|
||||
'pf_type' => $status->type ?? $status->setType(),
|
||||
'reply_count' => (int) $status->reply_count,
|
||||
'comments_disabled' => (bool) $status->comments_disabled,
|
||||
'thread' => false,
|
||||
'replies' => [],
|
||||
'parent' => [],
|
||||
'place' => $status->place,
|
||||
'local' => (bool) $status->local,
|
||||
'taggedPeople' => $taggedPeople,
|
||||
'label' => StatusLabelService::get($status),
|
||||
'liked_by' => LikeService::likedBy($status),
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => AccountService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
'poll' => $poll,
|
||||
'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,80 +2,75 @@
|
|||
|
||||
namespace App\Transformer\Api;
|
||||
|
||||
use App\Like;
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use Cache;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Services\BookmarkService;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\LikeService;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\MediaTagService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\PollService;
|
||||
use App\Services\ProfileService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\StatusLabelService;
|
||||
use App\Services\StatusMentionService;
|
||||
use App\Services\ProfileService;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Services\PollService;
|
||||
use App\Models\CustomEmoji;
|
||||
use App\Services\BookmarkService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use League\Fractal;
|
||||
|
||||
class StatusTransformer extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$pid = request()->user()->profile_id;
|
||||
$taggedPeople = MediaTagService::get($status->id);
|
||||
$poll = $status->type === 'poll' ? PollService::get($status->id, $pid) : null;
|
||||
$rendered = config('exp.autolink') ?
|
||||
( $status->caption ? Autolink::create()->autolink($status->caption) : '' ) :
|
||||
( $status->rendered ?? $status->caption );
|
||||
public function transform(Status $status)
|
||||
{
|
||||
$pid = request()->user()->profile_id;
|
||||
$taggedPeople = MediaTagService::get($status->id);
|
||||
$poll = $status->type === 'poll' ? PollService::get($status->id, $pid) : null;
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
return [
|
||||
'_v' => 1,
|
||||
'id' => (string) $status->id,
|
||||
'shortcode' => HashidService::encode($status->id),
|
||||
'uri' => $status->url(),
|
||||
'url' => $status->url(),
|
||||
'in_reply_to_id' => (string) $status->in_reply_to_id,
|
||||
'in_reply_to_account_id' => (string) $status->in_reply_to_profile_id,
|
||||
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id) : null,
|
||||
'content' => $rendered,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
'emojis' => CustomEmoji::scan($status->caption),
|
||||
'reblogs_count' => 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => $status->shared(),
|
||||
'favourited' => $status->liked(),
|
||||
'muted' => null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->scope ?? $status->visibility,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null
|
||||
],
|
||||
'language' => null,
|
||||
'mentions' => StatusMentionService::get($status->id),
|
||||
'pf_type' => $status->type ?? $status->setType(),
|
||||
'reply_count' => (int) $status->reply_count,
|
||||
'comments_disabled' => (bool) $status->comments_disabled,
|
||||
'thread' => false,
|
||||
'replies' => [],
|
||||
'parent' => [],
|
||||
'place' => $status->place,
|
||||
'local' => (bool) $status->local,
|
||||
'taggedPeople' => $taggedPeople,
|
||||
'label' => StatusLabelService::get($status),
|
||||
'liked_by' => LikeService::likedBy($status),
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => ProfileService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
'poll' => $poll,
|
||||
'bookmarked' => BookmarkService::get($pid, $status->id),
|
||||
'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
|
||||
];
|
||||
}
|
||||
return [
|
||||
'_v' => 1,
|
||||
'id' => (string) $status->id,
|
||||
'shortcode' => HashidService::encode($status->id),
|
||||
'uri' => $status->url(),
|
||||
'url' => $status->url(),
|
||||
'in_reply_to_id' => (string) $status->in_reply_to_id,
|
||||
'in_reply_to_account_id' => (string) $status->in_reply_to_profile_id,
|
||||
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id) : null,
|
||||
'content' => $content,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
'emojis' => CustomEmoji::scan($status->caption),
|
||||
'reblogs_count' => 0,
|
||||
'favourites_count' => $status->likes_count ?? 0,
|
||||
'reblogged' => $status->shared(),
|
||||
'favourited' => $status->liked(),
|
||||
'muted' => null,
|
||||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'spoiler_text' => $status->cw_summary ?? '',
|
||||
'visibility' => $status->scope ?? $status->visibility,
|
||||
'application' => [
|
||||
'name' => 'web',
|
||||
'website' => null,
|
||||
],
|
||||
'language' => null,
|
||||
'mentions' => StatusMentionService::get($status->id),
|
||||
'pf_type' => $status->type ?? $status->setType(),
|
||||
'reply_count' => (int) $status->reply_count,
|
||||
'comments_disabled' => (bool) $status->comments_disabled,
|
||||
'thread' => false,
|
||||
'replies' => [],
|
||||
'parent' => [],
|
||||
'place' => $status->place,
|
||||
'local' => (bool) $status->local,
|
||||
'taggedPeople' => $taggedPeople,
|
||||
'label' => StatusLabelService::get($status),
|
||||
'liked_by' => LikeService::likedBy($status),
|
||||
'media_attachments' => MediaService::get($status->id),
|
||||
'account' => ProfileService::get($status->profile_id, true),
|
||||
'tags' => StatusHashtagService::statusTags($status->id),
|
||||
'poll' => $poll,
|
||||
'bookmarked' => BookmarkService::get($pid, $status->id),
|
||||
'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue