blockerIdWith($user); if ($blockerId !== null) { return Inertia::render('user/unavailable', [ 'handle' => $user->handle, 'blockedUser' => $blockerId === $currentUser->id ? $user : null, ]); } $streakData = null; $getStreaks = function () use (&$streakData, $streaks, $user, $currentUser): array { return $streakData ??= $streaks->get($user, $currentUser); }; $countedUser = null; $getCountedUser = function () use (&$countedUser, $user, $currentUser): User { return $countedUser ??= $currentUser instanceof User ? $user->loadCounts($currentUser) : $user->loadPublicCounts(); }; // What the profile shows about the user changes for everyone on its public channel, and what it shows about the // viewer's relationship to them on the viewer's own. $profile = new Channel('profiles.'.$user->id); $relationship = fn (Closure $value): Closure|LiveProp => $currentUser instanceof User ? Inertia::live($value, UserUpdate::Account->value, new PrivateChannel($currentUser)) : $value; $canSeeModerationHistory = $currentUser instanceof User && ($currentUser->is($user) || ($currentUser->isAdmin() && ! $user->isAdmin())); return Inertia::render('user/show', [ 'user' => Inertia::live(fn (): ?array => ShownStreams::user($getCountedUser()), 'profile', $profile), 'profileGuilds' => $currentUser instanceof User ? Inertia::live(fn (): ?array => $features->available(Feature::Guilds, $currentUser) ? $guilds->joined($user, $currentUser)->map(fn (Guild $guild): array => ['id' => $guild->id, ...GuildResource::make($guild)->resolve($request)])->all() : null, 'profile', $profile) ->live(UserUpdate::Guilds->value, new PrivateChannel($currentUser)) : null, 'bioProfiles' => fn (): array => $bioProfiles->get($user), 'pasteisReceived' => Inertia::live(fn (): ?int => $currentUser?->pasteis_mode ? $user->pasteis_received : null, 'profile', $profile), 'isFollowing' => $relationship(fn (): bool => $currentUser?->isFollowing($user) ?? false), 'followsYou' => $relationship(fn (): bool => $currentUser instanceof User && $user->isFollowing($currentUser)), 'isMuting' => $relationship(fn (): bool => $currentUser?->isMuting($user) ?? false), 'followersYouKnow' => fn (): ?array => $currentUser instanceof User && $currentUser->isNot($user) ? $followersYouKnow->preview($user, $currentUser) : null, 'canPush' => $relationship(fn (): bool => $currentUser instanceof User && $currentUser->canMessage($user) && ! in_array($pushAccess->get($currentUser, $user), [PushAccess::Restricted, PushAccess::Closed], true)), 'activity' => fn (): array => $activity->get($user, $currentUser), 'streaks' => $getStreaks, 'achievements' => fn (): array => $achievements->get($user, $currentUser, $getStreaks()), 'moderation' => $currentUser?->isAdmin() === true && ! $user->isAdmin() ? fn (): array => $moderation->get([$user])[$user->id] : null, 'moderationHistory' => match (true) { $currentUser instanceof User && $currentUser->is($user) => Inertia::live(fn (): array => $moderation->history($user), UserUpdate::Account->value, new PrivateChannel($currentUser)), $canSeeModerationHistory => fn (): array => $moderation->history($user), default => fn (): null => null, }, 'tab' => $request->tab(...), 'pinnedCommit' => Inertia::live(fn (): ?array => ShownStreams::commit($request->tab() === 'commits' ? $pinned->get($user, $currentUser) : null), 'profile', $profile), 'readme' => fn (): string|false|null => $request->tab() === 'readme' ? $readme->get($user) : null, // The README tab shows no commits, so it doesn't look for any. 'commits' => Inertia::scroll(fn (): CursorPaginator => ShownStreams::page($request->tab() === 'readme' ? new CursorPaginator([], 20) : $commits->builder($user, $currentUser, $request->tab() === 'replies') ->cursorPaginate(20) ->appends(['tab' => $request->tab()]))), ])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->user($getCountedUser())]); } public function destroy(DeleteUserRequest $request, #[CurrentUser] User $user, DeleteUser $action): RedirectResponse { Auth::logout(); $action->handle($user); $request->session()->invalidate(); $request->session()->regenerateToken(); return to_route('home'); } }