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
6namespace App\Transformers;
7
8use App\Models\Follow;
9
10class FollowCommentTransformer extends FollowTransformer
11{
12 protected array $availableIncludes = [
13 'commentable_meta',
14 'latest_comment',
15 ];
16
17 private $latestComments;
18
19 public function __construct($latestComments = null)
20 {
21 // should be keyed by "type:id"
22 $this->latestComments = $latestComments;
23 }
24
25 public function includeCommentableMeta(Follow $follow)
26 {
27 return $this->item($follow->notifiable, new CommentableMetaTransformer());
28 }
29
30 public function includeLatestComment(Follow $follow)
31 {
32 $comment = $this->latestComments["{$follow->notifiable_type}:{$follow->notifiable_id}"] ?? null;
33
34 if ($comment !== null) {
35 return $this->item($comment, new CommentTransformer());
36 }
37 }
38}