-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into all-progress-fix
- Loading branch information
Showing
319 changed files
with
8,018 additions
and
1,097 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
app/Community/Actions/FetchDynamicShortcodeContentAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/Community/Controllers/Api/ForumTopicCommentApiController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.