Skip to content
Merged
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: 2 additions & 0 deletions KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
11 changes: 6 additions & 5 deletions app/Enums/RepliesPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
23 changes: 23 additions & 0 deletions tests/Feature/Controllers/Api/LogControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down