Skip to content

Commit

Permalink
Merge branch 'master' into all-progress-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland authored Jan 17, 2025
2 parents e04aef9 + 65e3052 commit f136368
Show file tree
Hide file tree
Showing 319 changed files with 8,018 additions and 1,097 deletions.
4 changes: 2 additions & 2 deletions app/Community/Actions/DropGameClaimAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function execute(Game $game): ?AchievementSetClaim

Cache::forget(CacheKey::buildUserExpiringClaimsCacheKey($firstCollabClaim->user->User));

addArticleComment("Server", ArticleType::SetClaim, $game->ID, "Primary claim dropped by {$currentUser->User}, transferred to {$firstCollabClaim->user->User}");
addArticleComment("Server", ArticleType::SetClaim, $game->ID, "Primary claim dropped by {$currentUser->display_name}, transferred to {$firstCollabClaim->user->display_name}");
} else {
addArticleComment("Server", ArticleType::SetClaim, $game->ID, ClaimType::toString($claim->ClaimType) . " claim dropped by {$currentUser->User}");
addArticleComment("Server", ArticleType::SetClaim, $game->ID, ClaimType::toString($claim->ClaimType) . " claim dropped by {$currentUser->display_name}");
}

$webhookUrl = config('services.discord.webhook.claims');
Expand Down
100 changes: 100 additions & 0 deletions app/Community/Actions/FetchDynamicShortcodeContentAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

declare(strict_types=1);

namespace App\Community\Actions;

use App\Data\UserData;
use App\Models\Achievement;
use App\Models\Game;
use App\Models\Ticket;
use App\Models\User;
use App\Platform\Data\AchievementData;
use App\Platform\Data\GameData;
use App\Platform\Data\TicketData;
use Illuminate\Support\Collection;

class FetchDynamicShortcodeContentAction
{
public function execute(
array $usernames = [],
array $ticketIds = [],
array $achievementIds = [],
array $gameIds = [],
): array {
$results = collect([
'users' => $this->fetchUsers($usernames),
'tickets' => $this->fetchTickets($ticketIds),
'achievements' => $this->fetchAchievements($achievementIds),
'games' => $this->fetchGames($gameIds),
]);

return $results->toArray();
}

/**
* @return Collection<int, UserData>
*/
private function fetchUsers(array $usernames): Collection
{
if (empty($usernames)) {
return collect();
}

$users = User::query()
->where(function ($query) use ($usernames) {
$query->whereIn('User', $usernames)
->orWhereIn('display_name', $usernames);
})
->get();

return $users->map(fn (User $user) => UserData::fromUser($user));
}

/**
* @return Collection<int, TicketData>
*/
private function fetchTickets(array $ticketIds): Collection
{
if (empty($ticketIds)) {
return collect();
}

return Ticket::with('achievement')
->whereIn('ID', $ticketIds)
->get()
->map(fn (Ticket $ticket) => TicketData::fromTicket($ticket)->include('state', 'ticketable'));
}

/**
* @return Collection<int, AchievementData>
*/
private function fetchAchievements(array $achievementIds): Collection
{
if (empty($achievementIds)) {
return collect();
}

return Achievement::whereIn('ID', $achievementIds)
->get()
->map(fn (Achievement $achievement) => AchievementData::fromAchievement($achievement)->include(
'badgeUnlockedUrl',
'points'
));
}

/**
* @return Collection<int, GameData>
*/
private function fetchGames(array $gameIds): Collection
{
if (empty($gameIds)) {
return collect();
}

return Game::with('system')
->whereIn('ID', $gameIds)
->get()
->map(fn (Game $game) => GameData::fromGame($game)->include('badgeUrl', 'system.name'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ public function execute(string $messageBody): string
return $messageBody;
}

$users = User::whereIn('ID', $userIds)->get()->keyBy('ID');
$users = User::whereIn('ID', $userIds)
->get(['ID', 'User', 'display_name'])
->keyBy('ID');

// Replace each shortcode with the corresponding username.
return preg_replace_callback('/\[user=(\d+)\]/', function ($matches) use ($users) {
$userId = $matches[1];
$user = $users->get($userId);

return '[user=' . ($user ? $user->username : $userId) . ']';
$username = $user ? ($user->display_name ?? $user->username) : $userId;

return "[user={$username}]";
}, $messageBody);
}
}
2 changes: 1 addition & 1 deletion app/Community/Commands/GenerateAnnualRecap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(): void
if ($userId) {
$user = is_numeric($userId)
? User::findOrFail($userId)
: User::where('User', $userId)->firstOrFail();
: User::whereName($userId)->firstOrFail();

$this->generateAnnualRecapAction->execute($user);
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/Community/Components/UserCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function getUserData(string $username): ?array
return Cache::store('array')->rememberForever(
CacheKey::buildUserCardDataCacheKey($username),
function () use ($username): ?array {
$foundUser = User::firstWhere('User', $username);
$foundUser = User::whereName($username)->first();

return $foundUser ? [
...$foundUser->toArray(),
Expand All @@ -79,7 +79,7 @@ private function buildAllCardViewValues(string $username, array $rawUserData): a

private function buildCardBioData(array $rawUserData): array
{
$username = $rawUserData['User'] ?? "";
$username = $rawUserData['display_name'] ?? $rawUserData['User'] ?? "";
$motto = $rawUserData['Motto'] && !$rawUserData['isMuted'] ? $rawUserData['Motto'] : null;
$avatarUrl = $rawUserData['avatarUrl'] ?? null;
$hardcorePoints = $rawUserData['RAPoints'] ?? 0;
Expand Down
18 changes: 9 additions & 9 deletions app/Community/Components/UserProfileMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ private function buildDeveloperStats(User $user, array $userMassData): array
$setsWorkedOnStat = [
'label' => 'Achievement sets worked on',
'value' => localized_number($gameAuthoredAchievementsCount),
'href' => $gameAuthoredAchievementsCount ? route('developer.sets', ['user' => $user]) : null,
'href' => $gameAuthoredAchievementsCount ? route('developer.sets', ['user' => $user->display_name]) : null,
'isMuted' => !$gameAuthoredAchievementsCount,
];

// Achievements unlocked by players
$achievementsUnlockedByPlayersStat = [
'label' => 'Achievements unlocked by players',
'value' => localized_number($userMassData['ContribCount']),
'href' => $userMassData['ContribCount'] > 0 ? route('user.achievement-author.feed', ['user' => $user]) : null,
'href' => $userMassData['ContribCount'] > 0 ? route('user.achievement-author.feed', ['user' => $user->display_name]) : null,
'isMuted' => !$userMassData['ContribCount'],
];

// Points awarded to players
$pointsAwardedToPlayersStat = [
'label' => 'Points awarded to players',
'value' => localized_number($userMassData['ContribYield']),
'href' => $userMassData['ContribYield'] > 0 ? route('user.achievement-author.feed', ['user' => $user]) : null,
'href' => $userMassData['ContribYield'] > 0 ? route('user.achievement-author.feed', ['user' => $user->display_name]) : null,
'isMuted' => !$userMassData['ContribYield'],
];

Expand All @@ -100,7 +100,7 @@ private function buildDeveloperStats(User $user, array $userMassData): array
$codeNotesCreatedStat = [
'label' => 'Code notes created',
'value' => localized_number($totalAuthoredCodeNotes),
'href' => $totalAuthoredCodeNotes ? '/individualdevstats.php?u=' . $user->User . '#code-notes' : null,
'href' => $totalAuthoredCodeNotes ? '/individualdevstats.php?u=' . $user->display_name . '#code-notes' : null,
'isMuted' => !$totalAuthoredCodeNotes,
];

Expand All @@ -111,7 +111,7 @@ private function buildDeveloperStats(User $user, array $userMassData): array
$leaderboardsCreatedStat = [
'label' => 'Leaderboards created',
'value' => localized_number($totalAuthoredLeaderboards),
'href' => $totalAuthoredLeaderboards ? '/individualdevstats.php?u=' . $user->User : null,
'href' => $totalAuthoredLeaderboards ? '/individualdevstats.php?u=' . $user->display_name : null,
'isMuted' => !$totalAuthoredLeaderboards,
];

Expand All @@ -122,8 +122,8 @@ private function buildDeveloperStats(User $user, array $userMassData): array
}
$openTicketsStat = [
'label' => 'Open tickets',
'value' => $openTickets === null ? "Tickets can't be assigned to {$user->User}." : localized_number($openTickets),
'href' => $openTickets ? route('developer.tickets', ['user' => $user]) : null,
'value' => $openTickets === null ? "Tickets can't be assigned to {$user->display_name}." : localized_number($openTickets),
'href' => $openTickets ? route('developer.tickets', ['user' => $user->display_name]) : null,
'isMuted' => !$openTickets,
];

Expand Down Expand Up @@ -242,7 +242,7 @@ private function buildPlayerStats(
'value' => localized_number($totalGamesBeaten),
'isHrefLabelBeforeLabel' => false,
'isMuted' => !$totalGamesBeaten,
'href' => $retailGamesBeaten ? route('ranking.beaten-games', ['filter[user]' => $user->username]) : null,
'href' => $retailGamesBeaten ? route('ranking.beaten-games', ['filter[user]' => $user->display_name]) : null,
];

// Started games beaten
Expand Down Expand Up @@ -329,7 +329,7 @@ private function buildSocialStats(User $user): array
$forumPostsStat = [
'label' => 'Forum posts',
'value' => localized_number($numForumPosts),
'href' => $numForumPosts ? route('user.posts.index', ['user' => $user]) : null,
'href' => $numForumPosts ? route('user.posts.index', ['user' => $user->display_name]) : null,
'isMuted' => $numForumPosts === 0,
];

Expand Down
57 changes: 57 additions & 0 deletions app/Community/Controllers/Api/ForumTopicCommentApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace App\Community\Controllers\Api;

use App\Community\Actions\FetchDynamicShortcodeContentAction;
use App\Community\Requests\PreviewForumPostRequest;
use App\Community\Requests\UpdateForumTopicCommentRequest;
use App\Http\Controller;
use App\Models\ForumTopicComment;
use App\Support\Shortcode\Shortcode;
use Illuminate\Http\JsonResponse;

class ForumTopicCommentApiController extends Controller
{
public function store(): void
{
}

public function update(
UpdateForumTopicCommentRequest $request,
ForumTopicComment $comment
): JsonResponse {
$this->authorize('update', $comment);

// Take any RA links and convert them to relevant shortcodes.
// eg: "https://retroachievements.org/game/1" --> "[game=1]"
$newPayload = normalize_shortcodes($request->input('body'));

// Convert [user=$user->username] to [user=$user->id].
$newPayload = Shortcode::convertUserShortcodesToUseIds($newPayload);

$comment->body = $newPayload;
$comment->save();

return response()->json(['success' => true]);
}

public function destroy(): void
{
}

public function preview(
PreviewForumPostRequest $request,
FetchDynamicShortcodeContentAction $action
): JsonResponse {
$entities = $action->execute(
usernames: $request->input('usernames'),
ticketIds: $request->input('ticketIds'),
achievementIds: $request->input('achievementIds'),
gameIds: $request->input('gameIds'),
);

return response()->json($entities);
}
}
22 changes: 18 additions & 4 deletions app/Community/Controllers/ForumTopicCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

use App\Community\Actions\AddCommentAction;
use App\Community\Actions\GetUrlToCommentDestinationAction;
use App\Community\Actions\ReplaceUserShortcodesWithUsernamesAction;
use App\Community\Requests\ForumTopicCommentRequest;
use App\Data\EditForumTopicCommentPagePropsData;
use App\Data\ForumTopicCommentData;
use App\Models\ForumTopic;
use App\Models\ForumTopicComment;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response as InertiaResponse;

class ForumTopicCommentController extends CommentController
{
Expand Down Expand Up @@ -44,12 +48,22 @@ public function store(
// ->with('success', $this->resourceActionSuccessMessage('comment', 'create'));
}

public function edit(ForumTopicComment $comment): View
public function edit(ForumTopicComment $comment): InertiaResponse
{
$this->authorize('update', $comment);

return view('forum-topic-comment.edit')
->with('comment', $comment);
// "[user=1]" -> "[user=Scott]"
$comment->body = (new ReplaceUserShortcodesWithUsernamesAction())->execute($comment->body);

$props = new EditForumTopicCommentPagePropsData(
forumTopicComment: ForumTopicCommentData::from($comment)->include(
'forumTopic',
'forumTopic.forum',
'forumTopic.forum.category',
),
);

return Inertia::render('forums/post/[comment]/edit', $props);
}

protected function update(
Expand Down
2 changes: 1 addition & 1 deletion app/Community/Controllers/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function store(MessageRequest $request): RedirectResponse

(new AddToMessageThreadAction())->execute($thread, $user, $body);
} else {
$recipient = User::firstWhere('User', $input['recipient']);
$recipient = User::whereName($input['recipient'])->first();

if (!$user->can('sendToRecipient', [Message::class, $recipient])) {
return back()->withErrors($user->isMuted() ?
Expand Down
2 changes: 1 addition & 1 deletion app/Community/Controllers/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function updateEmail(UpdateEmailRequest $request): JsonResponse
'Server',
ArticleType::UserModeration,
$user->id,
"{$user->username} changed their email address"
"{$user->display_name} changed their email address"
);

return response()->json(['success' => true]);
Expand Down
3 changes: 3 additions & 0 deletions app/Community/Enums/TicketState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace App\Community\Enums;

use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript]
abstract class TicketState
{
public const Closed = 0;
Expand Down
6 changes: 3 additions & 3 deletions app/Community/Listeners/NotifyMessageThreadParticipants.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handle(MessageCreated $event): void

// send email?
if (BitSet($userTo->websitePrefs, UserPreference::EmailOn_PrivateMessage)) {
sendPrivateMessageEmail($userTo->User, $userTo->EmailAddress, $thread->title, $message->body, $userFrom->User);
sendPrivateMessageEmail($userTo->display_name, $userTo->EmailAddress, $thread->title, $message->body, $userFrom->display_name);
}

$this->forwardToDiscord($userFrom, $userTo, $thread, $message);
Expand Down Expand Up @@ -156,9 +156,9 @@ private function forwardToDiscord(
'embeds' => [
[
'author' => [
'name' => $userFrom->username,
'name' => $userFrom->display_name,
// TODO 'url' => route('user.show', $userFrom),
'url' => url('user/' . $userFrom->username),
'url' => url('user/' . $userFrom->display_name),
'icon_url' => $userFrom->avatar_url,
],
'title' => mb_substr($messageThread->title, 0, 100),
Expand Down
Loading

0 comments on commit f136368

Please sign in to comment.