Repository navigation
Expand file tree
/
Copy pathCommitPhotoController.php
More file actions
57 lines (50 loc) · 2.38 KB
/
Copy pathCommitPhotoController.php
File metadata and controls
57 lines (50 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Dto\ThreadContinuation;
use App\Http\Requests\ShowCommitPhotoRequest;
use App\Http\Resources\ShownStreams;
use App\Models\Commit;
use App\Models\Profile;
use App\Models\User;
use App\Queries\CommitAncestorsQuery;
use App\Queries\CommitContinuationQuery;
use App\Queries\CommitRepliesQuery;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\RedirectResponse;
use Illuminate\Pagination\CursorPaginator;
use Inertia\Inertia;
use Inertia\Response;
final readonly class CommitPhotoController
{
public function show(ShowCommitPhotoRequest $request, #[CurrentUser] ?User $currentUser, Profile $profile, Commit $commit, int $photo, CommitAncestorsQuery $ancestors, CommitContinuationQuery $continuation, CommitRepliesQuery $replies): RedirectResponse|Response
{
if (! $currentUser instanceof User) {
return to_route('commit.show', [$profile, $commit]);
}
$focusedCommit = null;
$getCommit = function () use (&$focusedCommit, $commit, $currentUser): Commit {
return $focusedCommit ??= Commit::query()
->withVisibleReplyCount($currentUser)
->withContinuationId($currentUser)
->with(['author', 'linkPreview', 'images'])
->withQuotedCommitFor($currentUser)
->withStarsFor($currentUser)
->findOrFail($commit->id);
};
$threadContinuation = null;
$getContinuation = function () use (&$threadContinuation, $continuation, $getCommit, $currentUser): ThreadContinuation {
return $threadContinuation ??= $continuation->get($getCommit(), $currentUser);
};
return Inertia::render('commit/show', [
'commit' => fn (): ?array => ShownStreams::commit($getCommit()),
'ancestors' => fn (): array => ShownStreams::commits($ancestors->get($commit, $currentUser)),
'continuation' => fn (): array => ShownStreams::continuation($getContinuation()),
'replies' => fn (): ?CursorPaginator => $getContinuation()->commits->isEmpty() ? ShownStreams::page($replies->paginate($commit, $currentUser, limit: $request->repliesPerPage())) : null,
'photo' => fn (): array => [
'commit' => ShownStreams::commit($getCommit()),
'index' => $photo - 1,
],
]);
}
}