Skip to content

Commit

Permalink
Update StatusTransformer, generate autolink on request
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Oct 16, 2023
1 parent 9677791 commit dfe2379
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Transformer/Api/StatusStatelessTransformer.php
Expand Up @@ -16,13 +16,15 @@
use App\Services\StatusMentionService;
use App\Services\PollService;
use App\Models\CustomEmoji;
use App\Util\Lexer\Autolink;

class StatusStatelessTransformer extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
$taggedPeople = MediaTagService::get($status->id);
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
$rendered = $status->caption ? Autolink::create()->autolink($status->caption) : null;

return [
'_v' => 1,
Expand All @@ -34,7 +36,7 @@ public function transform(Status $status)
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id, false) : null,
'content' => $status->rendered ?? $status->caption,
'content' => $rendered,
'content_text' => $status->caption,
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
'emojis' => CustomEmoji::scan($status->caption),
Expand Down
4 changes: 3 additions & 1 deletion app/Transformer/Api/StatusTransformer.php
Expand Up @@ -19,6 +19,7 @@
use App\Services\PollService;
use App\Models\CustomEmoji;
use App\Services\BookmarkService;
use App\Util\Lexer\Autolink;

class StatusTransformer extends Fractal\TransformerAbstract
{
Expand All @@ -27,6 +28,7 @@ public function transform(Status $status)
$pid = request()->user()->profile_id;
$taggedPeople = MediaTagService::get($status->id);
$poll = $status->type === 'poll' ? PollService::get($status->id, $pid) : null;
$rendered = $status->caption ? Autolink::create()->autolink($status->caption) : null;

return [
'_v' => 1,
Expand All @@ -37,7 +39,7 @@ public function transform(Status $status)
'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' => $status->rendered ?? $status->caption,
'content' => $rendered,
'content_text' => $status->caption,
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
'emojis' => CustomEmoji::scan($status->caption),
Expand Down

0 comments on commit dfe2379

Please sign in to comment.