Merge pull request #5355 from pixelfed/staging

Staging
pull/5375/head
daniel 1 year ago committed by GitHub
commit c04e19bc4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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\PollService;
use App\Services\StatusHashtagService; use App\Services\StatusHashtagService;
use App\Services\StatusLabelService;
use App\Services\StatusMentionService; use App\Services\StatusMentionService;
use App\Services\PollService; use App\Util\Lexer\Autolink;
use App\Models\CustomEmoji; use Illuminate\Http\Resources\Json\JsonResource;
class StatusStateless extends JsonResource class StatusStateless extends JsonResource
{ {
@ -28,6 +27,7 @@ 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,
@ -39,7 +39,7 @@ class StatusStateless extends JsonResource
'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),
@ -53,7 +53,7 @@ class StatusStateless extends JsonResource
'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),
@ -70,7 +70,7 @@ class StatusStateless extends JsonResource
'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,14 +2,17 @@
namespace App\Transformer\ActivityPub; namespace App\Transformer\ActivityPub;
use App\Services\MediaService;
use App\Status; use App\Status;
use App\Util\Lexer\Autolink;
use League\Fractal; use League\Fractal;
use App\Services\MediaService;
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',
@ -28,7 +31,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
// 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
@ -53,7 +56,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'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,10 +2,11 @@
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
{ {
@ -15,25 +16,26 @@ class CreateNote extends Fractal\TransformerAbstract
$webfinger = $mention->emailUrl(); $webfinger = $mention->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
$webfinger : $webfinger :
'@' . $webfinger; '@'.$webfinger;
return [ return [
'type' => 'Mention', 'type' => 'Mention',
'href' => $mention->permalink(), 'href' => $mention->permalink(),
'name' => $name 'name' => $name,
]; ];
})->toArray(); })->toArray();
if($status->in_reply_to_id != null) { if ($status->in_reply_to_id != null) {
$parent = $status->parent()->profile; $parent = $status->parent()->profile;
if($parent) { if ($parent) {
$webfinger = $parent->emailUrl(); $webfinger = $parent->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
$webfinger : $webfinger :
'@' . $webfinger; '@'.$webfinger;
$reply = [ $reply = [
'type' => 'Mention', 'type' => 'Mention',
'href' => $parent->permalink(), 'href' => $parent->permalink(),
'name' => $name 'name' => $name,
]; ];
$mentions = array_merge($reply, $mentions); $mentions = array_merge($reply, $mentions);
} }
@ -50,6 +52,7 @@ class CreateNote extends Fractal\TransformerAbstract
$emojis = CustomEmoji::scan($status->caption, true) ?? []; $emojis = CustomEmoji::scan($status->caption, true) ?? [];
$emoji = array_merge($emojis, $mentions); $emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags); $tags = array_merge($emoji, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [ return [
'@context' => [ '@context' => [
@ -62,28 +65,28 @@ class CreateNote extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#', 'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [ 'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled', '@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean' '@type' => 'schema:Boolean',
], ],
'capabilities' => [ 'capabilities' => [
'@id' => 'pixelfed:capabilities', '@id' => 'pixelfed:capabilities',
'@container' => '@set' '@container' => '@set',
], ],
'announce' => [ 'announce' => [
'@id' => 'pixelfed:canAnnounce', '@id' => 'pixelfed:canAnnounce',
'@type' => '@id' '@type' => '@id',
], ],
'like' => [ 'like' => [
'@id' => 'pixelfed:canLike', '@id' => 'pixelfed:canLike',
'@type' => '@id' '@type' => '@id',
], ],
'reply' => [ 'reply' => [
'@id' => 'pixelfed:canReply', '@id' => 'pixelfed:canReply',
'@type' => '@id' '@type' => '@id',
], ],
'toot' => 'http://joinmastodon.org/ns#', 'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji', 'Emoji' => 'toot:Emoji',
'blurhash' => 'toot:blurhash', 'blurhash' => 'toot:blurhash',
] ],
], ],
'id' => $status->permalink(), 'id' => $status->permalink(),
'type' => 'Create', 'type' => 'Create',
@ -95,7 +98,7 @@ class CreateNote extends Fractal\TransformerAbstract
'id' => $status->url(), 'id' => $status->url(),
'type' => 'Note', 'type' => 'Note',
'summary' => $status->is_nsfw ? $status->cw_summary : null, 'summary' => $status->is_nsfw ? $status->cw_summary : null,
'content' => $status->rendered ?? $status->caption, 'content' => $content,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null, 'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
'published' => $status->created_at->toAtomString(), 'published' => $status->created_at->toAtomString(),
'url' => $status->url(), 'url' => $status->url(),
@ -110,32 +113,33 @@ class CreateNote extends Fractal\TransformerAbstract
'url' => $media->url(), 'url' => $media->url(),
'name' => $media->caption, 'name' => $media->caption,
]; ];
if($media->blurhash) { if ($media->blurhash) {
$res['blurhash'] = $media->blurhash; $res['blurhash'] = $media->blurhash;
} }
if($media->width) { if ($media->width) {
$res['width'] = $media->width; $res['width'] = $media->width;
} }
if($media->height) { if ($media->height) {
$res['height'] = $media->height; $res['height'] = $media->height;
} }
return $res; return $res;
})->toArray(), })->toArray(),
'tag' => $tags, 'tag' => $tags,
'commentsEnabled' => (bool) !$status->comments_disabled, 'commentsEnabled' => (bool) ! $status->comments_disabled,
'capabilities' => [ 'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public', 'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => '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' 'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
], ],
'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,10 +2,11 @@
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
{ {
@ -16,25 +17,26 @@ class Note extends Fractal\TransformerAbstract
$webfinger = $mention->emailUrl(); $webfinger = $mention->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
$webfinger : $webfinger :
'@' . $webfinger; '@'.$webfinger;
return [ return [
'type' => 'Mention', 'type' => 'Mention',
'href' => $mention->permalink(), 'href' => $mention->permalink(),
'name' => $name 'name' => $name,
]; ];
})->toArray(); })->toArray();
if($status->in_reply_to_id != null) { if ($status->in_reply_to_id != null) {
$parent = $status->parent()->profile; $parent = $status->parent()->profile;
if($parent) { if ($parent) {
$webfinger = $parent->emailUrl(); $webfinger = $parent->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
$webfinger : $webfinger :
'@' . $webfinger; '@'.$webfinger;
$reply = [ $reply = [
'type' => 'Mention', 'type' => 'Mention',
'href' => $parent->permalink(), 'href' => $parent->permalink(),
'name' => $name 'name' => $name,
]; ];
array_push($mentions, $reply); array_push($mentions, $reply);
} }
@ -51,6 +53,7 @@ class Note extends Fractal\TransformerAbstract
$emojis = CustomEmoji::scan($status->caption, true) ?? []; $emojis = CustomEmoji::scan($status->caption, true) ?? [];
$emoji = array_merge($emojis, $mentions); $emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags); $tags = array_merge($emoji, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [ return [
'@context' => [ '@context' => [
@ -63,33 +66,33 @@ class Note extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#', 'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [ 'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled', '@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean' '@type' => 'schema:Boolean',
], ],
'capabilities' => [ 'capabilities' => [
'@id' => 'pixelfed:capabilities', '@id' => 'pixelfed:capabilities',
'@container' => '@set' '@container' => '@set',
], ],
'announce' => [ 'announce' => [
'@id' => 'pixelfed:canAnnounce', '@id' => 'pixelfed:canAnnounce',
'@type' => '@id' '@type' => '@id',
], ],
'like' => [ 'like' => [
'@id' => 'pixelfed:canLike', '@id' => 'pixelfed:canLike',
'@type' => '@id' '@type' => '@id',
], ],
'reply' => [ 'reply' => [
'@id' => 'pixelfed:canReply', '@id' => 'pixelfed:canReply',
'@type' => '@id' '@type' => '@id',
], ],
'toot' => 'http://joinmastodon.org/ns#', 'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji', 'Emoji' => 'toot:Emoji',
'blurhash' => 'toot:blurhash', 'blurhash' => 'toot:blurhash',
] ],
], ],
'id' => $status->url(), 'id' => $status->url(),
'type' => 'Note', 'type' => 'Note',
'summary' => $status->is_nsfw ? $status->cw_summary : null, 'summary' => $status->is_nsfw ? $status->cw_summary : null,
'content' => $status->rendered ?? $status->caption, 'content' => $content,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null, 'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
'published' => $status->created_at->toAtomString(), 'published' => $status->created_at->toAtomString(),
'url' => $status->url(), 'url' => $status->url(),
@ -104,30 +107,31 @@ class Note extends Fractal\TransformerAbstract
'url' => $media->url(), 'url' => $media->url(),
'name' => $media->caption, 'name' => $media->caption,
]; ];
if($media->blurhash) { if ($media->blurhash) {
$res['blurhash'] = $media->blurhash; $res['blurhash'] = $media->blurhash;
} }
if($media->width) { if ($media->width) {
$res['width'] = $media->width; $res['width'] = $media->width;
} }
if($media->height) { if ($media->height) {
$res['height'] = $media->height; $res['height'] = $media->height;
} }
return $res; return $res;
})->toArray(), })->toArray(),
'tag' => $tags, 'tag' => $tags,
'commentsEnabled' => (bool) !$status->comments_disabled, 'commentsEnabled' => (bool) ! $status->comments_disabled,
'capabilities' => [ 'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public', 'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => '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' 'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
], ],
'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,
]; ];
} }

@ -3,8 +3,9 @@
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
{ {
@ -14,11 +15,12 @@ class Question extends Fractal\TransformerAbstract
$webfinger = $mention->emailUrl(); $webfinger = $mention->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
$webfinger : $webfinger :
'@' . $webfinger; '@'.$webfinger;
return [ return [
'type' => 'Mention', 'type' => 'Mention',
'href' => $mention->permalink(), 'href' => $mention->permalink(),
'name' => $name 'name' => $name,
]; ];
})->toArray(); })->toArray();
@ -30,6 +32,7 @@ class Question extends Fractal\TransformerAbstract
]; ];
})->toArray(); })->toArray();
$tags = array_merge($mentions, $hashtags); $tags = array_merge($mentions, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [ return [
'@context' => [ '@context' => [
@ -42,32 +45,32 @@ class Question extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#', 'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [ 'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled', '@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean' '@type' => 'schema:Boolean',
], ],
'capabilities' => [ 'capabilities' => [
'@id' => 'pixelfed:capabilities', '@id' => 'pixelfed:capabilities',
'@container' => '@set' '@container' => '@set',
], ],
'announce' => [ 'announce' => [
'@id' => 'pixelfed:canAnnounce', '@id' => 'pixelfed:canAnnounce',
'@type' => '@id' '@type' => '@id',
], ],
'like' => [ 'like' => [
'@id' => 'pixelfed:canLike', '@id' => 'pixelfed:canLike',
'@type' => '@id' '@type' => '@id',
], ],
'reply' => [ 'reply' => [
'@id' => 'pixelfed:canReply', '@id' => 'pixelfed:canReply',
'@type' => '@id' '@type' => '@id',
], ],
'toot' => 'http://joinmastodon.org/ns#', 'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji' 'Emoji' => 'toot:Emoji',
] ],
], ],
'id' => $status->url(), 'id' => $status->url(),
'type' => 'Question', 'type' => 'Question',
'summary' => null, 'summary' => null,
'content' => $status->rendered ?? $status->caption, 'content' => $content,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null, 'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
'published' => $status->created_at->toAtomString(), 'published' => $status->created_at->toAtomString(),
'url' => $status->url(), 'url' => $status->url(),
@ -77,30 +80,30 @@ class Question extends Fractal\TransformerAbstract
'sensitive' => (bool) $status->is_nsfw, 'sensitive' => (bool) $status->is_nsfw,
'attachment' => [], 'attachment' => [],
'tag' => $tags, 'tag' => $tags,
'commentsEnabled' => (bool) !$status->comments_disabled, 'commentsEnabled' => (bool) ! $status->comments_disabled,
'capabilities' => [ 'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public', 'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => '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' 'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
], ],
'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,
'endTime' => $status->poll->expires_at->toAtomString(), 'endTime' => $status->poll->expires_at->toAtomString(),
'oneOf' => collect($status->poll->poll_options)->map(function($option, $index) use($status) { 'oneOf' => collect($status->poll->poll_options)->map(function ($option, $index) use ($status) {
return [ return [
'type' => 'Note', 'type' => 'Note',
'name' => $option, 'name' => $option,
'replies' => [ 'replies' => [
'type' => 'Collection', 'type' => 'Collection',
'totalItems' => $status->poll->cached_tallies[$index] 'totalItems' => $status->poll->cached_tallies[$index],
] ],
]; ];
}) }),
]; ];
} }
} }

@ -2,10 +2,11 @@
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
{ {
@ -15,25 +16,26 @@ class UpdateNote extends Fractal\TransformerAbstract
$webfinger = $mention->emailUrl(); $webfinger = $mention->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
$webfinger : $webfinger :
'@' . $webfinger; '@'.$webfinger;
return [ return [
'type' => 'Mention', 'type' => 'Mention',
'href' => $mention->permalink(), 'href' => $mention->permalink(),
'name' => $name 'name' => $name,
]; ];
})->toArray(); })->toArray();
if($status->in_reply_to_id != null) { if ($status->in_reply_to_id != null) {
$parent = $status->parent()->profile; $parent = $status->parent()->profile;
if($parent) { if ($parent) {
$webfinger = $parent->emailUrl(); $webfinger = $parent->emailUrl();
$name = Str::startsWith($webfinger, '@') ? $name = Str::startsWith($webfinger, '@') ?
$webfinger : $webfinger :
'@' . $webfinger; '@'.$webfinger;
$reply = [ $reply = [
'type' => 'Mention', 'type' => 'Mention',
'href' => $parent->permalink(), 'href' => $parent->permalink(),
'name' => $name 'name' => $name,
]; ];
$mentions = array_merge($reply, $mentions); $mentions = array_merge($reply, $mentions);
} }
@ -51,6 +53,7 @@ class UpdateNote extends Fractal\TransformerAbstract
$emoji = array_merge($emojis, $mentions); $emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags); $tags = array_merge($emoji, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
$latestEdit = $status->edits()->latest()->first(); $latestEdit = $status->edits()->latest()->first();
return [ return [
@ -64,29 +67,29 @@ class UpdateNote extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#', 'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [ 'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled', '@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean' '@type' => 'schema:Boolean',
], ],
'capabilities' => [ 'capabilities' => [
'@id' => 'pixelfed:capabilities', '@id' => 'pixelfed:capabilities',
'@container' => '@set' '@container' => '@set',
], ],
'announce' => [ 'announce' => [
'@id' => 'pixelfed:canAnnounce', '@id' => 'pixelfed:canAnnounce',
'@type' => '@id' '@type' => '@id',
], ],
'like' => [ 'like' => [
'@id' => 'pixelfed:canLike', '@id' => 'pixelfed:canLike',
'@type' => '@id' '@type' => '@id',
], ],
'reply' => [ 'reply' => [
'@id' => 'pixelfed:canReply', '@id' => 'pixelfed:canReply',
'@type' => '@id' '@type' => '@id',
], ],
'toot' => 'http://joinmastodon.org/ns#', 'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji' 'Emoji' => 'toot:Emoji',
] ],
], ],
'id' => $status->permalink('#updates/' . $latestEdit->id), 'id' => $status->permalink('#updates/'.$latestEdit->id),
'type' => 'Update', 'type' => 'Update',
'actor' => $status->profile->permalink(), 'actor' => $status->profile->permalink(),
'published' => $latestEdit->created_at->toAtomString(), 'published' => $latestEdit->created_at->toAtomString(),
@ -96,7 +99,7 @@ class UpdateNote extends Fractal\TransformerAbstract
'id' => $status->url(), 'id' => $status->url(),
'type' => 'Note', 'type' => 'Note',
'summary' => $status->is_nsfw ? $status->cw_summary : null, 'summary' => $status->is_nsfw ? $status->cw_summary : null,
'content' => $status->rendered ?? $status->caption, 'content' => $content,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null, 'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
'published' => $status->created_at->toAtomString(), 'published' => $status->created_at->toAtomString(),
'url' => $status->url(), 'url' => $status->url(),
@ -113,21 +116,21 @@ class UpdateNote extends Fractal\TransformerAbstract
]; ];
})->toArray(), })->toArray(),
'tag' => $tags, 'tag' => $tags,
'commentsEnabled' => (bool) !$status->comments_disabled, 'commentsEnabled' => (bool) ! $status->comments_disabled,
'updated' => $latestEdit->created_at->toAtomString(), 'updated' => $latestEdit->created_at->toAtomString(),
'capabilities' => [ 'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public', 'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => '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' 'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
], ],
'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,17 +2,19 @@
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)
{ {
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [ return [
'id' => (string) $status->id, 'id' => (string) $status->id,
'created_at' => $status->created_at->toJSON(), 'created_at' => $status->created_at->toJSON(),
@ -31,11 +33,11 @@ class StatusTransformer extends Fractal\TransformerAbstract
'favourited' => $status->liked(), 'favourited' => $status->liked(),
'muted' => false, 'muted' => false,
'bookmarked' => false, 'bookmarked' => false,
'content' => $status->rendered ?? $status->caption ?? '', 'content' => $content,
'reblog' => null, 'reblog' => null,
'application' => [ 'application' => [
'name' => 'web', 'name' => 'web',
'website' => null 'website' => null,
], ],
'mentions' => [], 'mentions' => [],
'emojis' => [], 'emojis' => [],

@ -2,21 +2,20 @@
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
{ {
@ -24,9 +23,7 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
{ {
$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,
@ -52,7 +49,7 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
'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),

@ -2,24 +2,21 @@
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
{ {
@ -28,9 +25,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
$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,
@ -41,7 +36,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'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),
@ -55,7 +50,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'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),

@ -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…
Cancel
Save