diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 87930f627..673fe12f2 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -600,6 +600,8 @@ A signed request sees what the web shows you, such as your own pending commits a - list your devices and revoke them; - delete your account. +Signed lists show each commit with its newest reply or quote. Add `?replies_per_page=` with 3, 5, 10, 15, 20, or 25 to show that many replies and quotes, like the replies choice in Settings → Appearance. + Signed request bodies are JSON, or multipart when they carry images or a voice note, so app commits can have images with descriptions or a poll but no link-card choice. Before your first app submission, accept the [commit rules](#moderation) through the web composer. Signed requests are limited to **120 requests per minute per user**. Settings → Devices lists your approved devices, with the app's name when it gave one and when each was last used, and revokes them. Sources: [signed requests](app/Services/SignedRequests.php), [sign-in page](app/Http/Controllers/MobileAuthorizationController.php), [devices settings](resources/js/pages/device/index.tsx), [API routes](routes/api.php). diff --git a/app/Enums/RepliesPerPage.php b/app/Enums/RepliesPerPage.php index fe583bb83..e6ba6b6bd 100644 --- a/app/Enums/RepliesPerPage.php +++ b/app/Enums/RepliesPerPage.php @@ -17,14 +17,15 @@ enum RepliesPerPage: int case TwentyFive = 25; /** - * Kept in a cookie, like the theme, so guests can pick it too. API clients page on from the newest reply alone. + * Kept in a cookie, like the theme, so guests can pick it too. API clients ask with ?replies_per_page= and + * otherwise page on from the newest reply alone. */ public static function of(Request $request): self { - if ($request->is('api/*')) { - return self::One; - } + [$picked, $default] = $request->is('api/*') + ? [$request->query('replies_per_page'), self::One] + : [$request->cookie('replies_per_page'), self::Three]; - return array_find(self::cases(), fn (self $count): bool => (string) $count->value === $request->cookie('replies_per_page')) ?? self::Three; + return array_find(self::cases(), fn (self $count): bool => (string) $count->value === $picked) ?? $default; } } diff --git a/tests/Feature/Controllers/Api/LogControllerTest.php b/tests/Feature/Controllers/Api/LogControllerTest.php index 79305ac0a..febb51c34 100644 --- a/tests/Feature/Controllers/Api/LogControllerTest.php +++ b/tests/Feature/Controllers/Api/LogControllerTest.php @@ -233,6 +233,29 @@ ->assertJsonPath('meta.next_cursor', null); }); +it('shows as many reply previews as the client asks for, newest first', function (): void { + $commit = Commit::factory()->create(['created_at' => now()->subHour()]); + $replies = Commit::factory()->for($commit, 'parent')->count(4) + ->state(new Sequence(fn (Sequence $sequence): array => ['created_at' => now()->subMinutes(10 - $sequence->index)])) + ->create(); + + $response = signedApiRequest($this->keyPair, 'GET', route('api-log.show', ['latest', 'replies_per_page' => 3])); + + $response->assertOk() + ->assertJsonPath('data.0.reply_preview.data.*.id', [$replies[3]->id, $replies[2]->id, $replies[1]->id]); + + expect($response->json('data.0.reply_preview.next_cursor'))->toBeString(); +}); + +it('shows one reply preview when the client asks for a count the web does not offer', function (string $count): void { + $commit = Commit::factory()->create(['created_at' => now()->subHour()]); + Commit::factory()->for($commit, 'parent')->count(4)->create(); + + $response = signedApiRequest($this->keyPair, 'GET', route('api-log.show', ['latest', 'replies_per_page' => $count])); + + $response->assertOk()->assertJsonCount(1, 'data.0.reply_preview.data'); +})->with(['7', '3abc']); + it('does not query each commit or author', function (): void { Queue::fake([DetectCommitLanguage::class]); signedApiRequest($this->keyPair, 'GET', route('api-log.show', 'latest'))->assertOk();