mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-02 03:03:17 +00:00
commit
c04e19bc4b
14 changed files with 734 additions and 762 deletions
|
@ -3,6 +3,8 @@
|
||||||
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.12.3...dev)
|
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.12.3...dev)
|
||||||
- Update AP helpers, reject statuses with invalid dates ([960f3849](https://github.com/pixelfed/pixelfed/commit/960f3849))
|
- Update AP helpers, reject statuses with invalid dates ([960f3849](https://github.com/pixelfed/pixelfed/commit/960f3849))
|
||||||
- Update DirectMessage API, fix broken threading ([044d410c](https://github.com/pixelfed/pixelfed/commit/044d410c))
|
- Update DirectMessage API, fix broken threading ([044d410c](https://github.com/pixelfed/pixelfed/commit/044d410c))
|
||||||
|
- Update Status caption render logic ([fb8dbb95](https://github.com/pixelfed/pixelfed/commit/fb8dbb95))
|
||||||
|
- Update ApiV1Controller, fix bookmark bug. Closes #5216 ([9f7cc52c](https://github.com/pixelfed/pixelfed/commit/9f7cc52c))
|
||||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||||
|
|
||||||
## [v0.12.4 (2024-11-08)](https://github.com/pixelfed/pixelfed/compare/v0.12.4...dev)
|
## [v0.12.4 (2024-11-08)](https://github.com/pixelfed/pixelfed/compare/v0.12.4...dev)
|
||||||
|
|
|
@ -1878,7 +1878,7 @@ class ApiV1Controller extends Controller
|
||||||
$media->original_sha256 = $hash;
|
$media->original_sha256 = $hash;
|
||||||
$media->size = $photo->getSize();
|
$media->size = $photo->getSize();
|
||||||
$media->mime = $mime;
|
$media->mime = $mime;
|
||||||
$media->caption = $request->input('description') ?? "";
|
$media->caption = $request->input('description') ?? '';
|
||||||
$media->filter_class = $filterClass;
|
$media->filter_class = $filterClass;
|
||||||
$media->filter_name = $filterName;
|
$media->filter_name = $filterName;
|
||||||
if ($license) {
|
if ($license) {
|
||||||
|
@ -2106,7 +2106,7 @@ class ApiV1Controller extends Controller
|
||||||
$media->original_sha256 = $hash;
|
$media->original_sha256 = $hash;
|
||||||
$media->size = $photo->getSize();
|
$media->size = $photo->getSize();
|
||||||
$media->mime = $mime;
|
$media->mime = $mime;
|
||||||
$media->caption = $request->input('description') ?? "";
|
$media->caption = $request->input('description') ?? '';
|
||||||
$media->filter_class = $filterClass;
|
$media->filter_class = $filterClass;
|
||||||
$media->filter_name = $filterName;
|
$media->filter_name = $filterName;
|
||||||
if ($license) {
|
if ($license) {
|
||||||
|
@ -3951,6 +3951,7 @@ class ApiV1Controller extends Controller
|
||||||
abort_unless($request->user()->tokenCan('write'), 403);
|
abort_unless($request->user()->tokenCan('write'), 403);
|
||||||
|
|
||||||
$status = Status::findOrFail($id);
|
$status = Status::findOrFail($id);
|
||||||
|
$user = $request->user();
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
$account = AccountService::get($status->profile_id);
|
$account = AccountService::get($status->profile_id);
|
||||||
abort_if(isset($account['moved'], $account['moved']['id']), 422, 'Cannot bookmark a post from an account that has migrated');
|
abort_if(isset($account['moved'], $account['moved']['id']), 422, 'Cannot bookmark a post from an account that has migrated');
|
||||||
|
@ -3994,6 +3995,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$status = Status::findOrFail($id);
|
$status = Status::findOrFail($id);
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
abort_if($user->has_roles && ! UserRoleService::can('can-bookmark', $user->id), 403, 'Invalid permissions for this action');
|
abort_if($user->has_roles && ! UserRoleService::can('can-bookmark', $user->id), 403, 'Invalid permissions for this action');
|
||||||
abort_if($status->in_reply_to_id || $status->reblog_of_id, 404);
|
abort_if($status->in_reply_to_id || $status->reblog_of_id, 404);
|
||||||
|
|
|
@ -31,8 +31,8 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->fractal = new Fractal\Manager();
|
$this->fractal = new Fractal\Manager;
|
||||||
$this->fractal->setSerializer(new ArraySerializer());
|
$this->fractal->setSerializer(new ArraySerializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getUserData($user)
|
protected function getUserData($user)
|
||||||
|
@ -74,7 +74,7 @@ class PublicApiController extends Controller
|
||||||
abort_if(! in_array($cached['visibility'], ['public', 'unlisted']), 403);
|
abort_if(! in_array($cached['visibility'], ['public', 'unlisted']), 403);
|
||||||
$res = ['status' => $cached];
|
$res = ['status' => $cached];
|
||||||
} else {
|
} else {
|
||||||
$item = new Fractal\Resource\Item($status, new StatusStatelessTransformer());
|
$item = new Fractal\Resource\Item($status, new StatusStatelessTransformer);
|
||||||
$res = [
|
$res = [
|
||||||
'status' => $this->fractal->createData($item)->toArray(),
|
'status' => $this->fractal->createData($item)->toArray(),
|
||||||
];
|
];
|
||||||
|
@ -141,7 +141,7 @@ class PublicApiController extends Controller
|
||||||
$replies = $status->comments()
|
$replies = $status->comments()
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('scope', $scope)
|
->whereIn('scope', $scope)
|
||||||
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
||||||
->where('id', '>=', $request->min_id)
|
->where('id', '>=', $request->min_id)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
@ -150,7 +150,7 @@ class PublicApiController extends Controller
|
||||||
$replies = $status->comments()
|
$replies = $status->comments()
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('scope', $scope)
|
->whereIn('scope', $scope)
|
||||||
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
||||||
->where('id', '<=', $request->max_id)
|
->where('id', '<=', $request->max_id)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
@ -159,12 +159,12 @@ class PublicApiController extends Controller
|
||||||
$replies = Status::whereInReplyToId($status->id)
|
$replies = Status::whereInReplyToId($status->id)
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('scope', $scope)
|
->whereIn('scope', $scope)
|
||||||
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource = new Fractal\Resource\Collection($replies, new StatusStatelessTransformer(), 'data');
|
$resource = new Fractal\Resource\Collection($replies, new StatusStatelessTransformer, 'data');
|
||||||
$resource->setPaginator(new IlluminatePaginatorAdapter($replies));
|
$resource->setPaginator(new IlluminatePaginatorAdapter($replies));
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
$res = $this->fractal->createData($resource)->toArray();
|
||||||
|
|
||||||
|
@ -271,7 +271,6 @@ class PublicApiController extends Controller
|
||||||
'id',
|
'id',
|
||||||
'uri',
|
'uri',
|
||||||
'caption',
|
'caption',
|
||||||
'rendered',
|
|
||||||
'profile_id',
|
'profile_id',
|
||||||
'type',
|
'type',
|
||||||
'in_reply_to_id',
|
'in_reply_to_id',
|
||||||
|
@ -405,7 +404,6 @@ class PublicApiController extends Controller
|
||||||
'id',
|
'id',
|
||||||
'uri',
|
'uri',
|
||||||
'caption',
|
'caption',
|
||||||
'rendered',
|
|
||||||
'profile_id',
|
'profile_id',
|
||||||
'type',
|
'type',
|
||||||
'in_reply_to_id',
|
'in_reply_to_id',
|
||||||
|
@ -456,7 +454,6 @@ class PublicApiController extends Controller
|
||||||
'id',
|
'id',
|
||||||
'uri',
|
'uri',
|
||||||
'caption',
|
'caption',
|
||||||
'rendered',
|
|
||||||
'profile_id',
|
'profile_id',
|
||||||
'type',
|
'type',
|
||||||
'in_reply_to_id',
|
'in_reply_to_id',
|
||||||
|
|
|
@ -2,18 +2,17 @@
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use App\Models\CustomEmoji;
|
||||||
use Cache;
|
|
||||||
use App\Services\AccountService;
|
use App\Services\AccountService;
|
||||||
use App\Services\HashidService;
|
use App\Services\HashidService;
|
||||||
use App\Services\LikeService;
|
use App\Services\LikeService;
|
||||||
use App\Services\MediaService;
|
use App\Services\MediaService;
|
||||||
use App\Services\MediaTagService;
|
use App\Services\MediaTagService;
|
||||||
use App\Services\StatusHashtagService;
|
|
||||||
use App\Services\StatusLabelService;
|
|
||||||
use App\Services\StatusMentionService;
|
|
||||||
use App\Services\PollService;
|
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
|
class StatusStateless extends JsonResource
|
||||||
{
|
{
|
||||||
|
@ -28,49 +27,50 @@ class StatusStateless extends JsonResource
|
||||||
$status = $this;
|
$status = $this;
|
||||||
$taggedPeople = MediaTagService::get($status->id);
|
$taggedPeople = MediaTagService::get($status->id);
|
||||||
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
||||||
|
$autoLink = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'_v' => 1,
|
'_v' => 1,
|
||||||
'id' => (string) $status->id,
|
'id' => (string) $status->id,
|
||||||
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
||||||
'shortcode' => HashidService::encode($status->id),
|
'shortcode' => HashidService::encode($status->id),
|
||||||
'uri' => $status->url(),
|
'uri' => $status->url(),
|
||||||
'url' => $status->url(),
|
'url' => $status->url(),
|
||||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
'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,
|
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||||
'reblog' => null,
|
'reblog' => null,
|
||||||
'content' => $status->rendered ?? $status->caption,
|
'content' => $autoLink,
|
||||||
'content_text' => $status->caption,
|
'content_text' => $status->caption,
|
||||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||||
'emojis' => CustomEmoji::scan($status->caption),
|
'emojis' => CustomEmoji::scan($status->caption),
|
||||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||||
'favourites_count' => $status->likes_count ?? 0,
|
'favourites_count' => $status->likes_count ?? 0,
|
||||||
'reblogged' => null,
|
'reblogged' => null,
|
||||||
'favourited' => null,
|
'favourited' => null,
|
||||||
'muted' => null,
|
'muted' => null,
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'spoiler_text' => $status->cw_summary ?? '',
|
'spoiler_text' => $status->cw_summary ?? '',
|
||||||
'visibility' => $status->scope ?? $status->visibility,
|
'visibility' => $status->scope ?? $status->visibility,
|
||||||
'application' => [
|
'application' => [
|
||||||
'name' => 'web',
|
'name' => 'web',
|
||||||
'website' => null
|
'website' => null,
|
||||||
],
|
],
|
||||||
'language' => null,
|
'language' => null,
|
||||||
'mentions' => StatusMentionService::get($status->id),
|
'mentions' => StatusMentionService::get($status->id),
|
||||||
'pf_type' => $status->type ?? $status->setType(),
|
'pf_type' => $status->type ?? $status->setType(),
|
||||||
'reply_count' => (int) $status->reply_count,
|
'reply_count' => (int) $status->reply_count,
|
||||||
'comments_disabled' => (bool) $status->comments_disabled,
|
'comments_disabled' => (bool) $status->comments_disabled,
|
||||||
'thread' => false,
|
'thread' => false,
|
||||||
'replies' => [],
|
'replies' => [],
|
||||||
'parent' => [],
|
'parent' => [],
|
||||||
'place' => $status->place,
|
'place' => $status->place,
|
||||||
'local' => (bool) $status->local,
|
'local' => (bool) $status->local,
|
||||||
'taggedPeople' => $taggedPeople,
|
'taggedPeople' => $taggedPeople,
|
||||||
'liked_by' => LikeService::likedBy($status),
|
'liked_by' => LikeService::likedBy($status),
|
||||||
'media_attachments' => MediaService::get($status->id),
|
'media_attachments' => MediaService::get($status->id),
|
||||||
'account' => AccountService::get($status->profile_id, true),
|
'account' => AccountService::get($status->profile_id, true),
|
||||||
'tags' => StatusHashtagService::statusTags($status->id),
|
'tags' => StatusHashtagService::statusTags($status->id),
|
||||||
'poll' => $poll
|
'poll' => $poll,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,46 +308,6 @@ class Status extends Model
|
||||||
return $this->comments()->orderBy('created_at', 'desc')->take(3);
|
return $this->comments()->orderBy('created_at', 'desc')->take(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toActivityPubObject()
|
|
||||||
{
|
|
||||||
if($this->local == false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$profile = $this->profile;
|
|
||||||
$to = $this->scopeToAudience('to');
|
|
||||||
$cc = $this->scopeToAudience('cc');
|
|
||||||
return [
|
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
|
||||||
'id' => $this->permalink(),
|
|
||||||
'type' => 'Create',
|
|
||||||
'actor' => $profile->permalink(),
|
|
||||||
'published' => str_replace('+00:00', 'Z', $this->created_at->format(DATE_RFC3339_EXTENDED)),
|
|
||||||
'to' => $to,
|
|
||||||
'cc' => $cc,
|
|
||||||
'object' => [
|
|
||||||
'id' => $this->url(),
|
|
||||||
'type' => 'Note',
|
|
||||||
'summary' => null,
|
|
||||||
'inReplyTo' => null,
|
|
||||||
'published' => str_replace('+00:00', 'Z', $this->created_at->format(DATE_RFC3339_EXTENDED)),
|
|
||||||
'url' => $this->url(),
|
|
||||||
'attributedTo' => $this->profile->url(),
|
|
||||||
'to' => $to,
|
|
||||||
'cc' => $cc,
|
|
||||||
'sensitive' => (bool) $this->is_nsfw,
|
|
||||||
'content' => $this->rendered,
|
|
||||||
'attachment' => $this->media->map(function($media) {
|
|
||||||
return [
|
|
||||||
'type' => 'Document',
|
|
||||||
'mediaType' => $media->mime,
|
|
||||||
'url' => $media->url(),
|
|
||||||
'name' => null
|
|
||||||
];
|
|
||||||
})->toArray()
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function scopeToAudience($audience)
|
public function scopeToAudience($audience)
|
||||||
{
|
{
|
||||||
if(!in_array($audience, ['to', 'cc']) || $this->local == false) {
|
if(!in_array($audience, ['to', 'cc']) || $this->local == false) {
|
||||||
|
|
|
@ -2,59 +2,62 @@
|
||||||
|
|
||||||
namespace App\Transformer\ActivityPub;
|
namespace App\Transformer\ActivityPub;
|
||||||
|
|
||||||
use App\Status;
|
|
||||||
use League\Fractal;
|
|
||||||
use App\Services\MediaService;
|
use App\Services\MediaService;
|
||||||
|
use App\Status;
|
||||||
|
use App\Util\Lexer\Autolink;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class StatusTransformer extends Fractal\TransformerAbstract
|
class StatusTransformer extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
|
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'@context' => [
|
'@context' => [
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'https://w3id.org/security/v1',
|
'https://w3id.org/security/v1',
|
||||||
[
|
[
|
||||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||||
'featured' => [
|
'featured' => [
|
||||||
'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
|
'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
|
||||||
],
|
],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
'id' => $status->url(),
|
||||||
'id' => $status->url(),
|
|
||||||
|
|
||||||
// TODO: handle other types
|
// TODO: handle other types
|
||||||
'type' => 'Note',
|
'type' => 'Note',
|
||||||
|
|
||||||
// XXX: CW Title
|
// XXX: CW Title
|
||||||
'summary' => null,
|
'summary' => null,
|
||||||
'content' => $status->rendered ?? $status->caption,
|
'content' => $content,
|
||||||
'inReplyTo' => null,
|
'inReplyTo' => null,
|
||||||
|
|
||||||
// TODO: fix date format
|
// TODO: fix date format
|
||||||
'published' => $status->created_at->toAtomString(),
|
'published' => $status->created_at->toAtomString(),
|
||||||
'url' => $status->url(),
|
'url' => $status->url(),
|
||||||
'attributedTo' => $status->profile->permalink(),
|
'attributedTo' => $status->profile->permalink(),
|
||||||
'to' => [
|
'to' => [
|
||||||
// TODO: handle proper scope
|
// TODO: handle proper scope
|
||||||
'https://www.w3.org/ns/activitystreams#Public',
|
'https://www.w3.org/ns/activitystreams#Public',
|
||||||
],
|
],
|
||||||
'cc' => [
|
'cc' => [
|
||||||
// TODO: add cc's
|
// TODO: add cc's
|
||||||
$status->profile->permalink('/followers'),
|
$status->profile->permalink('/followers'),
|
||||||
],
|
],
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'atomUri' => $status->url(),
|
'atomUri' => $status->url(),
|
||||||
'inReplyToAtomUri' => null,
|
'inReplyToAtomUri' => null,
|
||||||
'attachment' => MediaService::activitypub($status->id),
|
'attachment' => MediaService::activitypub($status->id),
|
||||||
'tag' => [],
|
'tag' => [],
|
||||||
'location' => $status->place_id ? [
|
'location' => $status->place_id ? [
|
||||||
'type' => 'Place',
|
'type' => 'Place',
|
||||||
'name' => $status->place->name,
|
'name' => $status->place->name,
|
||||||
'longitude' => $status->place->long,
|
'longitude' => $status->place->long,
|
||||||
'latitude' => $status->place->lat,
|
'latitude' => $status->place->lat,
|
||||||
'country' => $status->place->country
|
'country' => $status->place->country,
|
||||||
] : null,
|
] : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,140 +2,144 @@
|
||||||
|
|
||||||
namespace App\Transformer\ActivityPub\Verb;
|
namespace App\Transformer\ActivityPub\Verb;
|
||||||
|
|
||||||
use App\Status;
|
|
||||||
use League\Fractal;
|
|
||||||
use App\Models\CustomEmoji;
|
use App\Models\CustomEmoji;
|
||||||
|
use App\Status;
|
||||||
|
use App\Util\Lexer\Autolink;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class CreateNote extends Fractal\TransformerAbstract
|
class CreateNote extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
$mentions = $status->mentions->map(function ($mention) {
|
$mentions = $status->mentions->map(function ($mention) {
|
||||||
$webfinger = $mention->emailUrl();
|
$webfinger = $mention->emailUrl();
|
||||||
$name = Str::startsWith($webfinger, '@') ?
|
$name = Str::startsWith($webfinger, '@') ?
|
||||||
$webfinger :
|
$webfinger :
|
||||||
'@' . $webfinger;
|
'@'.$webfinger;
|
||||||
return [
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => $mention->permalink(),
|
|
||||||
'name' => $name
|
|
||||||
];
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
if($status->in_reply_to_id != null) {
|
return [
|
||||||
$parent = $status->parent()->profile;
|
'type' => 'Mention',
|
||||||
if($parent) {
|
'href' => $mention->permalink(),
|
||||||
$webfinger = $parent->emailUrl();
|
'name' => $name,
|
||||||
$name = Str::startsWith($webfinger, '@') ?
|
];
|
||||||
$webfinger :
|
})->toArray();
|
||||||
'@' . $webfinger;
|
|
||||||
$reply = [
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => $parent->permalink(),
|
|
||||||
'name' => $name
|
|
||||||
];
|
|
||||||
$mentions = array_merge($reply, $mentions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
if ($status->in_reply_to_id != null) {
|
||||||
return [
|
$parent = $status->parent()->profile;
|
||||||
'type' => 'Hashtag',
|
if ($parent) {
|
||||||
'href' => $hashtag->url(),
|
$webfinger = $parent->emailUrl();
|
||||||
'name' => "#{$hashtag->name}",
|
$name = Str::startsWith($webfinger, '@') ?
|
||||||
];
|
$webfinger :
|
||||||
})->toArray();
|
'@'.$webfinger;
|
||||||
|
$reply = [
|
||||||
|
'type' => 'Mention',
|
||||||
|
'href' => $parent->permalink(),
|
||||||
|
'name' => $name,
|
||||||
|
];
|
||||||
|
$mentions = array_merge($reply, $mentions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||||
$emoji = array_merge($emojis, $mentions);
|
return [
|
||||||
$tags = array_merge($emoji, $hashtags);
|
'type' => 'Hashtag',
|
||||||
|
'href' => $hashtag->url(),
|
||||||
|
'name' => "#{$hashtag->name}",
|
||||||
|
];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
return [
|
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||||
'@context' => [
|
$emoji = array_merge($emojis, $mentions);
|
||||||
'https://w3id.org/security/v1',
|
$tags = array_merge($emoji, $hashtags);
|
||||||
'https://www.w3.org/ns/activitystreams',
|
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
[
|
|
||||||
'Hashtag' => 'as:Hashtag',
|
return [
|
||||||
'sensitive' => 'as:sensitive',
|
'@context' => [
|
||||||
'schema' => 'http://schema.org/',
|
'https://w3id.org/security/v1',
|
||||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'commentsEnabled' => [
|
[
|
||||||
'@id' => 'pixelfed:commentsEnabled',
|
'Hashtag' => 'as:Hashtag',
|
||||||
'@type' => 'schema:Boolean'
|
'sensitive' => 'as:sensitive',
|
||||||
],
|
'schema' => 'http://schema.org/',
|
||||||
'capabilities' => [
|
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||||
'@id' => 'pixelfed:capabilities',
|
'commentsEnabled' => [
|
||||||
'@container' => '@set'
|
'@id' => 'pixelfed:commentsEnabled',
|
||||||
],
|
'@type' => 'schema:Boolean',
|
||||||
'announce' => [
|
],
|
||||||
'@id' => 'pixelfed:canAnnounce',
|
'capabilities' => [
|
||||||
'@type' => '@id'
|
'@id' => 'pixelfed:capabilities',
|
||||||
],
|
'@container' => '@set',
|
||||||
'like' => [
|
],
|
||||||
'@id' => 'pixelfed:canLike',
|
'announce' => [
|
||||||
'@type' => '@id'
|
'@id' => 'pixelfed:canAnnounce',
|
||||||
],
|
'@type' => '@id',
|
||||||
'reply' => [
|
],
|
||||||
'@id' => 'pixelfed:canReply',
|
'like' => [
|
||||||
'@type' => '@id'
|
'@id' => 'pixelfed:canLike',
|
||||||
],
|
'@type' => '@id',
|
||||||
'toot' => 'http://joinmastodon.org/ns#',
|
],
|
||||||
'Emoji' => 'toot:Emoji',
|
'reply' => [
|
||||||
'blurhash' => 'toot:blurhash',
|
'@id' => 'pixelfed:canReply',
|
||||||
]
|
'@type' => '@id',
|
||||||
],
|
],
|
||||||
'id' => $status->permalink(),
|
'toot' => 'http://joinmastodon.org/ns#',
|
||||||
'type' => 'Create',
|
'Emoji' => 'toot:Emoji',
|
||||||
'actor' => $status->profile->permalink(),
|
'blurhash' => 'toot:blurhash',
|
||||||
'published' => $status->created_at->toAtomString(),
|
],
|
||||||
'to' => $status->scopeToAudience('to'),
|
],
|
||||||
'cc' => $status->scopeToAudience('cc'),
|
'id' => $status->permalink(),
|
||||||
'object' => [
|
'type' => 'Create',
|
||||||
'id' => $status->url(),
|
'actor' => $status->profile->permalink(),
|
||||||
'type' => 'Note',
|
'published' => $status->created_at->toAtomString(),
|
||||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
'to' => $status->scopeToAudience('to'),
|
||||||
'content' => $status->rendered ?? $status->caption,
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
'object' => [
|
||||||
'published' => $status->created_at->toAtomString(),
|
'id' => $status->url(),
|
||||||
'url' => $status->url(),
|
'type' => 'Note',
|
||||||
'attributedTo' => $status->profile->permalink(),
|
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||||
'to' => $status->scopeToAudience('to'),
|
'content' => $content,
|
||||||
'cc' => $status->scopeToAudience('cc'),
|
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'published' => $status->created_at->toAtomString(),
|
||||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
'url' => $status->url(),
|
||||||
$res = [
|
'attributedTo' => $status->profile->permalink(),
|
||||||
'type' => $media->activityVerb(),
|
'to' => $status->scopeToAudience('to'),
|
||||||
'mediaType' => $media->mime,
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
'url' => $media->url(),
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'name' => $media->caption,
|
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||||
];
|
$res = [
|
||||||
if($media->blurhash) {
|
'type' => $media->activityVerb(),
|
||||||
$res['blurhash'] = $media->blurhash;
|
'mediaType' => $media->mime,
|
||||||
}
|
'url' => $media->url(),
|
||||||
if($media->width) {
|
'name' => $media->caption,
|
||||||
$res['width'] = $media->width;
|
];
|
||||||
}
|
if ($media->blurhash) {
|
||||||
if($media->height) {
|
$res['blurhash'] = $media->blurhash;
|
||||||
$res['height'] = $media->height;
|
}
|
||||||
}
|
if ($media->width) {
|
||||||
return $res;
|
$res['width'] = $media->width;
|
||||||
})->toArray(),
|
}
|
||||||
'tag' => $tags,
|
if ($media->height) {
|
||||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
$res['height'] = $media->height;
|
||||||
'capabilities' => [
|
}
|
||||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
|
||||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
return $res;
|
||||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
})->toArray(),
|
||||||
],
|
'tag' => $tags,
|
||||||
'location' => $status->place_id ? [
|
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||||
'type' => 'Place',
|
'capabilities' => [
|
||||||
'name' => $status->place->name,
|
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'longitude' => $status->place->long,
|
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'latitude' => $status->place->lat,
|
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'country' => $status->place->country
|
],
|
||||||
] : null,
|
'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;
|
namespace App\Transformer\ActivityPub\Verb;
|
||||||
|
|
||||||
use App\Status;
|
|
||||||
use League\Fractal;
|
|
||||||
use App\Models\CustomEmoji;
|
use App\Models\CustomEmoji;
|
||||||
|
use App\Status;
|
||||||
|
use App\Util\Lexer\Autolink;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class Note extends Fractal\TransformerAbstract
|
class Note extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
|
|
||||||
$mentions = $status->mentions->map(function ($mention) {
|
$mentions = $status->mentions->map(function ($mention) {
|
||||||
$webfinger = $mention->emailUrl();
|
$webfinger = $mention->emailUrl();
|
||||||
$name = Str::startsWith($webfinger, '@') ?
|
$name = Str::startsWith($webfinger, '@') ?
|
||||||
$webfinger :
|
$webfinger :
|
||||||
'@' . $webfinger;
|
'@'.$webfinger;
|
||||||
return [
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => $mention->permalink(),
|
|
||||||
'name' => $name
|
|
||||||
];
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
if($status->in_reply_to_id != null) {
|
return [
|
||||||
$parent = $status->parent()->profile;
|
'type' => 'Mention',
|
||||||
if($parent) {
|
'href' => $mention->permalink(),
|
||||||
$webfinger = $parent->emailUrl();
|
'name' => $name,
|
||||||
$name = Str::startsWith($webfinger, '@') ?
|
];
|
||||||
$webfinger :
|
})->toArray();
|
||||||
'@' . $webfinger;
|
|
||||||
$reply = [
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => $parent->permalink(),
|
|
||||||
'name' => $name
|
|
||||||
];
|
|
||||||
array_push($mentions, $reply);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
if ($status->in_reply_to_id != null) {
|
||||||
return [
|
$parent = $status->parent()->profile;
|
||||||
'type' => 'Hashtag',
|
if ($parent) {
|
||||||
'href' => $hashtag->url(),
|
$webfinger = $parent->emailUrl();
|
||||||
'name' => "#{$hashtag->name}",
|
$name = Str::startsWith($webfinger, '@') ?
|
||||||
];
|
$webfinger :
|
||||||
})->toArray();
|
'@'.$webfinger;
|
||||||
|
$reply = [
|
||||||
|
'type' => 'Mention',
|
||||||
|
'href' => $parent->permalink(),
|
||||||
|
'name' => $name,
|
||||||
|
];
|
||||||
|
array_push($mentions, $reply);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||||
$emoji = array_merge($emojis, $mentions);
|
return [
|
||||||
$tags = array_merge($emoji, $hashtags);
|
'type' => 'Hashtag',
|
||||||
|
'href' => $hashtag->url(),
|
||||||
|
'name' => "#{$hashtag->name}",
|
||||||
|
];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
return [
|
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
||||||
'@context' => [
|
$emoji = array_merge($emojis, $mentions);
|
||||||
'https://w3id.org/security/v1',
|
$tags = array_merge($emoji, $hashtags);
|
||||||
'https://www.w3.org/ns/activitystreams',
|
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
[
|
|
||||||
'Hashtag' => 'as:Hashtag',
|
return [
|
||||||
'sensitive' => 'as:sensitive',
|
'@context' => [
|
||||||
'schema' => 'http://schema.org/',
|
'https://w3id.org/security/v1',
|
||||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'commentsEnabled' => [
|
[
|
||||||
'@id' => 'pixelfed:commentsEnabled',
|
'Hashtag' => 'as:Hashtag',
|
||||||
'@type' => 'schema:Boolean'
|
'sensitive' => 'as:sensitive',
|
||||||
],
|
'schema' => 'http://schema.org/',
|
||||||
'capabilities' => [
|
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||||
'@id' => 'pixelfed:capabilities',
|
'commentsEnabled' => [
|
||||||
'@container' => '@set'
|
'@id' => 'pixelfed:commentsEnabled',
|
||||||
],
|
'@type' => 'schema:Boolean',
|
||||||
'announce' => [
|
],
|
||||||
'@id' => 'pixelfed:canAnnounce',
|
'capabilities' => [
|
||||||
'@type' => '@id'
|
'@id' => 'pixelfed:capabilities',
|
||||||
],
|
'@container' => '@set',
|
||||||
'like' => [
|
],
|
||||||
'@id' => 'pixelfed:canLike',
|
'announce' => [
|
||||||
'@type' => '@id'
|
'@id' => 'pixelfed:canAnnounce',
|
||||||
],
|
'@type' => '@id',
|
||||||
'reply' => [
|
],
|
||||||
'@id' => 'pixelfed:canReply',
|
'like' => [
|
||||||
'@type' => '@id'
|
'@id' => 'pixelfed:canLike',
|
||||||
],
|
'@type' => '@id',
|
||||||
'toot' => 'http://joinmastodon.org/ns#',
|
],
|
||||||
'Emoji' => 'toot:Emoji',
|
'reply' => [
|
||||||
'blurhash' => 'toot:blurhash',
|
'@id' => 'pixelfed:canReply',
|
||||||
]
|
'@type' => '@id',
|
||||||
],
|
],
|
||||||
'id' => $status->url(),
|
'toot' => 'http://joinmastodon.org/ns#',
|
||||||
'type' => 'Note',
|
'Emoji' => 'toot:Emoji',
|
||||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
'blurhash' => 'toot:blurhash',
|
||||||
'content' => $status->rendered ?? $status->caption,
|
],
|
||||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
],
|
||||||
'published' => $status->created_at->toAtomString(),
|
'id' => $status->url(),
|
||||||
'url' => $status->url(),
|
'type' => 'Note',
|
||||||
'attributedTo' => $status->profile->permalink(),
|
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||||
'to' => $status->scopeToAudience('to'),
|
'content' => $content,
|
||||||
'cc' => $status->scopeToAudience('cc'),
|
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'published' => $status->created_at->toAtomString(),
|
||||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
'url' => $status->url(),
|
||||||
$res = [
|
'attributedTo' => $status->profile->permalink(),
|
||||||
'type' => $media->activityVerb(),
|
'to' => $status->scopeToAudience('to'),
|
||||||
'mediaType' => $media->mime,
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
'url' => $media->url(),
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'name' => $media->caption,
|
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||||
];
|
$res = [
|
||||||
if($media->blurhash) {
|
'type' => $media->activityVerb(),
|
||||||
$res['blurhash'] = $media->blurhash;
|
'mediaType' => $media->mime,
|
||||||
}
|
'url' => $media->url(),
|
||||||
if($media->width) {
|
'name' => $media->caption,
|
||||||
$res['width'] = $media->width;
|
];
|
||||||
}
|
if ($media->blurhash) {
|
||||||
if($media->height) {
|
$res['blurhash'] = $media->blurhash;
|
||||||
$res['height'] = $media->height;
|
}
|
||||||
}
|
if ($media->width) {
|
||||||
return $res;
|
$res['width'] = $media->width;
|
||||||
})->toArray(),
|
}
|
||||||
'tag' => $tags,
|
if ($media->height) {
|
||||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
$res['height'] = $media->height;
|
||||||
'capabilities' => [
|
}
|
||||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
|
||||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
return $res;
|
||||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
})->toArray(),
|
||||||
],
|
'tag' => $tags,
|
||||||
'location' => $status->place_id ? [
|
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||||
'type' => 'Place',
|
'capabilities' => [
|
||||||
'name' => $status->place->name,
|
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'longitude' => $status->place->long,
|
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'latitude' => $status->place->lat,
|
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'country' => $status->place->country
|
],
|
||||||
] : null,
|
'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;
|
namespace App\Transformer\ActivityPub\Verb;
|
||||||
|
|
||||||
use App\Status;
|
use App\Status;
|
||||||
use League\Fractal;
|
use App\Util\Lexer\Autolink;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class Question extends Fractal\TransformerAbstract
|
class Question extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
$mentions = $status->mentions->map(function ($mention) {
|
$mentions = $status->mentions->map(function ($mention) {
|
||||||
$webfinger = $mention->emailUrl();
|
$webfinger = $mention->emailUrl();
|
||||||
$name = Str::startsWith($webfinger, '@') ?
|
$name = Str::startsWith($webfinger, '@') ?
|
||||||
$webfinger :
|
$webfinger :
|
||||||
'@' . $webfinger;
|
'@'.$webfinger;
|
||||||
return [
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => $mention->permalink(),
|
|
||||||
'name' => $name
|
|
||||||
];
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
return [
|
||||||
return [
|
'type' => 'Mention',
|
||||||
'type' => 'Hashtag',
|
'href' => $mention->permalink(),
|
||||||
'href' => $hashtag->url(),
|
'name' => $name,
|
||||||
'name' => "#{$hashtag->name}",
|
];
|
||||||
];
|
})->toArray();
|
||||||
})->toArray();
|
|
||||||
$tags = array_merge($mentions, $hashtags);
|
|
||||||
|
|
||||||
return [
|
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||||
'@context' => [
|
return [
|
||||||
'https://w3id.org/security/v1',
|
'type' => 'Hashtag',
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'href' => $hashtag->url(),
|
||||||
[
|
'name' => "#{$hashtag->name}",
|
||||||
'Hashtag' => 'as:Hashtag',
|
];
|
||||||
'sensitive' => 'as:sensitive',
|
})->toArray();
|
||||||
'schema' => 'http://schema.org/',
|
$tags = array_merge($mentions, $hashtags);
|
||||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
'commentsEnabled' => [
|
|
||||||
'@id' => 'pixelfed:commentsEnabled',
|
return [
|
||||||
'@type' => 'schema:Boolean'
|
'@context' => [
|
||||||
],
|
'https://w3id.org/security/v1',
|
||||||
'capabilities' => [
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'@id' => 'pixelfed:capabilities',
|
[
|
||||||
'@container' => '@set'
|
'Hashtag' => 'as:Hashtag',
|
||||||
],
|
'sensitive' => 'as:sensitive',
|
||||||
'announce' => [
|
'schema' => 'http://schema.org/',
|
||||||
'@id' => 'pixelfed:canAnnounce',
|
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||||
'@type' => '@id'
|
'commentsEnabled' => [
|
||||||
],
|
'@id' => 'pixelfed:commentsEnabled',
|
||||||
'like' => [
|
'@type' => 'schema:Boolean',
|
||||||
'@id' => 'pixelfed:canLike',
|
],
|
||||||
'@type' => '@id'
|
'capabilities' => [
|
||||||
],
|
'@id' => 'pixelfed:capabilities',
|
||||||
'reply' => [
|
'@container' => '@set',
|
||||||
'@id' => 'pixelfed:canReply',
|
],
|
||||||
'@type' => '@id'
|
'announce' => [
|
||||||
],
|
'@id' => 'pixelfed:canAnnounce',
|
||||||
'toot' => 'http://joinmastodon.org/ns#',
|
'@type' => '@id',
|
||||||
'Emoji' => 'toot:Emoji'
|
],
|
||||||
]
|
'like' => [
|
||||||
],
|
'@id' => 'pixelfed:canLike',
|
||||||
'id' => $status->url(),
|
'@type' => '@id',
|
||||||
'type' => 'Question',
|
],
|
||||||
'summary' => null,
|
'reply' => [
|
||||||
'content' => $status->rendered ?? $status->caption,
|
'@id' => 'pixelfed:canReply',
|
||||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
'@type' => '@id',
|
||||||
'published' => $status->created_at->toAtomString(),
|
],
|
||||||
'url' => $status->url(),
|
'toot' => 'http://joinmastodon.org/ns#',
|
||||||
'attributedTo' => $status->profile->permalink(),
|
'Emoji' => 'toot:Emoji',
|
||||||
'to' => $status->scopeToAudience('to'),
|
],
|
||||||
'cc' => $status->scopeToAudience('cc'),
|
],
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'id' => $status->url(),
|
||||||
'attachment' => [],
|
'type' => 'Question',
|
||||||
'tag' => $tags,
|
'summary' => null,
|
||||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
'content' => $content,
|
||||||
'capabilities' => [
|
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
'published' => $status->created_at->toAtomString(),
|
||||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
'url' => $status->url(),
|
||||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
'attributedTo' => $status->profile->permalink(),
|
||||||
],
|
'to' => $status->scopeToAudience('to'),
|
||||||
'location' => $status->place_id ? [
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
'type' => 'Place',
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'name' => $status->place->name,
|
'attachment' => [],
|
||||||
'longitude' => $status->place->long,
|
'tag' => $tags,
|
||||||
'latitude' => $status->place->lat,
|
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||||
'country' => $status->place->country
|
'capabilities' => [
|
||||||
] : null,
|
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'endTime' => $status->poll->expires_at->toAtomString(),
|
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'oneOf' => collect($status->poll->poll_options)->map(function($option, $index) use($status) {
|
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
return [
|
],
|
||||||
'type' => 'Note',
|
'location' => $status->place_id ? [
|
||||||
'name' => $option,
|
'type' => 'Place',
|
||||||
'replies' => [
|
'name' => $status->place->name,
|
||||||
'type' => 'Collection',
|
'longitude' => $status->place->long,
|
||||||
'totalItems' => $status->poll->cached_tallies[$index]
|
'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;
|
namespace App\Transformer\ActivityPub\Verb;
|
||||||
|
|
||||||
use App\Status;
|
|
||||||
use League\Fractal;
|
|
||||||
use App\Models\CustomEmoji;
|
use App\Models\CustomEmoji;
|
||||||
|
use App\Status;
|
||||||
|
use App\Util\Lexer\Autolink;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class UpdateNote extends Fractal\TransformerAbstract
|
class UpdateNote extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
$mentions = $status->mentions->map(function ($mention) {
|
$mentions = $status->mentions->map(function ($mention) {
|
||||||
$webfinger = $mention->emailUrl();
|
$webfinger = $mention->emailUrl();
|
||||||
$name = Str::startsWith($webfinger, '@') ?
|
$name = Str::startsWith($webfinger, '@') ?
|
||||||
$webfinger :
|
$webfinger :
|
||||||
'@' . $webfinger;
|
'@'.$webfinger;
|
||||||
return [
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => $mention->permalink(),
|
|
||||||
'name' => $name
|
|
||||||
];
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
if($status->in_reply_to_id != null) {
|
return [
|
||||||
$parent = $status->parent()->profile;
|
'type' => 'Mention',
|
||||||
if($parent) {
|
'href' => $mention->permalink(),
|
||||||
$webfinger = $parent->emailUrl();
|
'name' => $name,
|
||||||
$name = Str::startsWith($webfinger, '@') ?
|
];
|
||||||
$webfinger :
|
})->toArray();
|
||||||
'@' . $webfinger;
|
|
||||||
$reply = [
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => $parent->permalink(),
|
|
||||||
'name' => $name
|
|
||||||
];
|
|
||||||
$mentions = array_merge($reply, $mentions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hashtags = $status->hashtags->map(function ($hashtag) {
|
if ($status->in_reply_to_id != null) {
|
||||||
return [
|
$parent = $status->parent()->profile;
|
||||||
'type' => 'Hashtag',
|
if ($parent) {
|
||||||
'href' => $hashtag->url(),
|
$webfinger = $parent->emailUrl();
|
||||||
'name' => "#{$hashtag->name}",
|
$name = Str::startsWith($webfinger, '@') ?
|
||||||
];
|
$webfinger :
|
||||||
})->toArray();
|
'@'.$webfinger;
|
||||||
|
$reply = [
|
||||||
|
'type' => 'Mention',
|
||||||
|
'href' => $parent->permalink(),
|
||||||
|
'name' => $name,
|
||||||
|
];
|
||||||
|
$mentions = array_merge($reply, $mentions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
$hashtags = $status->hashtags->map(function ($hashtag) {
|
||||||
$emoji = array_merge($emojis, $mentions);
|
return [
|
||||||
$tags = array_merge($emoji, $hashtags);
|
'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 [
|
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
'@context' => [
|
$latestEdit = $status->edits()->latest()->first();
|
||||||
'https://w3id.org/security/v1',
|
|
||||||
'https://www.w3.org/ns/activitystreams',
|
return [
|
||||||
[
|
'@context' => [
|
||||||
'Hashtag' => 'as:Hashtag',
|
'https://w3id.org/security/v1',
|
||||||
'sensitive' => 'as:sensitive',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'schema' => 'http://schema.org/',
|
[
|
||||||
'pixelfed' => 'http://pixelfed.org/ns#',
|
'Hashtag' => 'as:Hashtag',
|
||||||
'commentsEnabled' => [
|
'sensitive' => 'as:sensitive',
|
||||||
'@id' => 'pixelfed:commentsEnabled',
|
'schema' => 'http://schema.org/',
|
||||||
'@type' => 'schema:Boolean'
|
'pixelfed' => 'http://pixelfed.org/ns#',
|
||||||
],
|
'commentsEnabled' => [
|
||||||
'capabilities' => [
|
'@id' => 'pixelfed:commentsEnabled',
|
||||||
'@id' => 'pixelfed:capabilities',
|
'@type' => 'schema:Boolean',
|
||||||
'@container' => '@set'
|
],
|
||||||
],
|
'capabilities' => [
|
||||||
'announce' => [
|
'@id' => 'pixelfed:capabilities',
|
||||||
'@id' => 'pixelfed:canAnnounce',
|
'@container' => '@set',
|
||||||
'@type' => '@id'
|
],
|
||||||
],
|
'announce' => [
|
||||||
'like' => [
|
'@id' => 'pixelfed:canAnnounce',
|
||||||
'@id' => 'pixelfed:canLike',
|
'@type' => '@id',
|
||||||
'@type' => '@id'
|
],
|
||||||
],
|
'like' => [
|
||||||
'reply' => [
|
'@id' => 'pixelfed:canLike',
|
||||||
'@id' => 'pixelfed:canReply',
|
'@type' => '@id',
|
||||||
'@type' => '@id'
|
],
|
||||||
],
|
'reply' => [
|
||||||
'toot' => 'http://joinmastodon.org/ns#',
|
'@id' => 'pixelfed:canReply',
|
||||||
'Emoji' => 'toot:Emoji'
|
'@type' => '@id',
|
||||||
]
|
],
|
||||||
],
|
'toot' => 'http://joinmastodon.org/ns#',
|
||||||
'id' => $status->permalink('#updates/' . $latestEdit->id),
|
'Emoji' => 'toot:Emoji',
|
||||||
'type' => 'Update',
|
],
|
||||||
'actor' => $status->profile->permalink(),
|
],
|
||||||
'published' => $latestEdit->created_at->toAtomString(),
|
'id' => $status->permalink('#updates/'.$latestEdit->id),
|
||||||
'to' => $status->scopeToAudience('to'),
|
'type' => 'Update',
|
||||||
'cc' => $status->scopeToAudience('cc'),
|
'actor' => $status->profile->permalink(),
|
||||||
'object' => [
|
'published' => $latestEdit->created_at->toAtomString(),
|
||||||
'id' => $status->url(),
|
'to' => $status->scopeToAudience('to'),
|
||||||
'type' => 'Note',
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
'object' => [
|
||||||
'content' => $status->rendered ?? $status->caption,
|
'id' => $status->url(),
|
||||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
'type' => 'Note',
|
||||||
'published' => $status->created_at->toAtomString(),
|
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
||||||
'url' => $status->url(),
|
'content' => $content,
|
||||||
'attributedTo' => $status->profile->permalink(),
|
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||||
'to' => $status->scopeToAudience('to'),
|
'published' => $status->created_at->toAtomString(),
|
||||||
'cc' => $status->scopeToAudience('cc'),
|
'url' => $status->url(),
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'attributedTo' => $status->profile->permalink(),
|
||||||
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
'to' => $status->scopeToAudience('to'),
|
||||||
return [
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
'type' => $media->activityVerb(),
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'mediaType' => $media->mime,
|
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
||||||
'url' => $media->url(),
|
return [
|
||||||
'name' => $media->caption,
|
'type' => $media->activityVerb(),
|
||||||
];
|
'mediaType' => $media->mime,
|
||||||
})->toArray(),
|
'url' => $media->url(),
|
||||||
'tag' => $tags,
|
'name' => $media->caption,
|
||||||
'commentsEnabled' => (bool) !$status->comments_disabled,
|
];
|
||||||
'updated' => $latestEdit->created_at->toAtomString(),
|
})->toArray(),
|
||||||
'capabilities' => [
|
'tag' => $tags,
|
||||||
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
'commentsEnabled' => (bool) ! $status->comments_disabled,
|
||||||
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
'updated' => $latestEdit->created_at->toAtomString(),
|
||||||
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
'capabilities' => [
|
||||||
],
|
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'location' => $status->place_id ? [
|
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'type' => 'Place',
|
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'name' => $status->place->name,
|
],
|
||||||
'longitude' => $status->place->long,
|
'location' => $status->place_id ? [
|
||||||
'latitude' => $status->place->lat,
|
'type' => 'Place',
|
||||||
'country' => $status->place->country
|
'name' => $status->place->name,
|
||||||
] : null,
|
'longitude' => $status->place->long,
|
||||||
]
|
'latitude' => $status->place->lat,
|
||||||
];
|
'country' => $status->place->country,
|
||||||
}
|
] : null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,48 +2,50 @@
|
||||||
|
|
||||||
namespace App\Transformer\Api\Mastodon\v1;
|
namespace App\Transformer\Api\Mastodon\v1;
|
||||||
|
|
||||||
use App\Status;
|
|
||||||
use League\Fractal;
|
|
||||||
use Cache;
|
|
||||||
use App\Services\MediaService;
|
use App\Services\MediaService;
|
||||||
use App\Services\ProfileService;
|
use App\Services\ProfileService;
|
||||||
use App\Services\StatusHashtagService;
|
use App\Services\StatusHashtagService;
|
||||||
|
use App\Status;
|
||||||
|
use App\Util\Lexer\Autolink;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class StatusTransformer extends Fractal\TransformerAbstract
|
class StatusTransformer extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
return [
|
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
'id' => (string) $status->id,
|
|
||||||
'created_at' => $status->created_at->toJSON(),
|
return [
|
||||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
'id' => (string) $status->id,
|
||||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
'created_at' => $status->created_at->toJSON(),
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||||
'spoiler_text' => $status->cw_summary ?? '',
|
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||||
'visibility' => $status->visibility ?? $status->scope,
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'language' => 'en',
|
'spoiler_text' => $status->cw_summary ?? '',
|
||||||
'uri' => $status->permalink(''),
|
'visibility' => $status->visibility ?? $status->scope,
|
||||||
'url' => $status->url(),
|
'language' => 'en',
|
||||||
'replies_count' => $status->reply_count ?? 0,
|
'uri' => $status->permalink(''),
|
||||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
'url' => $status->url(),
|
||||||
'favourites_count' => $status->likes_count ?? 0,
|
'replies_count' => $status->reply_count ?? 0,
|
||||||
'reblogged' => $status->shared(),
|
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||||
'favourited' => $status->liked(),
|
'favourites_count' => $status->likes_count ?? 0,
|
||||||
'muted' => false,
|
'reblogged' => $status->shared(),
|
||||||
'bookmarked' => false,
|
'favourited' => $status->liked(),
|
||||||
'content' => $status->rendered ?? $status->caption ?? '',
|
'muted' => false,
|
||||||
'reblog' => null,
|
'bookmarked' => false,
|
||||||
'application' => [
|
'content' => $content,
|
||||||
'name' => 'web',
|
'reblog' => null,
|
||||||
'website' => null
|
'application' => [
|
||||||
],
|
'name' => 'web',
|
||||||
'mentions' => [],
|
'website' => null,
|
||||||
'emojis' => [],
|
],
|
||||||
'card' => null,
|
'mentions' => [],
|
||||||
'poll' => null,
|
'emojis' => [],
|
||||||
'media_attachments' => MediaService::get($status->id),
|
'card' => null,
|
||||||
'account' => ProfileService::get($status->profile_id, true),
|
'poll' => null,
|
||||||
'tags' => StatusHashtagService::statusTags($status->id),
|
'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;
|
namespace App\Transformer\Api;
|
||||||
|
|
||||||
use App\Status;
|
use App\Models\CustomEmoji;
|
||||||
use League\Fractal;
|
|
||||||
use Cache;
|
|
||||||
use App\Services\AccountService;
|
use App\Services\AccountService;
|
||||||
use App\Services\HashidService;
|
use App\Services\HashidService;
|
||||||
use App\Services\LikeService;
|
use App\Services\LikeService;
|
||||||
use App\Services\MediaService;
|
use App\Services\MediaService;
|
||||||
use App\Services\MediaTagService;
|
use App\Services\MediaTagService;
|
||||||
use App\Services\StatusService;
|
use App\Services\PollService;
|
||||||
use App\Services\StatusHashtagService;
|
use App\Services\StatusHashtagService;
|
||||||
use App\Services\StatusLabelService;
|
use App\Services\StatusLabelService;
|
||||||
use App\Services\StatusMentionService;
|
use App\Services\StatusMentionService;
|
||||||
use App\Services\PollService;
|
use App\Services\StatusService;
|
||||||
use App\Models\CustomEmoji;
|
use App\Status;
|
||||||
use App\Util\Lexer\Autolink;
|
use App\Util\Lexer\Autolink;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class StatusStatelessTransformer extends Fractal\TransformerAbstract
|
class StatusStatelessTransformer extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
$taggedPeople = MediaTagService::get($status->id);
|
$taggedPeople = MediaTagService::get($status->id);
|
||||||
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
||||||
$rendered = config('exp.autolink') ?
|
$rendered = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
( $status->caption ? Autolink::create()->autolink($status->caption) : '' ) :
|
|
||||||
( $status->rendered ?? $status->caption );
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'_v' => 1,
|
'_v' => 1,
|
||||||
'id' => (string) $status->id,
|
'id' => (string) $status->id,
|
||||||
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
||||||
'shortcode' => HashidService::encode($status->id),
|
'shortcode' => HashidService::encode($status->id),
|
||||||
'uri' => $status->url(),
|
'uri' => $status->url(),
|
||||||
'url' => $status->url(),
|
'url' => $status->url(),
|
||||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
'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,
|
'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,
|
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id, false) : null,
|
||||||
'content' => $rendered,
|
'content' => $rendered,
|
||||||
'content_text' => $status->caption,
|
'content_text' => $status->caption,
|
||||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||||
'emojis' => CustomEmoji::scan($status->caption),
|
'emojis' => CustomEmoji::scan($status->caption),
|
||||||
'reblogs_count' => $status->reblogs_count ?? 0,
|
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||||
'favourites_count' => $status->likes_count ?? 0,
|
'favourites_count' => $status->likes_count ?? 0,
|
||||||
'reblogged' => null,
|
'reblogged' => null,
|
||||||
'favourited' => null,
|
'favourited' => null,
|
||||||
'muted' => null,
|
'muted' => null,
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'spoiler_text' => $status->cw_summary ?? '',
|
'spoiler_text' => $status->cw_summary ?? '',
|
||||||
'visibility' => $status->scope ?? $status->visibility,
|
'visibility' => $status->scope ?? $status->visibility,
|
||||||
'application' => [
|
'application' => [
|
||||||
'name' => 'web',
|
'name' => 'web',
|
||||||
'website' => null
|
'website' => null,
|
||||||
],
|
],
|
||||||
'language' => null,
|
'language' => null,
|
||||||
'mentions' => StatusMentionService::get($status->id),
|
'mentions' => StatusMentionService::get($status->id),
|
||||||
'pf_type' => $status->type ?? $status->setType(),
|
'pf_type' => $status->type ?? $status->setType(),
|
||||||
'reply_count' => (int) $status->reply_count,
|
'reply_count' => (int) $status->reply_count,
|
||||||
'comments_disabled' => (bool) $status->comments_disabled,
|
'comments_disabled' => (bool) $status->comments_disabled,
|
||||||
'thread' => false,
|
'thread' => false,
|
||||||
'replies' => [],
|
'replies' => [],
|
||||||
'parent' => [],
|
'parent' => [],
|
||||||
'place' => $status->place,
|
'place' => $status->place,
|
||||||
'local' => (bool) $status->local,
|
'local' => (bool) $status->local,
|
||||||
'taggedPeople' => $taggedPeople,
|
'taggedPeople' => $taggedPeople,
|
||||||
'label' => StatusLabelService::get($status),
|
'label' => StatusLabelService::get($status),
|
||||||
'liked_by' => LikeService::likedBy($status),
|
'liked_by' => LikeService::likedBy($status),
|
||||||
'media_attachments' => MediaService::get($status->id),
|
'media_attachments' => MediaService::get($status->id),
|
||||||
'account' => AccountService::get($status->profile_id, true),
|
'account' => AccountService::get($status->profile_id, true),
|
||||||
'tags' => StatusHashtagService::statusTags($status->id),
|
'tags' => StatusHashtagService::statusTags($status->id),
|
||||||
'poll' => $poll,
|
'poll' => $poll,
|
||||||
'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
|
'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;
|
namespace App\Transformer\Api;
|
||||||
|
|
||||||
use App\Like;
|
use App\Models\CustomEmoji;
|
||||||
use App\Status;
|
use App\Services\BookmarkService;
|
||||||
use League\Fractal;
|
|
||||||
use Cache;
|
|
||||||
use App\Services\HashidService;
|
use App\Services\HashidService;
|
||||||
use App\Services\LikeService;
|
use App\Services\LikeService;
|
||||||
use App\Services\MediaService;
|
use App\Services\MediaService;
|
||||||
use App\Services\MediaTagService;
|
use App\Services\MediaTagService;
|
||||||
use App\Services\StatusService;
|
use App\Services\PollService;
|
||||||
|
use App\Services\ProfileService;
|
||||||
use App\Services\StatusHashtagService;
|
use App\Services\StatusHashtagService;
|
||||||
use App\Services\StatusLabelService;
|
use App\Services\StatusLabelService;
|
||||||
use App\Services\StatusMentionService;
|
use App\Services\StatusMentionService;
|
||||||
use App\Services\ProfileService;
|
use App\Services\StatusService;
|
||||||
use Illuminate\Support\Str;
|
use App\Status;
|
||||||
use App\Services\PollService;
|
|
||||||
use App\Models\CustomEmoji;
|
|
||||||
use App\Services\BookmarkService;
|
|
||||||
use App\Util\Lexer\Autolink;
|
use App\Util\Lexer\Autolink;
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
class StatusTransformer extends Fractal\TransformerAbstract
|
class StatusTransformer extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
$pid = request()->user()->profile_id;
|
$pid = request()->user()->profile_id;
|
||||||
$taggedPeople = MediaTagService::get($status->id);
|
$taggedPeople = MediaTagService::get($status->id);
|
||||||
$poll = $status->type === 'poll' ? PollService::get($status->id, $pid) : null;
|
$poll = $status->type === 'poll' ? PollService::get($status->id, $pid) : null;
|
||||||
$rendered = config('exp.autolink') ?
|
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||||
( $status->caption ? Autolink::create()->autolink($status->caption) : '' ) :
|
|
||||||
( $status->rendered ?? $status->caption );
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'_v' => 1,
|
'_v' => 1,
|
||||||
'id' => (string) $status->id,
|
'id' => (string) $status->id,
|
||||||
'shortcode' => HashidService::encode($status->id),
|
'shortcode' => HashidService::encode($status->id),
|
||||||
'uri' => $status->url(),
|
'uri' => $status->url(),
|
||||||
'url' => $status->url(),
|
'url' => $status->url(),
|
||||||
'in_reply_to_id' => (string) $status->in_reply_to_id,
|
'in_reply_to_id' => (string) $status->in_reply_to_id,
|
||||||
'in_reply_to_account_id' => (string) $status->in_reply_to_profile_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,
|
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id) : null,
|
||||||
'content' => $rendered,
|
'content' => $content,
|
||||||
'content_text' => $status->caption,
|
'content_text' => $status->caption,
|
||||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||||
'emojis' => CustomEmoji::scan($status->caption),
|
'emojis' => CustomEmoji::scan($status->caption),
|
||||||
'reblogs_count' => 0,
|
'reblogs_count' => 0,
|
||||||
'favourites_count' => $status->likes_count ?? 0,
|
'favourites_count' => $status->likes_count ?? 0,
|
||||||
'reblogged' => $status->shared(),
|
'reblogged' => $status->shared(),
|
||||||
'favourited' => $status->liked(),
|
'favourited' => $status->liked(),
|
||||||
'muted' => null,
|
'muted' => null,
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
'spoiler_text' => $status->cw_summary ?? '',
|
'spoiler_text' => $status->cw_summary ?? '',
|
||||||
'visibility' => $status->scope ?? $status->visibility,
|
'visibility' => $status->scope ?? $status->visibility,
|
||||||
'application' => [
|
'application' => [
|
||||||
'name' => 'web',
|
'name' => 'web',
|
||||||
'website' => null
|
'website' => null,
|
||||||
],
|
],
|
||||||
'language' => null,
|
'language' => null,
|
||||||
'mentions' => StatusMentionService::get($status->id),
|
'mentions' => StatusMentionService::get($status->id),
|
||||||
'pf_type' => $status->type ?? $status->setType(),
|
'pf_type' => $status->type ?? $status->setType(),
|
||||||
'reply_count' => (int) $status->reply_count,
|
'reply_count' => (int) $status->reply_count,
|
||||||
'comments_disabled' => (bool) $status->comments_disabled,
|
'comments_disabled' => (bool) $status->comments_disabled,
|
||||||
'thread' => false,
|
'thread' => false,
|
||||||
'replies' => [],
|
'replies' => [],
|
||||||
'parent' => [],
|
'parent' => [],
|
||||||
'place' => $status->place,
|
'place' => $status->place,
|
||||||
'local' => (bool) $status->local,
|
'local' => (bool) $status->local,
|
||||||
'taggedPeople' => $taggedPeople,
|
'taggedPeople' => $taggedPeople,
|
||||||
'label' => StatusLabelService::get($status),
|
'label' => StatusLabelService::get($status),
|
||||||
'liked_by' => LikeService::likedBy($status),
|
'liked_by' => LikeService::likedBy($status),
|
||||||
'media_attachments' => MediaService::get($status->id),
|
'media_attachments' => MediaService::get($status->id),
|
||||||
'account' => ProfileService::get($status->profile_id, true),
|
'account' => ProfileService::get($status->profile_id, true),
|
||||||
'tags' => StatusHashtagService::statusTags($status->id),
|
'tags' => StatusHashtagService::statusTags($status->id),
|
||||||
'poll' => $poll,
|
'poll' => $poll,
|
||||||
'bookmarked' => BookmarkService::get($pid, $status->id),
|
'bookmarked' => BookmarkService::get($pid, $status->id),
|
||||||
'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
|
'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,8 +417,8 @@ class Inbox
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = $activity['content'];
|
$msg = Purify::clean($activity['content']);
|
||||||
$msgText = strip_tags($activity['content']);
|
$msgText = strip_tags($msg);
|
||||||
|
|
||||||
if (Str::startsWith($msgText, '@'.$profile->username)) {
|
if (Str::startsWith($msgText, '@'.$profile->username)) {
|
||||||
$len = strlen('@'.$profile->username);
|
$len = strlen('@'.$profile->username);
|
||||||
|
|
Loading…
Reference in a new issue