Skip to content
Draft
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
2 changes: 1 addition & 1 deletion KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/CommitReplyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
5 changes: 4 additions & 1 deletion app/Http/Requests/ListApiCommitRepliesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,14 +27,16 @@ 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<string, list<string>>
*/
public function rules(): array
{
return [
'newest' => ['sometimes', 'boolean'],
'limit' => ['sometimes', 'integer', 'between:1,'.CommitRepliesQuery::PER_PAGE],
];
}
}
30 changes: 30 additions & 0 deletions tests/Feature/Controllers/Api/CommitReplyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand Down