Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ public function execute(
): PaginatedData|array {
$topics = $this->getRecentForumTopics($page, $permissions, $limit);

$shortcodeIds = [];
foreach ($topics as $topic) {
$postShortcodeIds = Shortcode::extractShortcodeIds($topic['ShortMsg']);
foreach ($postShortcodeIds as $key => $ids) {
$shortcodeIds[$key] = array_merge($shortcodeIds[$key] ?? [], $ids);
}
}
$shortcodeRecords = Shortcode::fetchRecords($shortcodeIds);
$shortcodeRecords = Shortcode::fetchRecordsFor(array_column($topics, 'ShortMsg'));

$transformedTopics = array_map(
fn ($topic) => ForumTopicData::fromRecentlyActiveTopic($topic, $shortcodeRecords)->include(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ public function execute(
->limit($limit)
->get();

$shortcodeIds = [];
foreach ($latestComments as $post) {
$postShortcodeIds = Shortcode::extractShortcodeIds($post->Payload);
foreach ($postShortcodeIds as $key => $ids) {
$shortcodeIds[$key] = array_merge($shortcodeIds[$key] ?? [], $ids);
}
}
$shortcodeRecords = Shortcode::fetchRecords($shortcodeIds);
$shortcodeRecords = Shortcode::fetchRecordsFor($latestComments->pluck('Payload'));

return $latestComments->map(function ($post) use ($numMessageChars, $shortcodeRecords) {
$postArray = (array) $post;
Expand Down
9 changes: 1 addition & 8 deletions app/Community/Components/ForumRecentActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ private function prepareRecentForumPosts(int $numToFetch = 4, int $userPermissio

$isShowAbsoluteDatesPreferenceSet = $userPreferences && BitSet($userPreferences, UserPreference::Forum_ShowAbsoluteDates);

$shortcodeIds = [];
foreach ($rawRecentPosts as $rawRecentPost) {
$postShortcodeIds = Shortcode::extractShortcodeIds($rawRecentPost['Payload']);
foreach ($postShortcodeIds as $key => $ids) {
$shortcodeIds[$key] = array_merge($shortcodeIds[$key] ?? [], $ids);
}
}
$shortcodeRecords = Shortcode::fetchRecords($shortcodeIds);
$shortcodeRecords = Shortcode::fetchRecordsFor($rawRecentPosts->pluck('Payload'));

foreach ($rawRecentPosts as $rawRecentPost) {
$recentForumPosts[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ public function index(Request $request, User $user): InertiaResponse
page: $page,
);

$shortcodeIds = [];
foreach ($posts as $post) {
$postShortcodeIds = Shortcode::extractShortcodeIds($post['ShortMsg']);
foreach ($postShortcodeIds as $key => $ids) {
$shortcodeIds[$key] = array_merge($shortcodeIds[$key] ?? [], $ids);
}
}
$shortcodeRecords = Shortcode::fetchRecords($shortcodeIds);
$shortcodeRecords = Shortcode::fetchRecordsFor(array_column($posts, 'ShortMsg'));

$transformedPosts = array_map(
fn ($post) => ForumTopicData::fromUserPost($post, $shortcodeRecords)->include('latestComment'),
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class EncryptCookies extends Middleware
'datatable_view_preference_setrequest_general_games',
'datatable_view_preference_setrequest_user_games',
'datatable_view_preference_system_games',
'datatable_view_preference_tickets_all',
'hide_nonmissable_achievements_games',
'hide_unlocked_achievements_games',
'prefers_hidden_user_completed_sets',
Expand Down
10 changes: 7 additions & 3 deletions app/Platform/Controllers/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ public function index(TicketListRequest $request): InertiaResponse
{
$this->authorize('viewAny', Ticket::class);

$scope = TicketListScope::All;

$action = new BuildTicketListAction();
$result = $action->execute(TicketListScope::All, null, $request);
$result = $action->execute($scope, null, $request);

$props = new TicketListPagePropsData(
scope: TicketListScope::All,
scope: $scope,
paginatedTickets: $result['paginatedTickets'],
stateCounts: $result['stateCounts'],
availableFilters: $action->getAvailableFilters(TicketListScope::All),
availableFilters: $action->getAvailableFilters($scope),
facetCounts: $result['facetCounts'],
persistenceCookieName: 'datatable_view_preference_tickets_all',
persistedViewPreferences: $request->getCookiePreferences(),
);

return Inertia::render('tickets', $props);
Expand Down
3 changes: 3 additions & 0 deletions app/Platform/Data/TicketListPagePropsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function __construct(
public array $availableFilters,
#[LiteralTypeScriptType('Record<string, Record<string, number>>')]
public array $facetCounts,
public string $persistenceCookieName,
#[LiteralTypeScriptType('Record<string, any> | null')]
public ?array $persistedViewPreferences = null,
public ?GameData $game = null,
public ?AchievementData $achievement = null,
public ?UserData $user = null,
Expand Down
45 changes: 37 additions & 8 deletions app/Platform/Requests/TicketListRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,53 @@ public function getPage(): int
return (int) $this->input('page.number', 1);
}

/**
* @return array<string, mixed>|null
*/
public function getCookiePreferences(): ?array
{
return once(function (): ?array {
$cookie = $this->cookie('datatable_view_preference_tickets_all');
if (!is_string($cookie)) {
return null;
}

$preferences = json_decode($cookie, true);

return is_array($preferences) ? $preferences : null;
});
}

/**
* @return array{field: TicketListSortField, direction: 'asc'|'desc'}
*/
public function getSort(): array
{
$sortParam = $this->input('sort');
$sortParam = $this->normalizeSortParam($this->input('sort'))
?? $this->normalizeSortParam($this->getCookiePreferences()['sortParam'] ?? null)
?? '-' . TicketListSortField::CreatedAt->value;

// Newest first is the default sort order.
$isDescending = str_starts_with($sortParam, '-');

return [
'field' => TicketListSortField::from(ltrim($sortParam, '-')),
'direction' => $isDescending ? 'desc' : 'asc',
];
}

private function normalizeSortParam(mixed $sortParam): ?string
{
if (!is_string($sortParam) || $sortParam === '') {
return ['field' => TicketListSortField::CreatedAt, 'direction' => 'desc'];
return null;
}

$direction = 'asc';
if (str_starts_with($sortParam, '-')) {
$direction = 'desc';
$sortParam = ltrim($sortParam, '-');
$isDescending = str_starts_with($sortParam, '-');
$fieldValue = $isDescending ? mb_substr($sortParam, 1) : $sortParam;

if (TicketListSortField::tryFrom($fieldValue) === null) {
return null;
}

return ['field' => TicketListSortField::from($sortParam), 'direction' => $direction];
return $isDescending ? "-{$fieldValue}" : $fieldValue;
}
}
18 changes: 17 additions & 1 deletion app/Support/Shortcode/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ public static function extractShortcodeIds(string $input): array
];
}

/**
* @param iterable<string> $inputs
*/
public static function fetchRecordsFor(iterable $inputs): array
{
$shortcodeIds = [];

foreach ($inputs as $input) {
foreach (self::extractShortcodeIds($input) as $key => $ids) {
$shortcodeIds[$key] = array_merge($shortcodeIds[$key] ?? [], $ids);
}
}

return self::fetchRecords($shortcodeIds);
}

public static function fetchRecords(array $shortcodeIds): array
{
$results = [];
Expand Down Expand Up @@ -294,7 +310,7 @@ public static function stripAndClamp(
$input = trim($input);
}

if (!$shortcodeRecords) {
if ($shortcodeRecords === null) {
$shortcodeIds = Shortcode::extractShortcodeIds($input);
$shortcodeRecords = Shortcode::fetchRecords($shortcodeIds);
}
Expand Down
18 changes: 17 additions & 1 deletion lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1561,5 +1561,21 @@
"Issue type": "Issue type",
"Change {{label}} filter": "Change {{label}} filter",
"{{label}} is <1>{{value}}</1>": "{{label}} is <1>{{value}}</1>",
"Publish status": "Publish status"
"Publish status": "Publish status",
"Resolved by": "Resolved by",
"Version": "Version",
"Core": "Core",
"Hash": "Hash",
"Did not cancel": "Did not cancel",
"Did not start": "Did not start",
"Did not submit": "Did not submit",
"Submitted wrong value": "Submitted wrong value",
"Display": "Display",
"Sort": "Sort",
"Reset to defaults": "Reset to defaults",
"Sort by": "Sort by",
"Ascending": "Ascending",
"Descending": "Descending",
"Oldest first": "Oldest first",
"Newest first": "Newest first"
}
Loading