1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6declare(strict_types=1);
7
8namespace App\Libraries\Opengraph;
9
10use App\Models\Comment;
11
12class CommentOpengraph implements OpengraphInterface
13{
14 public function __construct(private Comment $comment)
15 {
16 }
17
18 public function get(): array
19 {
20 if (!priv_check_user(null, 'CommentShow', $this->comment)->can()) {
21 return [];
22 }
23
24 $user = $this->comment->user;
25 $username = $user?->username ?? $this->comment->legacyName() ?? osu_trans('users.deleted');
26
27 return [
28 'description' => blade_safe(html_excerpt($this->comment->message_html, 100)),
29 'image' => $user?->user_avatar,
30 'title' => osu_trans('comments.ogp.title', ['user' => $username]),
31 ];
32 }
33}