Update Status caption render logic

This commit is contained in:
Daniel Supernault 2024-11-19 02:53:39 -07:00
parent 0917953dbc
commit fb8dbb95db
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
9 changed files with 719 additions and 708 deletions

View file

@ -2,18 +2,17 @@
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Cache;
use App\Models\CustomEmoji;
use App\Services\AccountService;
use App\Services\HashidService;
use App\Services\LikeService;
use App\Services\MediaService;
use App\Services\MediaTagService;
use App\Services\StatusHashtagService;
use App\Services\StatusLabelService;
use App\Services\StatusMentionService;
use App\Services\PollService;
use App\Models\CustomEmoji;
use App\Services\StatusHashtagService;
use App\Services\StatusMentionService;
use App\Util\Lexer\Autolink;
use Illuminate\Http\Resources\Json\JsonResource;
class StatusStateless extends JsonResource
{
@ -28,6 +27,7 @@ class StatusStateless extends JsonResource
$status = $this;
$taggedPeople = MediaTagService::get($status->id);
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
$autoLink = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'_v' => 1,
@ -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_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
'reblog' => null,
'content' => $status->rendered ?? $status->caption,
'content' => $autoLink,
'content_text' => $status->caption,
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
'emojis' => CustomEmoji::scan($status->caption),
@ -53,7 +53,7 @@ class StatusStateless extends JsonResource
'visibility' => $status->scope ?? $status->visibility,
'application' => [
'name' => 'web',
'website' => null
'website' => null,
],
'language' => null,
'mentions' => StatusMentionService::get($status->id),
@ -70,7 +70,7 @@ class StatusStateless extends JsonResource
'media_attachments' => MediaService::get($status->id),
'account' => AccountService::get($status->profile_id, true),
'tags' => StatusHashtagService::statusTags($status->id),
'poll' => $poll
'poll' => $poll,
];
}
}

View file

@ -2,14 +2,17 @@
namespace App\Transformer\ActivityPub;
use App\Status;
use League\Fractal;
use App\Services\MediaService;
use App\Status;
use App\Util\Lexer\Autolink;
use League\Fractal;
class StatusTransformer extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'@context' => [
'https://www.w3.org/ns/activitystreams',
@ -28,7 +31,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
// XXX: CW Title
'summary' => null,
'content' => $status->rendered ?? $status->caption,
'content' => $content,
'inReplyTo' => null,
// TODO: fix date format
@ -53,7 +56,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'name' => $status->place->name,
'longitude' => $status->place->long,
'latitude' => $status->place->lat,
'country' => $status->place->country
'country' => $status->place->country,
] : null,
];
}

View file

@ -2,10 +2,11 @@
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
use App\Models\CustomEmoji;
use App\Status;
use App\Util\Lexer\Autolink;
use Illuminate\Support\Str;
use League\Fractal;
class CreateNote extends Fractal\TransformerAbstract
{
@ -16,10 +17,11 @@ class CreateNote extends Fractal\TransformerAbstract
$name = Str::startsWith($webfinger, '@') ?
$webfinger :
'@'.$webfinger;
return [
'type' => 'Mention',
'href' => $mention->permalink(),
'name' => $name
'name' => $name,
];
})->toArray();
@ -33,7 +35,7 @@ class CreateNote extends Fractal\TransformerAbstract
$reply = [
'type' => 'Mention',
'href' => $parent->permalink(),
'name' => $name
'name' => $name,
];
$mentions = array_merge($reply, $mentions);
}
@ -50,6 +52,7 @@ class CreateNote extends Fractal\TransformerAbstract
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
$emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'@context' => [
@ -62,28 +65,28 @@ class CreateNote extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean'
'@type' => 'schema:Boolean',
],
'capabilities' => [
'@id' => 'pixelfed:capabilities',
'@container' => '@set'
'@container' => '@set',
],
'announce' => [
'@id' => 'pixelfed:canAnnounce',
'@type' => '@id'
'@type' => '@id',
],
'like' => [
'@id' => 'pixelfed:canLike',
'@type' => '@id'
'@type' => '@id',
],
'reply' => [
'@id' => 'pixelfed:canReply',
'@type' => '@id'
'@type' => '@id',
],
'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji',
'blurhash' => 'toot:blurhash',
]
],
],
'id' => $status->permalink(),
'type' => 'Create',
@ -95,7 +98,7 @@ class CreateNote extends Fractal\TransformerAbstract
'id' => $status->url(),
'type' => 'Note',
'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,
'published' => $status->created_at->toAtomString(),
'url' => $status->url(),
@ -119,6 +122,7 @@ class CreateNote extends Fractal\TransformerAbstract
if ($media->height) {
$res['height'] = $media->height;
}
return $res;
})->toArray(),
'tag' => $tags,
@ -126,16 +130,16 @@ class CreateNote extends Fractal\TransformerAbstract
'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => 'https://www.w3.org/ns/activitystreams#Public',
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
],
'location' => $status->place_id ? [
'type' => 'Place',
'name' => $status->place->name,
'longitude' => $status->place->long,
'latitude' => $status->place->lat,
'country' => $status->place->country
'country' => $status->place->country,
] : null,
]
],
];
}
}

View file

@ -2,10 +2,11 @@
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
use App\Models\CustomEmoji;
use App\Status;
use App\Util\Lexer\Autolink;
use Illuminate\Support\Str;
use League\Fractal;
class Note extends Fractal\TransformerAbstract
{
@ -17,10 +18,11 @@ class Note extends Fractal\TransformerAbstract
$name = Str::startsWith($webfinger, '@') ?
$webfinger :
'@'.$webfinger;
return [
'type' => 'Mention',
'href' => $mention->permalink(),
'name' => $name
'name' => $name,
];
})->toArray();
@ -34,7 +36,7 @@ class Note extends Fractal\TransformerAbstract
$reply = [
'type' => 'Mention',
'href' => $parent->permalink(),
'name' => $name
'name' => $name,
];
array_push($mentions, $reply);
}
@ -51,6 +53,7 @@ class Note extends Fractal\TransformerAbstract
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
$emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'@context' => [
@ -63,33 +66,33 @@ class Note extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean'
'@type' => 'schema:Boolean',
],
'capabilities' => [
'@id' => 'pixelfed:capabilities',
'@container' => '@set'
'@container' => '@set',
],
'announce' => [
'@id' => 'pixelfed:canAnnounce',
'@type' => '@id'
'@type' => '@id',
],
'like' => [
'@id' => 'pixelfed:canLike',
'@type' => '@id'
'@type' => '@id',
],
'reply' => [
'@id' => 'pixelfed:canReply',
'@type' => '@id'
'@type' => '@id',
],
'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji',
'blurhash' => 'toot:blurhash',
]
],
],
'id' => $status->url(),
'type' => 'Note',
'summary' => $status->is_nsfw ? $status->cw_summary : null,
'content' => $status->rendered ?? $status->caption,
'content' => $content,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
'published' => $status->created_at->toAtomString(),
'url' => $status->url(),
@ -113,6 +116,7 @@ class Note extends Fractal\TransformerAbstract
if ($media->height) {
$res['height'] = $media->height;
}
return $res;
})->toArray(),
'tag' => $tags,
@ -120,14 +124,14 @@ class Note extends Fractal\TransformerAbstract
'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => 'https://www.w3.org/ns/activitystreams#Public',
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
],
'location' => $status->place_id ? [
'type' => 'Place',
'name' => $status->place->name,
'longitude' => $status->place->long,
'latitude' => $status->place->lat,
'country' => $status->place->country
'country' => $status->place->country,
] : null,
];
}

View file

@ -3,8 +3,9 @@
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
use App\Util\Lexer\Autolink;
use Illuminate\Support\Str;
use League\Fractal;
class Question extends Fractal\TransformerAbstract
{
@ -15,10 +16,11 @@ class Question extends Fractal\TransformerAbstract
$name = Str::startsWith($webfinger, '@') ?
$webfinger :
'@'.$webfinger;
return [
'type' => 'Mention',
'href' => $mention->permalink(),
'name' => $name
'name' => $name,
];
})->toArray();
@ -30,6 +32,7 @@ class Question extends Fractal\TransformerAbstract
];
})->toArray();
$tags = array_merge($mentions, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'@context' => [
@ -42,32 +45,32 @@ class Question extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean'
'@type' => 'schema:Boolean',
],
'capabilities' => [
'@id' => 'pixelfed:capabilities',
'@container' => '@set'
'@container' => '@set',
],
'announce' => [
'@id' => 'pixelfed:canAnnounce',
'@type' => '@id'
'@type' => '@id',
],
'like' => [
'@id' => 'pixelfed:canLike',
'@type' => '@id'
'@type' => '@id',
],
'reply' => [
'@id' => 'pixelfed:canReply',
'@type' => '@id'
'@type' => '@id',
],
'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji'
]
'Emoji' => 'toot:Emoji',
],
],
'id' => $status->url(),
'type' => 'Question',
'summary' => null,
'content' => $status->rendered ?? $status->caption,
'content' => $content,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
'published' => $status->created_at->toAtomString(),
'url' => $status->url(),
@ -81,14 +84,14 @@ class Question extends Fractal\TransformerAbstract
'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => 'https://www.w3.org/ns/activitystreams#Public',
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
],
'location' => $status->place_id ? [
'type' => 'Place',
'name' => $status->place->name,
'longitude' => $status->place->long,
'latitude' => $status->place->lat,
'country' => $status->place->country
'country' => $status->place->country,
] : null,
'endTime' => $status->poll->expires_at->toAtomString(),
'oneOf' => collect($status->poll->poll_options)->map(function ($option, $index) use ($status) {
@ -97,10 +100,10 @@ class Question extends Fractal\TransformerAbstract
'name' => $option,
'replies' => [
'type' => 'Collection',
'totalItems' => $status->poll->cached_tallies[$index]
]
'totalItems' => $status->poll->cached_tallies[$index],
],
];
})
}),
];
}
}

View file

@ -2,10 +2,11 @@
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
use App\Models\CustomEmoji;
use App\Status;
use App\Util\Lexer\Autolink;
use Illuminate\Support\Str;
use League\Fractal;
class UpdateNote extends Fractal\TransformerAbstract
{
@ -16,10 +17,11 @@ class UpdateNote extends Fractal\TransformerAbstract
$name = Str::startsWith($webfinger, '@') ?
$webfinger :
'@'.$webfinger;
return [
'type' => 'Mention',
'href' => $mention->permalink(),
'name' => $name
'name' => $name,
];
})->toArray();
@ -33,7 +35,7 @@ class UpdateNote extends Fractal\TransformerAbstract
$reply = [
'type' => 'Mention',
'href' => $parent->permalink(),
'name' => $name
'name' => $name,
];
$mentions = array_merge($reply, $mentions);
}
@ -51,6 +53,7 @@ class UpdateNote extends Fractal\TransformerAbstract
$emoji = array_merge($emojis, $mentions);
$tags = array_merge($emoji, $hashtags);
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
$latestEdit = $status->edits()->latest()->first();
return [
@ -64,27 +67,27 @@ class UpdateNote extends Fractal\TransformerAbstract
'pixelfed' => 'http://pixelfed.org/ns#',
'commentsEnabled' => [
'@id' => 'pixelfed:commentsEnabled',
'@type' => 'schema:Boolean'
'@type' => 'schema:Boolean',
],
'capabilities' => [
'@id' => 'pixelfed:capabilities',
'@container' => '@set'
'@container' => '@set',
],
'announce' => [
'@id' => 'pixelfed:canAnnounce',
'@type' => '@id'
'@type' => '@id',
],
'like' => [
'@id' => 'pixelfed:canLike',
'@type' => '@id'
'@type' => '@id',
],
'reply' => [
'@id' => 'pixelfed:canReply',
'@type' => '@id'
'@type' => '@id',
],
'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji'
]
'Emoji' => 'toot:Emoji',
],
],
'id' => $status->permalink('#updates/'.$latestEdit->id),
'type' => 'Update',
@ -96,7 +99,7 @@ class UpdateNote extends Fractal\TransformerAbstract
'id' => $status->url(),
'type' => 'Note',
'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,
'published' => $status->created_at->toAtomString(),
'url' => $status->url(),
@ -118,16 +121,16 @@ class UpdateNote extends Fractal\TransformerAbstract
'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => 'https://www.w3.org/ns/activitystreams#Public',
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public',
],
'location' => $status->place_id ? [
'type' => 'Place',
'name' => $status->place->name,
'longitude' => $status->place->long,
'latitude' => $status->place->lat,
'country' => $status->place->country
'country' => $status->place->country,
] : null,
]
],
];
}
}

View file

@ -2,17 +2,19 @@
namespace App\Transformer\Api\Mastodon\v1;
use App\Status;
use League\Fractal;
use Cache;
use App\Services\MediaService;
use App\Services\ProfileService;
use App\Services\StatusHashtagService;
use App\Status;
use App\Util\Lexer\Autolink;
use League\Fractal;
class StatusTransformer extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'id' => (string) $status->id,
'created_at' => $status->created_at->toJSON(),
@ -31,11 +33,11 @@ class StatusTransformer extends Fractal\TransformerAbstract
'favourited' => $status->liked(),
'muted' => false,
'bookmarked' => false,
'content' => $status->rendered ?? $status->caption ?? '',
'content' => $content,
'reblog' => null,
'application' => [
'name' => 'web',
'website' => null
'website' => null,
],
'mentions' => [],
'emojis' => [],

View file

@ -2,21 +2,20 @@
namespace App\Transformer\Api;
use App\Status;
use League\Fractal;
use Cache;
use App\Models\CustomEmoji;
use App\Services\AccountService;
use App\Services\HashidService;
use App\Services\LikeService;
use App\Services\MediaService;
use App\Services\MediaTagService;
use App\Services\StatusService;
use App\Services\PollService;
use App\Services\StatusHashtagService;
use App\Services\StatusLabelService;
use App\Services\StatusMentionService;
use App\Services\PollService;
use App\Models\CustomEmoji;
use App\Services\StatusService;
use App\Status;
use App\Util\Lexer\Autolink;
use League\Fractal;
class StatusStatelessTransformer extends Fractal\TransformerAbstract
{
@ -24,9 +23,7 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
{
$taggedPeople = MediaTagService::get($status->id);
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
$rendered = config('exp.autolink') ?
( $status->caption ? Autolink::create()->autolink($status->caption) : '' ) :
( $status->rendered ?? $status->caption );
$rendered = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'_v' => 1,
@ -52,7 +49,7 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
'visibility' => $status->scope ?? $status->visibility,
'application' => [
'name' => 'web',
'website' => null
'website' => null,
],
'language' => null,
'mentions' => StatusMentionService::get($status->id),

View file

@ -2,24 +2,21 @@
namespace App\Transformer\Api;
use App\Like;
use App\Status;
use League\Fractal;
use Cache;
use App\Models\CustomEmoji;
use App\Services\BookmarkService;
use App\Services\HashidService;
use App\Services\LikeService;
use App\Services\MediaService;
use App\Services\MediaTagService;
use App\Services\StatusService;
use App\Services\PollService;
use App\Services\ProfileService;
use App\Services\StatusHashtagService;
use App\Services\StatusLabelService;
use App\Services\StatusMentionService;
use App\Services\ProfileService;
use Illuminate\Support\Str;
use App\Services\PollService;
use App\Models\CustomEmoji;
use App\Services\BookmarkService;
use App\Services\StatusService;
use App\Status;
use App\Util\Lexer\Autolink;
use League\Fractal;
class StatusTransformer extends Fractal\TransformerAbstract
{
@ -28,9 +25,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
$pid = request()->user()->profile_id;
$taggedPeople = MediaTagService::get($status->id);
$poll = $status->type === 'poll' ? PollService::get($status->id, $pid) : null;
$rendered = config('exp.autolink') ?
( $status->caption ? Autolink::create()->autolink($status->caption) : '' ) :
( $status->rendered ?? $status->caption );
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
return [
'_v' => 1,
@ -41,7 +36,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'in_reply_to_id' => (string) $status->in_reply_to_id,
'in_reply_to_account_id' => (string) $status->in_reply_to_profile_id,
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id) : null,
'content' => $rendered,
'content' => $content,
'content_text' => $status->caption,
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
'emojis' => CustomEmoji::scan($status->caption),
@ -55,7 +50,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'visibility' => $status->scope ?? $status->visibility,
'application' => [
'name' => 'web',
'website' => null
'website' => null,
],
'language' => null,
'mentions' => StatusMentionService::get($status->id),