From e284a36dd46473f9e0a48ecdfa232b6efadef091 Mon Sep 17 00:00:00 2001 From: sulimanbenhalim Date: Sun, 29 Nov 2026 05:39:51 +0200 Subject: [PATCH] Take a commit you deleted off a profile even when it was below the first page --- .../Concerns/HoldsNewCommits.php | 9 +++-- tests/Feature/Screens/CommitMenuTest.php | 36 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/NativeComponents/Concerns/HoldsNewCommits.php b/app/NativeComponents/Concerns/HoldsNewCommits.php index b73e1d6f..23514e84 100644 --- a/app/NativeComponents/Concerns/HoldsNewCommits.php +++ b/app/NativeComponents/Concerns/HoldsNewCommits.php @@ -5,6 +5,7 @@ use App\Devnull\Data\Commit; use App\Devnull\Data\Page; use App\Devnull\FreshPage; +use App\Devnull\ResponseCache; /** * A list of commits that takes fresh first pages without moving under your @@ -94,13 +95,17 @@ protected function waitingCommits(): array /** * Lays a fresh first page over the list. Newer commits wait for the pill - * unless $showNewer says you asked for them. + * unless $showNewer says you asked for them. Commits deleted on this phone + * leave it first, wherever they are in it: the fresh page only knows about + * its own, and the rows below it stay. * * @param array $json */ protected function layFreshCommits(array $json, bool $showNewer = false): void { - $fresh = FreshPage::over($this->commits, $this->nextCursor, Page::fromArray($json, Commit::fromArray(...)), $this->madeHere); + $deleted = array_flip(app(ResponseCache::class)->deletedIds()); + $shown = array_values(array_filter($this->commits, fn (Commit $commit): bool => ! isset($deleted[$commit->id]))); + $fresh = FreshPage::over($shown, $this->nextCursor, Page::fromArray($json, Commit::fromArray(...)), $this->madeHere); $this->commits = $fresh->items; $this->nextCursor = $fresh->nextCursor; diff --git a/tests/Feature/Screens/CommitMenuTest.php b/tests/Feature/Screens/CommitMenuTest.php index 86485d53..39ba9d46 100644 --- a/tests/Feature/Screens/CommitMenuTest.php +++ b/tests/Feature/Screens/CommitMenuTest.php @@ -1,5 +1,6 @@ $request->method() === 'DELETE' && $request->url() === 'http://devnull.test/api/v1/commits/c2'); }); +it('takes a commit you deleted off your profile when it was further down than the first page', function () { + $deleted = []; + + serveApi(function (Request $request) use (&$deleted) { + $route = $request->method().' '.parse_url($request->url(), PHP_URL_PATH); + + return match (true) { + str_starts_with($route, 'DELETE /api/v1/commits/') => tap(Http::response(null, 204), function () use (&$deleted, $route): void { + $deleted[] = basename($route); + }), + $route === 'GET /api/v1/users/local_dev' => Http::response(['data' => userWithCountsJson(commits: 3 - count($deleted)), 'is_following' => false, 'pinned_commit' => null]), + $route === 'GET /api/v1/users/local_dev/commits' && str_contains($request->url(), 'cursor=older') => Http::response(pageJson(array_values(array_filter([ + commitJson(['id' => 'c2', 'body' => 'Delete me here']), + commitJson(['id' => 'c1', 'body' => 'Delete me on its page']), + ], fn (array $commit): bool => ! in_array($commit['id'], $deleted, true))))), + $route === 'GET /api/v1/users/local_dev/commits' => Http::response(pageJson([commitJson(['id' => 'c3', 'body' => 'Keep me'])], 'older')), + default => Http::response(currentUserJson()), + }; + }); + + $screen = Native::visit('/log/users/local_dev', platform: 'ios') + ->call('loadMore') + ->assertSee('Delete me here') + ->tap('delete-c2') + ->emitNative(ButtonPressed::class, ['index' => 1, 'label' => 'Delete', 'id' => 'delete-commit']) + ->assertDontSee('Delete me here') + ->assertSee('Delete me on its page'); + + app(Client::class)->deleteCommit('c1'); + + $screen->call('onResume') + ->assertDontSee('Delete me on its page') + ->assertSee('Keep me'); +}); + it('deletes your reply from a commit page, staying on the page', function () { $deleted = false;