diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index a34915941..09409ad6f 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -610,7 +610,7 @@ 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 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. A commit's own replies and quotes come 50 a page; add `?limit=` from 1 to 50 for fewer. 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**. Each action's per-minute limit (pastéis, opening issues, and so on) counts on its own, shared between the web and the API. Settings → Devices lists your approved devices, with the app's name when it gave one and when each was last used, and revokes them. diff --git a/app/Http/Controllers/Api/CommitReplyController.php b/app/Http/Controllers/Api/CommitReplyController.php index 7506a4a07..e39486c86 100644 --- a/app/Http/Controllers/Api/CommitReplyController.php +++ b/app/Http/Controllers/Api/CommitReplyController.php @@ -16,6 +16,6 @@ { public function index(ListApiCommitRepliesRequest $request, #[CurrentUser] User $user, Commit $commit, CommitRepliesQuery $replies): AnonymousResourceCollection { - return CommitResource::collection($replies->paginate($commit, $user, $request->boolean('newest'))->withQueryString()); + return CommitResource::collection($replies->paginate($commit, $user, $request->boolean('newest'), $request->integer('limit', CommitRepliesQuery::PER_PAGE))->withQueryString()); } } diff --git a/app/Http/Requests/ListApiCommitRepliesRequest.php b/app/Http/Requests/ListApiCommitRepliesRequest.php index 359a8f9b0..dd82ffe53 100644 --- a/app/Http/Requests/ListApiCommitRepliesRequest.php +++ b/app/Http/Requests/ListApiCommitRepliesRequest.php @@ -6,6 +6,7 @@ use App\Models\Commit; use App\Models\User; +use App\Queries\CommitRepliesQuery; use Illuminate\Auth\Access\Response; use Illuminate\Foundation\Http\FormRequest; @@ -26,7 +27,8 @@ public function authorize(): Response } /** - * Newest first continues the next_cursor of a reply preview, as on the web. + * Newest first continues the next_cursor of a reply preview, as on the web, and a page holds up to 50 replies, or + * fewer when the app asks for fewer, as the web's do. * * @return array> */ @@ -34,6 +36,7 @@ public function rules(): array { return [ 'newest' => ['sometimes', 'boolean'], + 'limit' => ['sometimes', 'integer', 'between:1,'.CommitRepliesQuery::PER_PAGE], ]; } } diff --git a/tests/Feature/Controllers/Api/CommitReplyControllerTest.php b/tests/Feature/Controllers/Api/CommitReplyControllerTest.php index adfc109fc..178f85b44 100644 --- a/tests/Feature/Controllers/Api/CommitReplyControllerTest.php +++ b/tests/Feature/Controllers/Api/CommitReplyControllerTest.php @@ -108,6 +108,36 @@ ->assertJsonPath('data.0.body', 'Reply 50'); }); +it('lists as many replies a page as asked for, and keeps that limit on the next page', function (): void { + $parent = Commit::factory()->create(); + + Commit::factory()->for($parent, 'parent')->count(12) + ->state(new Sequence(fn (Sequence $sequence): array => [ + 'body' => "Reply {$sequence->index}", + 'created_at' => now()->subMinutes(100 - $sequence->index), + ])) + ->create(); + + $first = signedApiRequest($this->keyPair, 'GET', route('api-commit-reply.index', [$parent, 'limit' => 10])); + + $first->assertOk() + ->assertJsonCount(10, 'data') + ->assertJsonPath('data.9.body', 'Reply 9') + ->assertJsonPath('meta.per_page', 10); + + signedApiRequest($this->keyPair, 'GET', (string) $first->json('links.next')) + ->assertOk() + ->assertJsonPath('data.*.body', ['Reply 10', 'Reply 11']); +}); + +it('lists at most 50 replies a page', function (mixed $limit): void { + $parent = Commit::factory()->create(); + + signedApiRequest($this->keyPair, 'GET', route('api-commit-reply.index', [$parent, 'limit' => $limit])) + ->assertUnprocessable() + ->assertJsonValidationErrors('limit'); +})->with([0, 51, 'ten']); + it('continues the cursor of a reply preview newest first, as the web does', function (): void { $parent = Commit::factory()->create(); $oldest = Commit::factory()->for($parent, 'parent')->create(['created_at' => now()->subMinutes(3)]);