Skip to content

Commit

Permalink
Fix opengraph on legacy comment with nonexistent user
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Nov 7, 2023
1 parent 4540200 commit 3f37f65
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/Libraries/Opengraph/CommentOpengraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public function __construct(private Comment $comment)

public function get(): array
{
if (!priv_check_user(null, 'CommentShow', $this->comment)->can()) {
return [];
}

$user = $this->comment->user;
$username = $user?->username ?? $this->comment->legacyName() ?? osu_trans('users.deleted');

return priv_check_user(null, 'CommentShow', $this->comment)->can()
? [
'description' => blade_safe(html_excerpt($this->comment->message_html, 100)),
'image' => $user->user_avatar,
'title' => osu_trans('comments.ogp.title', ['user' => $user->username]),
] : [];
return [
'description' => blade_safe(html_excerpt($this->comment->message_html, 100)),
'image' => $user?->user_avatar,
'title' => osu_trans('comments.ogp.title', ['user' => $username]),
];
}
}

0 comments on commit 3f37f65

Please sign in to comment.