Repository navigation
Expand file tree
/
Copy pathUserController.php
More file actions
56 lines (48 loc) · 2.64 KB
/
Copy pathUserController.php
File metadata and controls
56 lines (48 loc) · 2.64 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
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Enums\ActivityScale;
use App\Http\Requests\ShowApiUserRequest;
use App\Http\Resources\CommitResource;
use App\Http\Resources\UserResource;
use App\Models\Commit;
use App\Models\User;
use App\Queries\BioProfilesQuery;
use App\Queries\PinnedCommitQuery;
use App\Queries\ReplyPreviewsQuery;
use App\Queries\UserAchievementsQuery;
use App\Queries\UserActivityQuery;
use App\Queries\UserStreakQuery;
use Illuminate\Container\Attributes\CurrentUser;
final readonly class UserController
{
/**
* A signed request gets the profile as the web shows it to that user, with whether they mute it, its achievements
* and Unix rank, and how many pastéis it was given, which the app only shows in pastéis mode, as the web does. The
* pinned commit is left out of the commits list, so it comes with the profile, as on the web. Anyone gets which
* handles the bio mentions have a page on /dev/null, by lowercase handle, so only those link to one.
*/
public function show(ShowApiUserRequest $request, #[CurrentUser] ?User $currentUser, User $user, UserActivityQuery $activity, UserStreakQuery $streaks, UserAchievementsQuery $achievements, PinnedCommitQuery $pinned, ReplyPreviewsQuery $replyPreviews, BioProfilesQuery $bioProfiles): UserResource
{
if ($currentUser instanceof User) {
$pinnedCommit = $pinned->get($user, $currentUser);
$replyPreviews->load(array_filter([$pinnedCommit]), $currentUser);
$userStreaks = $streaks->get($user, $currentUser);
return UserResource::make($user->loadCounts($currentUser))->additional([
'is_following' => $currentUser->isFollowing($user),
'follows_you' => $user->isFollowing($currentUser),
'is_muting' => $currentUser->isMuting($user),
'pasteis_received' => $user->pasteis_received,
// API clients don't know the half-year scale yet, so they keep getting the year for anyone past a month.
'activity' => $activity->get($user, $currentUser, scales: [ActivityScale::Day, ActivityScale::Week, ActivityScale::Month]),
'streaks' => $userStreaks,
'achievements' => $achievements->get($user, $currentUser, $userStreaks),
'pinned_commit' => $pinnedCommit instanceof Commit ? CommitResource::make($pinnedCommit) : null,
'bio_profiles' => (object) $bioProfiles->get($user),
]);
}
return UserResource::make($user->loadPublicCounts())->additional([
'bio_profiles' => (object) $bioProfiles->get($user),
]);
}
}