From 3436948ee850e4c991a682379bd1575b1adc427c Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 16 Nov 2026 00:23:34 +0000 Subject: [PATCH 01/30] Hide replies on the Log until asked, and line the rail's end dot up with the actions Replies no longer show under a commit in a feed. The replies button moves to its own line under the action row and opens the thread in place, ten replies at a time, with Show more for the next ten. A reply has the same button under its own actions, which opens its replies inline one step in. Deeper than that, the button opens the reply's page. devnull's API sends 50 replies a page whatever `limit` asks for, so the app keeps what it was sent and shows ten at a time, asking for the next page only once they all show. The end dot of a commit's rail is now drawn inside its action row, so it sits level with the actions whatever is above or below them. It used to be placed a fixed distance from the row's bottom, which assumed the action row's -my-[6] pulled it in. iOS does that, Android keeps the space and only moves the drawing, and a row with a thread under it had no bottom padding, so the dot sat above the actions in some rows and below in others. The action row now has no vertical negative margins, and the rail's lines are worked out from the fixed heights under it to meet the dot. Opening and closing a thread fades its rows in and out, and the chevron turns. Starring a commit pops the star as the web's star-pop does, and giving a pastel bumps it as the web's pastel button does. EDGE only animates from one frame to the next, so each step is a frame drawn when a short background Beat comes back. Quote now has its label beside its icon, as Reply always does. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Beat.php | 34 ++ app/Devnull/Client.php | 6 +- app/Devnull/Pop.php | 39 ++ app/Devnull/RowInputs.php | 4 +- app/Devnull/ThreadRows.php | 119 +++++ app/NativeComponents/CommitDetail.php | 4 +- .../Concerns/ExpandsThreads.php | 263 +++++++++-- .../Concerns/HoldsNewCommits.php | 2 +- .../Concerns/PopsReactions.php | 59 +++ .../Concerns/ShowsCommits.php | 7 + app/NativeComponents/Log.php | 4 +- app/NativeComponents/Organization.php | 2 +- app/NativeComponents/Profile.php | 4 +- .../views/native/commit-detail.blade.php | 4 +- .../native/partials/commit-actions.blade.php | 73 ++-- .../partials/commit-row-content.blade.php | 20 +- .../views/native/partials/feed.blade.php | 42 +- .../views/native/partials/rail.blade.php | 17 +- .../native/partials/thread-more-row.blade.php | 33 ++ .../native/partials/thread-reply.blade.php | 14 +- tests/Feature/Screens/CommitCardTest.php | 9 +- .../Feature/Screens/CommitDetailCacheTest.php | 2 +- tests/Feature/Screens/CommitDetailTest.php | 24 +- tests/Feature/Screens/DraftStashTest.php | 2 +- tests/Feature/Screens/LogTest.php | 46 +- tests/Feature/Screens/LogThreadTest.php | 412 ++++++++++++++++++ tests/Feature/Screens/LogWindowTest.php | 23 +- tests/Feature/Screens/PasteisTest.php | 9 +- tests/Feature/Screens/ProfileTest.php | 7 +- tests/Feature/Screens/ReplyPreviewTest.php | 252 ----------- 30 files changed, 1097 insertions(+), 439 deletions(-) create mode 100644 app/Devnull/Beat.php create mode 100644 app/Devnull/Pop.php create mode 100644 app/Devnull/ThreadRows.php create mode 100644 app/NativeComponents/Concerns/PopsReactions.php create mode 100644 resources/views/native/partials/thread-more-row.blade.php create mode 100644 tests/Feature/Screens/LogThreadTest.php delete mode 100644 tests/Feature/Screens/ReplyPreviewTest.php diff --git a/app/Devnull/Beat.php b/app/Devnull/Beat.php new file mode 100644 index 00000000..c6598cfe --- /dev/null +++ b/app/Devnull/Beat.php @@ -0,0 +1,34 @@ +runningUnitTests()) { + usleep(max(0, $milliseconds) * 1000); + } + + return true; + } +} diff --git a/app/Devnull/Client.php b/app/Devnull/Client.php index b6538ae5..fc9990f1 100644 --- a/app/Devnull/Client.php +++ b/app/Devnull/Client.php @@ -110,10 +110,10 @@ public const string IssuesPath = 'issues'; /** - * How many replies the app asks for at a time. devnull sends 50 a page - * unless it's asked for fewer, and the app never asks for more than this. + * How many replies the app asks for at a time, in a feed's thread and on + * a commit's page. devnull sends 50 a page unless it's asked for fewer. */ - public const int RepliesPerPage = 5; + public const int RepliesPerPage = 10; /** * Where the signed-in account's timezone is saved, or unset, with whether their profile shows their local time. diff --git a/app/Devnull/Pop.php b/app/Devnull/Pop.php new file mode 100644 index 00000000..dc9e86f3 --- /dev/null +++ b/app/Devnull/Pop.php @@ -0,0 +1,39 @@ + ['scale' => 1.0, 'rotate' => 0.0, 'duration' => 150, 'easing' => 'ease-out'], + self::Up => ['scale' => $star ? 1.35 : 1.25, 'rotate' => $star ? -12.0 : 0.0, 'duration' => 150, 'easing' => 'ease-out'], + self::Down => ['scale' => 1.0, 'rotate' => 0.0, 'duration' => $star ? 320 : 180, 'easing' => $star ? 'spring' : 'ease-out'], + default => ['scale' => null, 'rotate' => null, 'duration' => null, 'easing' => null], + }; + } +} diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index 0659a309..c0409343 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -32,7 +32,9 @@ public static function for(Commit $commit, array $scope): array 'stashed' => $scope['stashed'] ?? [], 'unfolded' => $scope['unfolded'] ?? [], 'expandable' => isset($scope['threads']), - 'opened' => array_key_exists($commit->id, $scope['threads'] ?? []), + 'opened' => array_key_exists($commit->id, $scope['threads'] ?? []) && ! in_array($commit->id, $scope['closingThreads'] ?? [], true), + 'faded' => in_array($commit->id, $scope['fadedRows'] ?? [], true), + 'popping' => [$scope['popping']['star-'.$commit->id] ?? null, $scope['popping']['pastel-'.$commit->id] ?? null], 'tombstones' => $scope['tombstones'] ?? false, 'tombstoneReplies' => array_key_exists($commit->id, $scope['tombstoneReplies'] ?? []), 'shown' => [self::changing($commit), $commit->quotedCommit === null ? null : self::changing($commit->quotedCommit)], diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php new file mode 100644 index 00000000..3affe2a7 --- /dev/null +++ b/app/Devnull/ThreadRows.php @@ -0,0 +1,119 @@ +> $threads Open threads, by the id of the commit or reply they answer. + * @param array $cursors Where each open thread with more carries on. + * @param array $shown How many of each open thread's replies show. + * @param int|string|null $railLane The commit's rail running on past its thread, when its author's run carries on below. + * @return list, reply: Commit|null}> + */ + public static function under(Commit $commit, array $threads, array $cursors, array $shown, int|string|null $railLane = null): array + { + $thread = fn (string $id): array => array_slice($threads[$id] ?? [], 0, $shown[$id] ?? null); + $hasMore = fn (string $id): bool => isset($cursors[$id]) || count($thread($id)) < count($threads[$id] ?? []); + $replies = $thread($commit->id); + + if ($replies === []) { + return []; + } + + $rows = []; + $more = $hasMore($commit->id); + + foreach ($replies as $index => $reply) { + $nested = $reply->isDeleted() ? [] : $thread($reply->id); + $nestedMore = $nested !== [] && $hasMore($reply->id); + $followed = $index < count($replies) - 1 || $more; + + $rows[] = self::reply($reply, [ + 'lane' => $commit->lane(), + 'previousLane' => $index === 0 ? null : $replies[$index - 1]->lane(), + 'hasNext' => $followed || $nested !== [], + 'railLane' => $railLane, + 'thread' => $commit, + 'repliesInPlace' => true, + ]); + + foreach ($nested as $nestedIndex => $nestedReply) { + $rows[] = self::reply($nestedReply, [ + 'lane' => $reply->lane(), + 'previousLane' => $nestedIndex === 0 ? null : $nested[$nestedIndex - 1]->lane(), + 'hasNext' => $nestedIndex < count($nested) - 1 || $nestedMore, + 'railLane' => $railLane, + 'indent' => 32, + 'spine' => $followed ? $reply->lane() : null, + 'thread' => $reply, + 'repliesInPlace' => false, + ]); + } + + if ($nestedMore) { + $rows[] = self::more($reply->id, $nested[array_key_last($nested)]->lane(), $railLane, 32, $followed ? $reply->lane() : null); + } + } + + if ($more) { + $rows[] = self::more($commit->id, $replies[array_key_last($replies)]->lane(), $railLane); + } + + $last = array_key_last($rows); + $rows[$last]['data']['last'] = true; + + return $rows; + } + + /** + * @param array $data + * @return array{key: string, partial: string, data: array, reply: Commit} + */ + private static function reply(Commit $reply, array $data): array + { + return [ + 'key' => 'thread-reply-'.$reply->id, + 'partial' => 'native.partials.thread-reply', + 'data' => ['reply' => $reply, 'indent' => 0, 'spine' => null, 'last' => false, 'fades' => true, ...$data], + 'reply' => $reply, + ]; + } + + /** + * "Show more" at the foot of a thread, on a line down in the lane of the reply above it. + * + * @return array{key: string, partial: string, data: array, reply: null} + */ + private static function more(string $threadId, int|string $lane, int|string|null $railLane, int $indent = 0, int|string|null $spine = null): array + { + return [ + 'key' => 'thread-more-'.$threadId, + 'partial' => 'native.partials.thread-more-row', + 'data' => ['threadId' => $threadId, 'lane' => $lane, 'railLane' => $railLane, 'indent' => $indent, 'spine' => $spine, 'last' => false], + 'reply' => null, + ]; + } +} diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index f20c88a3..9fb0b843 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -39,9 +39,9 @@ * The commit opens near the top, under the commit it replies to, with the * ones before that behind "↑ N earlier commits" and its replies behind * "› N replies", each opened in place. Opened from a "› N replies" button - * ($data['replies']), its replies already show. They come five at a time + * ($data['replies']), its replies already show. They come ten at a time * (see Client::RepliesPerPage), and "Show more" under the last asks for the - * next five, as it does under a deleted reply's replies opened in place. + * next ten, as it does under a deleted reply's replies opened in place. * * It opens on the commit as it was last time, or opened from a row, on what * the row knew of it, then asks devnull for the rest behind it and fills it in. diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 2a5763ce..bee2b638 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -2,52 +2,83 @@ namespace App\NativeComponents\Concerns; +use App\Devnull\Beat; +use App\Devnull\Client; use App\Devnull\Data\Commit; use App\Devnull\Data\Page; +use App\Devnull\ThreadRows; /** - * "› N replies" under a commit in a feed opens its replies in place, the way - * the web's thread toggle does, and "Hide replies" closes them again. One - * level deep: a reply's own replies open its page. + * Replies in a feed stay hidden until you ask for them. "N replies", on its + * own line under a commit's actions, opens its replies in place, oldest first, + * ten at a time (Client::RepliesPerPage), with "Show more" under the last for + * the next ten. Tapped again ("Hide replies") it closes them. devnull's API + * sends 50 replies a page whatever `limit` asks for, so the replies it sent + * are kept and shown ten at a time ($threadShown), and the next page is only + * asked for once they're all showing. * - * The app asks for replies oldest first, five at a time (see - * Client::RepliesPerPage). A thread opened in place shows its first five, - * and "Show more" under them opens the rest on the commit's page, with its - * replies showing. + * A reply opened in place has the same button under its own actions, which + * opens its replies in place too, one step in. A reply that deep opens its + * replies on its page. Every thread is kept by the id of the commit or reply + * it answers, so a reply's replies sit in $threads beside its commit's. * - * Under a commit devnull sends with its newest reply, "Show more" opens the - * rest in place, newest first as on the web, so they're turned round here, - * and a thread longer than a page opens the commit's page instead. + * EDGE can't animate a row coming into a list or going out of it, so replies + * fade: a page that opens is drawn see-through ($fadedRows) and drawn again + * as it should be once a Beat comes back, which every row in a thread + * animates to. Closing fades its rows out the same way, then takes them out. * * A thread opened before opens at once from the cache, and refreshes behind. */ trait ExpandsThreads { /** - * The replies of each commit opened in place, by the commit's id. + * The replies opened in place, by the id of the commit or reply they answer. * * @var array> */ public array $threads = []; /** - * Threads opened from a preview with "Show more", which read newest first. + * Where the next page of each open thread starts, by the same id, for those with more. + * + * @var array + */ + public array $threadCursors = []; + + /** + * How many of each open thread's replies show, by the same id. + * + * @var array + */ + public array $threadShown = []; + + /** + * Open threads that have had a page after their first. + * + * @var list + */ + public array $pagedThreads = []; + + /** + * Rows drawn see-through: a page about to fade in, or a thread fading out. + * A reply's row goes by its id, a thread's "Show more" by "more-" and the + * thread's id. * * @var list */ - public array $newestFirst = []; + public array $fadedRows = []; /** - * Threads opened in place with more replies than they show. + * Threads fading out, still drawn until they've faded. * * @var list */ - public array $threadsWithMore = []; + public array $closingThreads = []; public function toggleReplies(string $id): void { if (array_key_exists($id, $this->threads)) { - $this->closeThread($id); + $this->fadeOut($id); return; } @@ -56,37 +87,96 @@ public function toggleReplies(string $id): void if ($kept === null) { $this->loadThread($id); - - return; + } else { + $this->takeThread($id, $kept); + $this->refreshThread($id); } - $this->takeThread($id, $kept); - $this->refreshThread($id); + if (array_key_exists($id, $this->threads)) { + $this->threadShown[$id] = min(Client::RepliesPerPage, count($this->threads[$id])); + $this->fadeIn($this->rowsOf($id, $this->shownReplies($id))); + } } /** - * "Show more" under the newest reply: the rest of the thread, in place. + * "Show more" under an open thread: its next page, under what's showing. */ public function showMoreReplies(string $id): void { - if (array_key_exists($id, $this->threads)) { + if (! $this->isOpenThread($id)) { return; } - if (! in_array($id, $this->newestFirst, true)) { - $this->newestFirst[] = $id; + $shown = $this->threadShown[$id] ?? count($this->threads[$id]); + + if ($shown >= count($this->threads[$id]) && ! $this->loadNextPage($id)) { + return; } - $kept = $this->cached('commits/'.$id.'/replies'); + $this->threadShown[$id] = min($shown + Client::RepliesPerPage, count($this->threads[$id])); + $this->fadeIn($this->rowsOf($id, array_slice($this->threads[$id], $shown, $this->threadShown[$id] - $shown))); + } - if ($kept === null) { - $this->loadThread($id); + /** + * The replies of an open thread that show. + * + * @return list + */ + public function shownReplies(string $id): array + { + return array_slice($this->threads[$id] ?? [], 0, $this->threadShown[$id] ?? null); + } - return; + /** + * Whether an open thread has replies past those that show, kept or still to ask for. + */ + public function hasMoreReplies(string $id): bool + { + return isset($this->threadCursors[$id]) || count($this->shownReplies($id)) < count($this->threads[$id] ?? []); + } + + /** + * Asks for the page after an open thread's replies, under them. False when there's none or it didn't come. + */ + private function loadNextPage(string $id): bool + { + $cursor = $this->threadCursors[$id] ?? null; + + if ($cursor === null) { + return false; } - $this->takeThread($id, $kept); - $this->refreshThread($id); + $page = $this->attempt(fn ($devnull) => $devnull->replies($id, $cursor)); + + if ($page === null || ! $this->isOpenThread($id)) { + return false; + } + + $loaded = array_flip(array_map(fn (Commit $reply): string => $reply->id, $this->threads[$id])); + $added = array_values(array_filter($page->items, fn (Commit $reply): bool => ! isset($loaded[$reply->id]))); + + $this->threads[$id] = [...$this->threads[$id], ...$added]; + $this->keepCursor($id, $page->nextCursor); + $this->pagedThreads = array_values(array_unique([...$this->pagedThreads, $id])); + + return $added !== []; + } + + /** + * Whether a thread shows, and isn't on its way out. + */ + public function isOpenThread(string $id): bool + { + return array_key_exists($id, $this->threads) && ! in_array($id, $this->closingThreads, true); + } + + /** + * Closes every thread at once, for a list that starts again. + */ + protected function forgetThreads(): void + { + $this->threads = $this->threadCursors = $this->threadShown = $this->pagedThreads = []; + $this->fadedRows = $this->closingThreads = []; } /** @@ -103,7 +193,7 @@ private function refreshThread(string $id): void { $this->refresh('commits/'.$id.'/replies', [], function (array $json) use ($id): void { // Closed while it was on its way. - if (array_key_exists($id, $this->threads)) { + if ($this->isOpenThread($id)) { $this->takeThread($id, $json); } }); @@ -118,6 +208,9 @@ private function takeThread(string $id, array $json): void } /** + * A thread's first page, over what it showed. Pages loaded after the first + * stay, past what it holds, with their own cursor. + * * @param Page $page */ private function openThread(string $id, Page $page): void @@ -129,33 +222,111 @@ private function openThread(string $id, Page $page): void return; } - if (! in_array($id, $this->newestFirst, true)) { - $this->threads[$id] = $page->items; - $this->threadsWithMore = array_values(array_diff($this->threadsWithMore, [$id])); + // With only the first page loaded, the fresh one is the whole thread: a reply that's gone goes. + if (in_array($id, $this->pagedThreads, true)) { + $fresh = array_flip(array_map(fn (Commit $reply): string => $reply->id, $page->items)); + $later = array_values(array_filter(array_slice($this->threads[$id], count($page->items)), fn (Commit $reply): bool => ! isset($fresh[$reply->id]))); + $this->threads[$id] = [...$page->items, ...$later]; - if ($page->hasMore()) { - $this->threadsWithMore[] = $id; - } + return; + } + + $this->threads[$id] = $page->items; + $this->keepCursor($id, $page->nextCursor); + } + + private function keepCursor(string $id, ?string $cursor): void + { + unset($this->threadCursors[$id]); + + if ($cursor !== null) { + $this->threadCursors[$id] = $cursor; + } + } + /** + * Takes a thread out, and the replies opened in it. + */ + private function closeThread(string $id): void + { + foreach ($this->threads[$id] ?? [] as $reply) { + $this->closeThread($reply->id); + } + + unset($this->threads[$id], $this->threadCursors[$id], $this->threadShown[$id]); + $this->pagedThreads = array_values(array_diff($this->pagedThreads, [$id])); + $this->closingThreads = array_values(array_diff($this->closingThreads, [$id])); + } + + /** + * Draws rows see-through for a frame, then as they are, which they fade to. + * + * @param list $rows + */ + private function fadeIn(array $rows): void + { + if ($rows === []) { return; } - // More than a page: the newest replies aren't on it, so the commit's page shows them. - if ($page->hasMore()) { - $this->closeThread($id); - $this->newestFirst = array_values(array_diff($this->newestFirst, [$id])); - $this->openReplies($id); + $this->fadedRows = array_values(array_unique([...$this->fadedRows, ...$rows])); + $shown = fn () => $this->fadedRows = array_values(array_diff($this->fadedRows, $rows)); + + Beat::dispatch(Beat::Step)->finished($shown)->failed($shown); + } + + /** + * Fades a thread's rows out, and the replies opened in it, then takes them out. + */ + private function fadeOut(string $id): void + { + if (in_array($id, $this->closingThreads, true)) { return; } - $this->threads[$id] = array_reverse($page->items); + $rows = $this->rowsInside($id); + $this->closingThreads[] = $id; + $this->fadedRows = array_values(array_unique([...$this->fadedRows, ...$rows])); + + $closed = function () use ($id, $rows): void { + $this->closeThread($id); + $this->fadedRows = array_values(array_diff($this->fadedRows, $rows)); + }; + + Beat::dispatch(ThreadRows::Fade)->finished($closed)->failed($closed); } - private function closeThread(string $id): void + /** + * The rows of $replies in a thread, and its "Show more" when it has more. + * + * @param list $replies + * @return list + */ + private function rowsOf(string $id, array $replies): array + { + return [ + ...array_map(fn (Commit $reply): string => $reply->id, $replies), + ...($this->hasMoreReplies($id) ? ['more-'.$id] : []), + ]; + } + + /** + * Every row a thread draws, the replies opened inside it included. + * + * @return list + */ + private function rowsInside(string $id): array { - unset($this->threads[$id]); - $this->threadsWithMore = array_values(array_diff($this->threadsWithMore, [$id])); + $rows = $this->rowsOf($id, $this->shownReplies($id)); + + foreach ($this->shownReplies($id) as $reply) { + if (array_key_exists($reply->id, $this->threads)) { + $rows = [...$rows, ...$this->rowsInside($reply->id)]; + } + } + + return $rows; } /** diff --git a/app/NativeComponents/Concerns/HoldsNewCommits.php b/app/NativeComponents/Concerns/HoldsNewCommits.php index 25e2ef68..dd5e42fb 100644 --- a/app/NativeComponents/Concerns/HoldsNewCommits.php +++ b/app/NativeComponents/Concerns/HoldsNewCommits.php @@ -111,7 +111,7 @@ protected function putNewCommitsOnTop(): void $shown = (new FreshPage($this->commits, $this->nextCursor, $this->newCommits, $this->newCommitsReplaceList, $this->newCommitsCursor))->withNewer(); if ($this->newCommitsReplaceList) { - $this->threads = []; + $this->forgetThreads(); $this->replacedList(); } diff --git a/app/NativeComponents/Concerns/PopsReactions.php b/app/NativeComponents/Concerns/PopsReactions.php new file mode 100644 index 00000000..3683ebd5 --- /dev/null +++ b/app/NativeComponents/Concerns/PopsReactions.php @@ -0,0 +1,59 @@ + + */ + public array $popping = []; + + protected function pop(string $button): void + { + $this->popping[$button] = Pop::Ready; + + $this->popStep($button, Pop::Ready, Pop::Up, Beat::Step, fn () => $this->popStep($button, Pop::Up, Pop::Down, 150, fn () => $this->popStep($button, Pop::Down, null, 400))); + } + + /** + * Moves $button from $from to $to after $wait milliseconds, unless a tap since started it again. + */ + private function popStep(string $button, string $from, ?string $to, int $wait, ?\Closure $then = null): void + { + $step = function () use ($button, $from, $to, $then): void { + if (($this->popping[$button] ?? null) !== $from) { + return; + } + + if ($to === null) { + unset($this->popping[$button]); + + return; + } + + $this->popping[$button] = $to; + + if ($then !== null) { + $then(); + } + }; + + Beat::dispatch($wait)->finished($step)->failed($step); + } +} diff --git a/app/NativeComponents/Concerns/ShowsCommits.php b/app/NativeComponents/Concerns/ShowsCommits.php index 05407927..19ce6212 100644 --- a/app/NativeComponents/Concerns/ShowsCommits.php +++ b/app/NativeComponents/Concerns/ShowsCommits.php @@ -45,6 +45,7 @@ trait ShowsCommits use OpensCommitSheet; use OpensHashtags; use OpensStargazers; + use PopsReactions; use VotesOnPolls; use WritesInBackground; @@ -223,6 +224,11 @@ public function toggleStar(string $id): void $this->showStar($id, ! $commit->starred); $this->queueStar($id, ! $commit->starred); + + // The web only pops a star going on. + if (! $commit->starred) { + $this->pop('star-'.$id); + } } /** @@ -250,6 +256,7 @@ public function givePastel(string $id): void app(Account::class)->rememberPasteis($pasteis->afterGiving()); $this->changeShownCommit($id, fn (Commit $shown): Commit => $shown->withMorePasteis(1)); + $this->pop('pastel-'.$id); $this->writeInBackground('POST', Client::pastelPath($id), null, fn (array $json) => $this->pastelGiven($id, $json), function (string $message, ?ApiException $exception = null) use ($id): void { $this->pastelTurnedDown($id, $exception); diff --git a/app/NativeComponents/Log.php b/app/NativeComponents/Log.php index 050e79e2..e99f8fe4 100644 --- a/app/NativeComponents/Log.php +++ b/app/NativeComponents/Log.php @@ -412,7 +412,7 @@ private function switchTo(string $log): void private function openAfresh(): void { $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->latestCommits = []; $this->suggestions = []; $this->rankedSince = null; @@ -959,7 +959,7 @@ private function takeRanking(string $log, array $json, bool $prefetch = true): v $this->commits = $page->items; $this->nextCursor = $page->nextCursor; $this->latestCommits = []; - $this->threads = []; + $this->forgetThreads(); $this->rankedSince = is_string($json['newest_commit_id'] ?? null) ? $json['newest_commit_id'] : null; $this->forgetNewCommits(); $this->keepStagedOnTop(); diff --git a/app/NativeComponents/Organization.php b/app/NativeComponents/Organization.php index c2f3718c..4531c108 100644 --- a/app/NativeComponents/Organization.php +++ b/app/NativeComponents/Organization.php @@ -296,7 +296,7 @@ private function switchTo(string $tab): void $this->tab = $tab; $this->listKey = $this->listKeys[$tab] ?? 0; $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->nextCursor = null; $this->commitsLoaded = false; $this->commitsFailed = false; diff --git a/app/NativeComponents/Profile.php b/app/NativeComponents/Profile.php index d4c1e690..4f19fc52 100644 --- a/app/NativeComponents/Profile.php +++ b/app/NativeComponents/Profile.php @@ -300,7 +300,7 @@ private function switchTo(string $tab): void $this->tab = $tab; $this->listKey = $this->listKeys[$tab] ?? 0; $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->nextCursor = null; $this->commitsLoaded = false; $this->forgetNewCommits(); @@ -732,7 +732,7 @@ private function showBlocked(): void private function forgetShownCommits(): void { $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->nextCursor = null; $this->forgetNewCommits(); } diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index c633a3d0..4eda3db3 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -19,10 +19,10 @@ behind "↑ N earlier commits", since EDGE can't open the page scrolled down to the commit. Opened, the ancestors, the commit and the rest of its series share one rail, so someone replying to themselves shows their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot - above them, five at a time with "Show more" under the last. A part of a series with more parts after it + above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything around the commit is muted, and still opens its own page. A deleted reply's own replies open in place, - one level in, five at a time too, since a deleted commit has no page. + one level in, ten at a time too, since a deleted commit has no page. --}} @if ($earlierCount > 0) @include('native.partials.earlier-commits', ['count' => $earlierCount, 'lane' => $earlierLane]) diff --git a/resources/views/native/partials/commit-actions.blade.php b/resources/views/native/partials/commit-actions.blade.php index 5c86cf74..9f0e361d 100644 --- a/resources/views/native/partials/commit-actions.blade.php +++ b/resources/views/native/partials/commit-actions.blade.php @@ -1,29 +1,31 @@ {{-- The action row under a commit, in the web's order. On the left: the star and its count, in pastéis mode the pastel - and its count, Quote, Reply, and in Commit Blue "› N replies" when the row has no thread under it already. On the - right: More. + and its count, Quote and Reply, each with its label. On the right: More. Under the row, on a line of its own, the + replies button: "› N replies" in Commit Blue, or "Hide replies" with the chevron turned down while they show. Share link, Report and Delete live in More, which opens the platform's own menu (a UIMenu on iOS, a dropdown on Android, see CommitMenu for what's in it). Tapping More only opens the menu. - Reply opens the commit with its reply composer focused. In a feed ($expandable) the replies link opens the thread in - place, as on the web; elsewhere it opens the commit with its replies showing. Like the web, someone else's commit - that isn't approved gets no star or Quote. devnull doesn't let you star your own commits, so on those the star is - the count, which opens who starred it (see OpensStargazers), or a faint star until there are any, as on the web. + Reply opens the commit with its reply composer focused. In a feed ($expandable) the replies button opens the replies + in place, as on the web (see Concerns\ExpandsThreads); elsewhere it opens the commit with its replies showing. Like + the web, someone else's commit that isn't approved gets no star or Quote. devnull doesn't let you star your own + commits, so on those the star is the count, which opens who starred it (see OpensStargazers), or a faint star until + there are any, as on the web. Quote opens a sheet to write the quote in, over the commit being quoted (see commit-sheet). The pastel is the web's: the pastel de nata and how many the commit was given, always, even 0. On someone else's published commit it gives one more per tap; on your own, or one that isn't published, it's just the count. It - only shows in pastéis mode ($pasteis). + only shows in pastéis mode ($pasteis). A star you give and a pastel pop as they do on the web (see PopsReactions). A commit with a quote or a reply you started and didn't send marks that button, as the web does with stash@{0} - beside its label. That doesn't fit the row, so here it's a dot after the icon or label, inside the button's 44pt. + beside its label. That doesn't fit the row, so here it's a dot after the label, inside the button. The screen passes the names of the drafts it has kept ($stashed, see App\Devnull\Stash). - Each action is at least 44pt wide and 36pt tall to tap, as Apple asks, with the row pulled in by the extra height so - the commit keeps its rhythm. EDGE makes a pressable's whole box tappable, so the box is the target. Off the log, - "› N replies" sits beside Reply, and both won't fit on a phone with their labels, so Reply is just its icon there. + Each action is at least 44pt wide and 36pt tall to tap, as Apple asks. The row has no negative vertical margins: + Android draws a negative margin as an offset and keeps the space, so the row sat 6pt lower there than on iOS, and + with it everything placed against it. $endDot draws the end of the commit's rail, a lane dot, inside the row at the + rail's x, so it's level with the actions whatever is above or below them (see commit-row-content). A button is the pressable itself, laid out as a row, with no row inside it, since a list builds and measures every node of a row as it scrolls in. More keeps its column: a pressable with a menu draws its content as the menu's @@ -38,7 +40,7 @@ @php($withQuote ??= true) @php($compact ??= false) @php($expandable ??= isset($threads)) -@php($isOpen = $repliesOpen ?? ($expandable && array_key_exists($commit->id, $threads))) +@php($isOpen = $repliesOpen ?? ($expandable && array_key_exists($commit->id, $threads) && ! in_array($commit->id, $closingThreads ?? [], true))) @php($repliesPress = $repliesToggle ?? ($expandable ? "toggleReplies('{$commit->id}')" : "openReplies('{$commit->id}')")) @php($repliesCount ??= $commit->repliesCount) @php($iconSize = $compact ? 14 : 16) @@ -49,17 +51,19 @@ @php($hasReplyStash = in_array('reply-'.$commit->id, $stashed, true)) @php($isOwn = $commit->author->id === $viewer?->id) @php($canQuote = $commit->isApproved() || $isOwn) -@php($hasThread = $expandable && $commit->replyPreview !== null) -@php($showsReplies = $withReplies && ! $hasThread && $repliesCount > 0) +@php($showsReplies = $withReplies && ! $commit->isDeleted() && $repliesCount > 0) +@php($endDot ??= null) +@php($starPop = \App\Devnull\Pop::transform($popping['star-'.$commit->id] ?? null, 'star')) +@php($pastelPop = \App\Devnull\Pop::transform($popping['pastel-'.$commit->id] ?? null, 'pastel')) @php($pasteis ??= app(\App\Devnull\Account::class)->pasteis()) @php($canGivePastel = $pasteis !== null && $viewer !== null && ! $isOwn && $commit->isApproved()) @php($pastelLabel = \App\Devnull\Display::count($commit->pasteisCount, 'pastel', 'pastéis')) @php($pastelSize = $compact ? 18 : 20) @php($starLabel = ($commit->starred ? 'Unstar commit' : 'Star commit').($commit->starsCount > 0 ? ', '.\App\Devnull\Display::count($commit->starsCount, 'star', 'stars') : '')) - + @if ($commit->isApproved() && ! $isOwn && $viewer !== null && ! $commit->isDeleted()) - + @if ($commit->starsCount > 0) {{ \App\Devnull\Display::compactCount($commit->starsCount) }} @endif @@ -77,7 +81,7 @@ @if ($canGivePastel) - + {{ \App\Devnull\Display::compactCount($commit->pasteisCount) }} @elseif ($pasteis !== null) @@ -88,38 +92,25 @@ @endif @if ($withQuote && $canQuote) - + + Quote @if ($hasQuoteStash) - + @endif @endif @if ($withReply) - + - @unless ($showsReplies) - Reply - @endunless + Reply @if ($hasReplyStash) @endif @endif - @if ($showsReplies) - - @if ($isOpen) - - Hide replies - @else - - {{ \App\Devnull\Display::count($repliesCount, 'reply', 'replies') }} - @endif - - @endif - @@ -127,4 +118,16 @@ + + @if ($endDot !== null) + {{-- The end of the rail, at its x: the row starts 8pt into the 64pt gutter's edge, and the dot is 18pt round. --}} + @include('native.partials.rail-node', ['lane' => $endDot, 'nodeRef' => 'end-dot', 'position' => 'absolute top-[9] -left-[33]']) + @endif + +@if ($showsReplies) + + + {{ $isOpen ? 'Hide replies' : \App\Devnull\Display::count($repliesCount, 'reply', 'replies') }} + +@endif diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 553ac21e..8e3c8ea5 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -4,8 +4,11 @@ after it links to them, as the web's "2 more commits in this series" does. $withTail runs the rail on below. In a feed, $continuesNext says whether the author's run goes on in the next row. The rail then runs on, or for a - commit alone in its run ends in a dot of its own, and with replies under the row ($threadBelow) a dashed line in - the lane carries on down to them, as the web draws it. + commit alone in its run ends in a dot of its own, level with the action row, and with replies open under the row + ($threadBelow) a dashed line in the lane carries on down from the dot to them, as the web draws it. The dot is drawn + inside the action row (see commit-actions), so it's level with it whatever the body, images or replies line above + and below. Only the rail's lines are placed from the row's bottom, to meet it, and every height under the action + row is fixed here, so they meet it on both platforms. On a commit page the commit it's about ($focused) is the main thing: a larger name and body in full ink, its time, which tapped says when in your timezone, its hash, and its replies behind a toggle in its action row. The commits around it ($muted) step back: @@ -30,7 +33,11 @@ @php($laterParts = $seriesExpanded ? 0 : $commit->laterSeriesParts()) @php($hasHairline = $hairline && ! $threadBelow) @php($inset = $focused ? 16 : 12) -@php($padding = 'pt-['.$inset.']'.($threadBelow ? '' : ' pb-['.($hasHairline ? $inset + 1 : $inset).']')) +{{-- The action row's 36pt reaches 6pt into the inset below it, as its buttons are taller than their icons. --}} +@php($bottom = $threadBelow ? 0 : $inset - 6 + ($hasHairline ? 1 : 0)) +@php($padding = 'pt-['.$inset.']'.($bottom > 0 ? ' pb-['.$bottom.']' : '')) +@php($repliesLine = ! $commit->isStaged() && ! $commit->isDeleted() && ($focused ? ($replyCount ?? $commit->repliesCount) : $commit->repliesCount) > 0 ? 40 : 0) +@php($dotInActions = $endsWithDot && ! $commit->isStaged()) @php($metaSize = $muted ? 'text-xs' : 'text-[13px]') @@ -86,9 +93,10 @@ 'repliesToggle' => 'toggleReplies', 'repliesOpen' => $repliesShown ?? false, 'repliesCount' => $replyCount ?? $commit->repliesCount, + 'endDot' => $dotInActions ? $commit->lane() : null, ]) @else - @include('native.partials.commit-actions', ['compact' => $muted]) + @include('native.partials.commit-actions', ['compact' => $muted, 'endDot' => $dotInActions ? $commit->lane() : null]) @endif @@ -97,6 +105,10 @@ 'lane' => $commit->lane(), 'tail' => ($inFeed ? $continuesNext || ! $continuesRun : $withTail) ? $commit->lane() : null, 'endsWithDot' => $endsWithDot, + // The middle of the action row, where the rail's end dot is, above the row's bottom: its padding, the replies + // line under the actions (4pt gap and 36pt) and half the row. + 'endDotAt' => $bottom + $repliesLine + 18, + 'dotInActions' => $dotInActions, 'replyTail' => $threadBelow && ! ($inFeed && $continuesNext), 'node' => $continuesRun ? 'dot' : 'avatar', 'avatarSize' => $muted ? 36 : 48, diff --git a/resources/views/native/partials/feed.blade.php b/resources/views/native/partials/feed.blade.php index c85258e0..74d9e1da 100644 --- a/resources/views/native/partials/feed.blade.php +++ b/resources/views/native/partials/feed.blade.php @@ -1,9 +1,9 @@ {{-- A feed's rows from App\Devnull\Timeline: day markers, the last-visit marker, who to follow ($whoToFollow, see - partials/who-to-follow) and commits on the rail. Under a commit hangs its thread, inside its row's hairline, as on - the web: the newest reply devnull previews, with "Show more" when there are others, or the replies opened in place, - with "Show more" to the commit's page when there are more than they show. The commit's rail runs on past them when - its author's run goes on below. + partials/who-to-follow) and commits on the rail. A commit's replies stay hidden until its replies button opens them + in place (see Concerns\ExpandsThreads). Then its thread hangs under it, inside its row's hairline, a page at a time + with "Show more" under the last, and a reply's own replies opened under it one step in (see App\Devnull\ThreadRows). + The commit's rail runs on past them when its author's run goes on below. Given a $rowCache (see App\Devnull\RowCache), commits and replies that haven't changed since the last frame are drawn from it rather than built again. Given a $rowWindow (see App\Devnull\RowWindow), rows far from the screen @@ -42,20 +42,14 @@ @else @php $feedCommit = $row->commit; - $opened = $threads[$feedCommit->id] ?? null; - $threadReplies = $opened ?? ($feedCommit->isDeleted() ? [] : $feedCommit->replyPreview?->replies ?? []); - $feedDraws = $rowWindow?->place($feedIndex, 1 + count($threadReplies)) ?? true; - $hasMoreReplies = $opened === null - ? ! $feedCommit->isDeleted() && ($feedCommit->replyPreview?->hasMore ?? false) - : in_array($feedCommit->id, $threadsWithMore ?? [], true); - $morePress = $opened === null ? "showMoreReplies('{$feedCommit->id}')" : "openReplies('{$feedCommit->id}')"; - $railLane = $row->continuesNext ? $feedCommit->lane() : null; + $threadRows = $feedCommit->isDeleted() ? [] : \App\Devnull\ThreadRows::under($feedCommit, $threads ?? [], $threadCursors ?? [], $threadShown ?? [], $row->continuesNext ? $feedCommit->lane() : null); + $feedDraws = $rowWindow?->place($feedIndex, 1 + count($threadRows)) ?? true; $commitRow = [ 'commit' => $feedCommit, 'previousLane' => $row->previousLane, 'continuesRun' => $row->continuesRun, 'continuesNext' => $row->continuesNext, - 'threadBelow' => $threadReplies !== [], + 'threadBelow' => $threadRows !== [], ]; @endphp @if (! $feedDraws) @@ -70,29 +64,17 @@ $rowCache->include('commit-'.$feedCommit->id, \App\Devnull\RowInputs::for($feedCommit, $rowScope), 'native.partials.commit-row', $commitRow, $rowScope); @endphp @endif - @foreach ($threadReplies as $index => $threadReply) - @php - $replyRow = [ - 'reply' => $threadReply, - 'lane' => $feedCommit->lane(), - 'previousLane' => $index === 0 ? null : $threadReplies[$index - 1]->lane(), - 'hasNext' => ! $loop->last || $hasMoreReplies, - 'railLane' => $railLane, - 'thread' => $feedCommit, - 'more' => $loop->last && $hasMoreReplies ? $morePress : null, - 'last' => $loop->last, - ]; - @endphp + @foreach ($threadRows as $threadRow) @if (! $feedDraws) @php - $rowWindow->placeholder('thread-reply-'.$threadReply->id); + $rowWindow->placeholder($threadRow['key']); @endphp - @elseif ($rowCache === null) - @include('native.partials.thread-reply', $replyRow) + @elseif ($rowCache === null || $threadRow['reply'] === null) + @include($threadRow['partial'], $threadRow['data']) @else @php $rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]); - $rowCache->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope); + $rowCache->include('reply-'.$threadRow['reply']->id, \App\Devnull\RowInputs::for($threadRow['reply'], $rowScope), $threadRow['partial'], $threadRow['data'], $rowScope); @endphp @endif @endforeach diff --git a/resources/views/native/partials/rail.blade.php b/resources/views/native/partials/rail.blade.php index f64abf05..3af56dbd 100644 --- a/resources/views/native/partials/rail.blade.php +++ b/resources/views/native/partials/rail.blade.php @@ -10,7 +10,8 @@ 'tombstone' a dashed Rail Gray ring where a deleted commit's avatar was 'skeleton' a wash disc, for a row still loading null no node; a $previous segment then runs the full height of the row - $endsWithDot stops the $tail 20pt above the bottom at a lane dot, as the web ends a commit that's alone in its run. + $endsWithDot stops the $tail at a lane dot $endDotAt above the bottom (its middle), as the web ends a commit that's + alone in its run. A commit row draws that dot in its action row ($dotInActions), so the rail only runs to it. $replyTail runs a dashed line in the lane on down from the node, or from that dot, to the replies under the row. $avatarSize draws the avatar's ring smaller than its 48pt, centred in the same place. --}} @@ -23,7 +24,8 @@ @php($replyTail ??= false) @php($avatarSize ??= 48) @php($center = 32) -@php($endDot = 20) +@php($endDotAt ??= 20) +@php($dotInActions ??= false) @php($segment = fn (int|string $lane): string => 'bg-theme-'.\App\Devnull\Lane::token($lane)) @if ($node === null) @@ -41,18 +43,19 @@ @endforeach @elseif ($tail !== null) - {{-- `bottom-0`, never `bottom-[0]`: EDGE reads an arbitrary zero inset as no inset, which leaves the tail no height. --}} - + {{-- `bottom-0`, never `bottom-[0]`: EDGE reads an arbitrary zero inset as no inset, which leaves the tail no height. + Ending at a dot, it stops 2pt into the dot's ring, which is in the same lane, so no gap shows. --}} + @endif @if ($replyTail && $endsWithDot) - @include('native.partials.dashed-line', ['position' => 'bottom-0 h-['.$endDot.']', 'left' => 31.5, 'lane' => $lane]) + @include('native.partials.dashed-line', ['position' => 'bottom-0 h-['.($endDotAt - 9).']', 'left' => 31.5, 'lane' => $lane]) @elseif ($replyTail) @include('native.partials.dashed-line', ['position' => 'top-['.($node === 'dot' ? $center - 9 : $center).'] bottom-0', 'left' => 31.5, 'lane' => $lane]) @endif - @if ($endsWithDot && $tail !== null) - @include('native.partials.rail-node', ['lane' => $tail, 'nodeRef' => 'end-dot', 'position' => 'absolute bottom-['.($endDot - 9).'] left-[23]']) + @if ($endsWithDot && $tail !== null && ! $dotInActions) + @include('native.partials.rail-node', ['lane' => $tail, 'nodeRef' => 'end-dot', 'position' => 'absolute bottom-['.($endDotAt - 9).'] left-[23]']) @endif {{-- The node itself takes its place on the rail, or the pressable around it does: no wrapper just to position it. --}} diff --git a/resources/views/native/partials/thread-more-row.blade.php b/resources/views/native/partials/thread-more-row.blade.php new file mode 100644 index 00000000..d35dc8f2 --- /dev/null +++ b/resources/views/native/partials/thread-more-row.blade.php @@ -0,0 +1,33 @@ +{{-- + "Show more" at the foot of a thread opened in a feed (see App\Devnull\ThreadRows), as a list row of its own: a muted + rail dot where the next avatar would be, on the dashed line down from the reply above ($lane), and the words. + Tapped, the thread's next page opens under what's showing. $indent puts it one step in, under a reply's own replies. + + It's 44pt tall, as tall as the list's shortest row, so the list never pads it out under its hairline. The dot sits + in its middle, so the line from above stops at the top of the dot, 13pt down. +--}} +@php($indent ??= 0) +@php($spine ??= null) +@php($railLane ??= null) +@php($faded = in_array('more-'.$threadId, $fadedRows ?? [], true)) + + + + + + + + + + + Show more + + + @if ($railLane !== null) + @include('native.partials.rail', ['previous' => $railLane]) + @endif + @if ($spine !== null) + @include('native.partials.dashed-line', ['position' => 'top-0 bottom-0', 'left' => 75.5, 'lane' => $spine]) + @endif + @include('native.partials.dashed-line', ['position' => 'top-0 h-[13]', 'left' => 75.5 + $indent, 'lane' => $lane]) + diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index 6a1d0a7c..b93ec9b0 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -17,6 +17,11 @@ A commit page draws its replies $muted, smaller and in muted ink, so the commit they answer stays the main thing. A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. + + In a feed a reply's replies button opens them under it ($repliesInPlace, see App\Devnull\ThreadRows); deeper in, + or on a commit page, it opens the reply's page. A feed's thread rows fade in as they open and out as they close + ($fades): drawn see-through and nudged up while they're in $fadedRows (see Concerns\ExpandsThreads), and eased + to where they belong. Only what's beside the rail fades, so the commit's rail running past never blinks. --}} @php($previousLane ??= null) @php($muted ??= false) @@ -26,11 +31,14 @@ @php($tombstones ??= false) @php($more ??= null) @php($avatarLine = 76 + $indent) +@php($repliesInPlace ??= false) +@php($fades ??= false) +@php($faded = $fades && in_array($reply->id, $fadedRows ?? [], true)) @if ($reply->isDeleted()) @php($opened = $tombstones && array_key_exists($reply->id, $tombstoneReplies ?? [])) - + @include('native.partials.dashed-ring', ['size' => 24, 'lane' => \App\Devnull\Lane::Rail]) @@ -67,7 +75,7 @@ - + @include('native.partials.rail-avatar', ['user' => $reply->author, 'lane' => $reply->lane(), 'size' => 24, 'staged' => false]) @@ -84,7 +92,7 @@ @include('native.partials.commit-body', ['size' => $muted ? 'text-sm' : 'text-[15px]']) @include('native.partials.commit-media', ['withEmbeds' => false]) @unless ($reply->isStaged()) - @include('native.partials.commit-actions', ['expandable' => false, 'withQuote' => false, 'compact' => $muted]) + @include('native.partials.commit-actions', ['expandable' => $repliesInPlace, 'withQuote' => false, 'compact' => $muted]) @endunless diff --git a/tests/Feature/Screens/CommitCardTest.php b/tests/Feature/Screens/CommitCardTest.php index 067cf306..966269ce 100644 --- a/tests/Feature/Screens/CommitCardTest.php +++ b/tests/Feature/Screens/CommitCardTest.php @@ -105,10 +105,12 @@ function logOf(array $commits): TestableComponent expect($target($ref))->toMatchArray(['min_width' => 44.0, 'height' => 36.0]); } + // The row takes its full 36pt, with no negative margins above or below, which Android draws as an offset and keeps + // the space of. The padding under it takes back the 6pt its buttons reach past their icons. expect($target('reply-to-c1')['height'])->toBe(36.0) ->and($target('replies-c1')['height'])->toBe(36.0) - // 6pt more above and below than the 24pt the row used to be, so it's pulled in by that much. - ->and(array_slice(nodeByRef($screen, 'actions-c1')['layout']['margin'], 0, 3))->toBe([-6.0, 0.0, -6.0]); + ->and(nodeByRef($screen, 'actions-c1')['layout']['height'])->toBe(36.0) + ->and(array_slice(nodeByRef($screen, 'actions-c1')['layout']['margin'] ?? [0.0, 0.0, 0.0], 0, 3))->toBe([0.0, 0.0, 0.0]); }); it('builds a row from as few views as it can, as a list builds and measures each of them while it scrolls', function () { @@ -122,7 +124,8 @@ function logOf(array $commits): TestableComponent ->and($content['layout']['margin'])->toBe([0.0, 0.0, 0.0, 64.0]) ->and($content['props']['border_b'])->toBe(1.0) ->and(array_column(nodeByRef($screen, 'star-c1')['children'], 'type'))->toBe(['icon', 'text']) - ->and(count(findNodes($row, fn (): bool => true)))->toBeLessThanOrEqual(35); + // Quote's label, and the end of the rail drawn in the action row, came to two more. + ->and(count(findNodes($row, fn (): bool => true)))->toBeLessThanOrEqual(37); }); it("draws a poll you haven't voted on as plain options, with nothing to tap, since the app can't vote yet", function () { diff --git a/tests/Feature/Screens/CommitDetailCacheTest.php b/tests/Feature/Screens/CommitDetailCacheTest.php index b864b63e..145eaedf 100644 --- a/tests/Feature/Screens/CommitDetailCacheTest.php +++ b/tests/Feature/Screens/CommitDetailCacheTest.php @@ -144,6 +144,6 @@ function serveThread(): void $screen->call('load'); - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/d1/replies?limit=5'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/d1/replies?limit=10'); $screen->assertSee('Under a deleted reply'); }); diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index fc0da284..d1e271be 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -431,36 +431,36 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('Hide replies'); }); -it('asks for the replies five at a time, and the next five from Show more', function () { +it('asks for the replies a page at a time, and the next page from Show more', function () { $replies = fn (int ...$numbers): array => array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}"]), $numbers); Http::fake(fn (Request $request) => match (parse_url($request->url(), PHP_URL_PATH)) { '/api/v1/commits/c2/replies' => Http::response(str_contains($request->url(), 'cursor=page2') - ? pageJson($replies(6)) - : pageJson($replies(1, 2, 3, 4, 5), 'page2', 'http://devnull.test/api/v1/commits/c2/replies')), + ? pageJson($replies(11)) + : pageJson($replies(...range(1, 10)), 'page2', 'http://devnull.test/api/v1/commits/c2/replies')), '/api/v1/commits/c2/related' => Http::response(['data' => []]), - default => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'replies_count' => 6]))), + default => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'replies_count' => 11]))), }); $screen = Native::visit('/log/commits/c2', ['replies' => true]) - ->assertSee('Reply 5') - ->assertDontSee('Reply 6') + ->assertSee('Reply 10') + ->assertDontSee('Reply 11') ->tap('more-replies-c2') - ->assertSee('Reply 6') + ->assertSee('Reply 11') ->assertDontSee('Show more'); $asked = collect(Http::recorded())->map(fn (array $sent): string => $sent[0]->url())->filter(fn (string $url): bool => str_contains($url, '/replies')); expect($asked)->toHaveCount(2) - ->and($asked->every(fn (string $url): bool => str_contains($url, 'limit=5')))->toBeTrue(); + ->and($asked->every(fn (string $url): bool => str_contains($url, 'limit=10')))->toBeTrue(); - // Asking again for the first five keeps the one loaded after them. + // Asking again for the first page keeps the one loaded after it. $screen->call('load') - ->assertSee('Reply 6') + ->assertSee('Reply 11') ->assertDontSee('Show more'); }); -it('opens the replies of a deleted reply five at a time too', function () { +it('opens the replies of a deleted reply a page at a time too', function () { $nested = fn (int ...$numbers): array => array_map(fn (int $n): array => replyJson(['id' => "n{$n}", 'parent_id' => 'r1', 'body' => "Nested {$n}"]), $numbers); Http::fake(fn (Request $request) => match (parse_url($request->url(), PHP_URL_PATH)) { @@ -486,7 +486,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('Nested 6') ->assertMissingElement('pressable', $more); - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/r1/replies?cursor=page2&limit=5'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/r1/replies?cursor=page2&limit=10'); }); it('keeps deleted ancestors on the rail as tombstones', function () { diff --git a/tests/Feature/Screens/DraftStashTest.php b/tests/Feature/Screens/DraftStashTest.php index 46baedf4..9a608c78 100644 --- a/tests/Feature/Screens/DraftStashTest.php +++ b/tests/Feature/Screens/DraftStashTest.php @@ -272,7 +272,7 @@ function stashLabel(TestableComponent $screen, string $ref): array $screen = Native::visit('/log', platform: 'ios'); // The dots sit inside the buttons, so the row has the same actions as without them. - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'more-c2']) ->and(array_values(array_filter(childRefs($screen, 'actions-c1'))))->toBe(['star-c1', 'pastel-c1', 'quote-c1', 'reply-to-c1', 'more-c1']) ->and(showsRef($screen, 'quote-stash-c2'))->toBeTrue() ->and(showsRef($screen, 'reply-stash-c2'))->toBeTrue() diff --git a/tests/Feature/Screens/LogTest.php b/tests/Feature/Screens/LogTest.php index c0222442..ffc354b0 100644 --- a/tests/Feature/Screens/LogTest.php +++ b/tests/Feature/Screens/LogTest.php @@ -437,7 +437,7 @@ ], ]); -it('puts the web action row under each commit: the star, Quote, Reply and replies, then More', function () { +it('puts the web action row under each commit: the star, Quote, Reply, then More, with the replies on a line below', function () { $ada = userJson(['id' => 'u2', 'handle' => 'ada']); Http::fake(['devnull.test/*' => Http::response(pageJson([ @@ -458,8 +458,9 @@ // Someone else's pending commit can't be starred or quoted, so the web leaves them off. ->assertMissingElement('pressable', fn (array $node): bool => in_array($node['ref'] ?? null, ['star-c0', 'quote-c0'], true)); - // The web's order: star, Quote, Reply and replies on the left, then More for Share link and Report. - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + // The web's order: star, Quote and Reply on the left, then More for Share link and Report. The replies are under them. + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'more-c2']) + ->and(findNode(nodeByRef($screen, 'actions-c2'), fn (array $node): bool => ($node['ref'] ?? null) === 'replies-c2'))->toBeNull() // Nor can it be reported, so all its menu has is the link. ->and(menuItems($screen, 'more-c0'))->toBe([['share-c0', 'Share link', 'custom:link']]); @@ -475,6 +476,8 @@ ->and($icon('reply-to-c1')['props']['name'] ?? null)->toBe('custom:message-square-reply') ->and($icon('replies-c2')['props']['name'] ?? null)->toBe('custom:chevron-right') ->and($text('replies-c2', '1 reply')['props']['color'] ?? null)->toBe($primary) + ->and($text('quote-c1', 'Quote'))->not->toBeNull() + ->and($text('reply-to-c1', 'Reply'))->not->toBeNull() ->and($icon('more-c1')['props']['name'] ?? null)->toBe('custom:ellipsis') ->and($icon('more-c1')['props']['color'] ?? null)->toBe($muted); @@ -607,7 +610,11 @@ ->assertSee('This commit was deleted.') ->assertSee('Hide replies'); - expect(findNode(nodeByRef($screen, 'replies-c2'), fn (array $node): bool => ($node['type'] ?? null) === 'icon')['props']['name'] ?? null)->toBe('custom:chevron-down'); + // The chevron turns down, which the phone animates. + $chevron = findNode(nodeByRef($screen, 'replies-c2'), fn (array $node): bool => ($node['type'] ?? null) === 'icon'); + expect($chevron['props']['name'] ?? null)->toBe('custom:chevron-right') + ->and($chevron['props']['rotate'] ?? null)->toBe(90.0) + ->and($chevron['props']['animate-duration'] ?? null)->toBeGreaterThan(0.0); // Its replies get the same actions, and open their own page. $screen->tap('star-r1'); @@ -618,24 +625,29 @@ Native::visit('/log')->tap('replies-c2')->tap('thread-reply-r1')->assertNavigatedTo('/log/commits/r1'); }); -it('opens five replies of a thread in place, and the rest on its commit page from Show more', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c2', 'replies_count' => 7])])], - 'GET /api/v1/commits/c2/replies' => [pageJson(array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}"]), range(1, 5)), 'page2', 'http://devnull.test/api/v1/commits/c2/replies')], - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'replies_count' => 7]))], - ]); +it('opens ten replies of a thread in place, and the next ten under them from Show more', function () { + $replies = fn (int $from, int $to): array => array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}"]), range($from, $to)); + + Http::fake(fn (Request $request) => Http::response(match (true) { + str_contains($request->url(), '/log/following') => pageJson([commitJson(['id' => 'c2', 'replies_count' => 13])]), + str_contains($request->url(), 'cursor=page2') => pageJson($replies(11, 13), path: 'http://devnull.test/api/v1/commits/c2/replies'), + default => pageJson($replies(1, 10), 'page2', 'http://devnull.test/api/v1/commits/c2/replies'), + })); - Native::visit('/log', platform: 'ios') + $screen = Native::visit('/log', platform: 'ios') ->tap('replies-c2') ->assertNoNavigation() - ->assertSee('Reply 5') + ->assertSee('Reply 10') + ->assertDontSee('Reply 11') ->tap('more-replies-c2') - ->assertNavigatedTo('/log/commits/c2') - ->follow() - ->assertSet('repliesShown', true) - ->assertSee('Reply 5'); + ->assertNoNavigation() + ->assertSee('Reply 13') + ->assertDontSee('Show more'); + + expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c2']))->toBe(array_map(fn (int $n): string => "r{$n}", range(1, 13))); - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c2/replies?limit=5'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c2/replies?limit=10'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c2/replies?cursor=page2&limit=10'); }); it('closes a thread whose replies have all gone', function () { diff --git a/tests/Feature/Screens/LogThreadTest.php b/tests/Feature/Screens/LogThreadTest.php new file mode 100644 index 00000000..2e6fa5ba --- /dev/null +++ b/tests/Feature/Screens/LogThreadTest.php @@ -0,0 +1,412 @@ + 'http://devnull.test']); + signIn(); +}); + +function grace(): array +{ + return userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace', 'lane' => 4]); +} + +function threadAda(): array +{ + return userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]); +} + +/** + * A commit by Ada in a list, with $replies replies, and the newest one devnull previews under it. + * + * @param array $overrides + * @return array + */ +function threadedJson(int $replies = 1, array $overrides = []): array +{ + return commitJson([ + 'id' => 'c1', + 'body' => 'Ship it?', + 'replies_count' => $replies, + 'author' => threadAda(), + 'reply_preview' => ['data' => [replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()])], 'next_cursor' => null], + ...$overrides, + ]); +} + +/** + * $count replies to $parentId, r1 to rN unless $prefix says otherwise. + * + * @return list> + */ +function repliesJson(string $parentId, int $count, string $prefix = 'r', int $from = 1, array $overrides = []): array +{ + return array_map(fn (int $n): array => replyJson(['id' => "{$prefix}{$n}", 'parent_id' => $parentId, 'body' => "Reply {$prefix}{$n}", 'author' => grace(), ...$overrides]), range($from, $from + $count - 1)); +} + +/** + * The colours of the dashed lines in a node, in order. + * + * @return list + */ +function dashColours(array $node): array +{ + return array_values(array_unique(array_map( + fn (array $line): string => $line['style']['border_color'] ?? '', + findNodes($node, fn (array $child): bool => ($child['props']['border_style'] ?? null) === 1), + ))); +} + +function refNode(array $node, string $ref): ?array +{ + return findNode($node, fn (array $child): bool => ($child['ref'] ?? null) === $ref); +} + +it('keeps replies hidden under a commit, with the replies button on its own line under the actions', function () { + Http::fake(['devnull.test/*' => Http::response(pageJson([threadedJson(3)]))]); + + $screen = Native::visit('/log', platform: 'ios') + ->assertSee('Ship it?') + ->assertDontSee('The newest reply') + ->assertSee('3 replies'); + + expect(refNode(nodeByRef($screen, 'actions-c1'), 'replies-c1'))->toBeNull() + ->and(refNode(nodeByRef($screen, 'commit-c1'), 'replies-c1'))->not->toBeNull() + ->and(findNode($screen->tree(), fn (array $node): bool => str_starts_with($node['ref'] ?? '', 'thread-reply-')))->toBeNull(); +}); + +it('opens the replies under a commit from its replies button, on a dashed elbow in its lane', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(2)])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 2))], + ]); + + $screen = Native::visit('/log', platform: 'ios') + ->tap('replies-c1') + ->assertNoNavigation() + ->assertSee('Reply r1') + ->assertSee('Reply r2') + ->assertSee('Hide replies'); + + $reply = nodeByRef($screen, 'thread-reply-r1'); + $elbow = refNode($reply, 'thread-elbow'); + + expect($elbow)->not->toBeNull() + ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-1')]) + ->and($elbow['props'])->toMatchArray(['border_l' => 1.0, 'border_b' => 1.0, 'border_t' => 0.0, 'border_r' => 0.0, 'radius_bl' => 12.0]) + ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 22.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) + // A reply's own actions: the star and Reply, but no Quote. + ->and(refNode($reply, 'reply-to-r1'))->not->toBeNull() + ->and(refNode($reply, 'quote-r1'))->toBeNull() + // The second hangs on a short link in the lane of the reply above it. + ->and(dashColours(nodeByRef($screen, 'thread-reply-r2')))->toContain(config('native-ui.theme.light.lane-4')) + ->and(refNode(nodeByRef($screen, 'thread-reply-r2'), 'thread-elbow'))->toBeNull() + // The last closes the commit's row with its hairline. + ->and(refNode($screen->tree(), 'thread-end-r2'))->not->toBeNull(); + + $screen->tap('thread-reply-r1')->assertNavigatedTo('/log/commits/r1'); +}); + +it('frames a reply avatar in its own lane without shifting the thread', function (string $platform) { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson()])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 1))], + ]); + + $screen = Native::visit('/log', platform: $platform)->tap('replies-c1'); + $ring = findNode(nodeByRef($screen, 'thread-reply-r1'), fn (array $node): bool => ($node['style']['border_color'] ?? null) === config('native-ui.theme.light.lane-4') + && ($node['layout']['width'] ?? null) === 24.0 + && ($node['layout']['height'] ?? null) === 24.0); + + expect($ring)->not->toBeNull() + ->and($ring['style']['border_radius'])->toBeGreaterThanOrEqual(12.0) + ->and($ring['style'])->toMatchArray(['border_width' => 1.0, 'bg_color' => config('native-ui.theme.light.surface')]) + ->and($ring['children'])->toHaveCount(1) + ->and($ring['children'][0]['layout'])->toMatchArray(['width' => 20.0, 'height' => 20.0]); +})->with(['ios', 'android']); + +it('shows ten replies at a time when devnull sends more, and asks for the next page once they all show', function () { + Http::fake(fn (Request $request) => Http::response(match (true) { + str_contains($request->url(), '/log/following') => pageJson([threadedJson(25)]), + // devnull sends 50 a page whatever limit asks for. + str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 12, from: 14), path: 'http://devnull.test/api/v1/commits/c1/replies'), + default => pageJson(repliesJson('c1', 13), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), + })); + + $screen = Native::visit('/log', platform: 'ios') + ->tap('replies-c1') + ->assertSee('Reply r10') + ->assertDontSee('Reply r11') + ->assertSee('Show more'); + + $screen->tap('more-replies-c1')->assertSee('Reply r13')->assertDontSee('Reply r14')->assertNoNavigation(); + expect(sentTo('GET', 'commits/c1/replies'))->toHaveCount(1); + + $screen->tap('more-replies-c1')->assertSee('Reply r23')->assertDontSee('Reply r24'); + $screen->tap('more-replies-c1')->assertSee('Reply r25')->assertDontSee('Show more'); + + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c1/replies?limit=10'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c1/replies?cursor=page2&limit=10'); +}); + +it("opens a reply's own replies in place, one step in, hanging off the line from its avatar", function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(2)])], + 'GET /api/v1/commits/c1/replies' => [pageJson([ + replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First', 'replies_count' => 12, 'author' => grace()]), + replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second', 'author' => threadAda()]), + ])], + 'GET /api/v1/commits/r1/replies' => [pageJson(repliesJson('r1', 12, 'n', overrides: ['author' => threadAda(), 'replies_count' => 2]))], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1'); + + // Its replies button is under its actions too. + expect(refNode(nodeByRef($screen, 'actions-r1'), 'replies-r1'))->toBeNull() + ->and(refNode(nodeByRef($screen, 'thread-reply-r1'), 'replies-r1'))->not->toBeNull(); + + $screen->tap('replies-r1') + ->assertNoNavigation() + ->assertSee('Reply n10') + ->assertDontSee('Reply n11'); + + // In order: r1, its replies, its Show more, then r2. + $refs = array_values(array_filter(array_map(fn (array $node): ?string => $node['ref'] ?? null, findNodes($screen->tree(), fn (array $node): bool => preg_match('/^(thread-reply-|more-replies-)/', $node['ref'] ?? '') === 1)))); + expect($refs)->toBe(['thread-reply-r1', ...array_map(fn (int $n): string => "thread-reply-n{$n}", range(1, 10)), 'more-replies-r1', 'thread-reply-r2']); + + $nested = nodeByRef($screen, 'thread-reply-n1'); + $elbow = refNode($nested, 'thread-elbow'); + $spine = fn (array $node): ?array => findNode($node, fn (array $line): bool => ($line['props']['border_style'] ?? null) === 1 && ($line['layout']['position'][3] ?? null) === 75.5 && ! isset($line['layout']['height'])); + + // Its elbow leaves the line down from r1's avatar, in r1's lane, and that line runs on past it to r2. + expect($elbow['layout']['position'][3] ?? null)->toBe(75.5) + ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-4')]) + ->and($spine($nested))->not->toBeNull(); + + // One step in, a reply's replies open its page instead. + $screen->tap('replies-n1')->assertNavigatedTo('/log/commits/n1'); + expect($screen->navigationIntent()->data['replies'])->toBeTrue(); +}); + +it("closes a commit's thread, and the replies opened inside it, from Hide replies", function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(1)])], + 'GET /api/v1/commits/c1/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'replies_count' => 1, 'author' => grace()])])], + 'GET /api/v1/commits/r1/replies' => [pageJson(repliesJson('r1', 1, 'n'))], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('replies-r1')->assertSee('Reply n1'); + + $screen->tap('replies-c1')->assertDontSee('Reply n1')->assertSee('1 reply'); + + expect($screen->instance()->threads)->toBe([]) + ->and($screen->instance()->fadedRows)->toBe([]); +}); + +it('fades a thread in as it opens and out as it closes', function () { + holdRefreshes(); + keep('log/following', pageJson([threadedJson(1)])); + keep('commits/c1/replies', pageJson(repliesJson('c1', 1))); + serveApi(fn () => Http::response(pageJson([]))); + + $screen = Native::visit('/log', platform: 'ios'); + $content = fn (): array => nodeByRef($screen, 'thread-reply-r1')['children'][0]['children'][1]; + + // Drawn see-through and nudged up first, with the animation it eases in by. + $screen->tap('replies-c1'); + expect($content()['style']['opacity'] ?? null)->toBe(0.0) + ->and($content()['props']['translate-y'] ?? null)->toBe(-8.0) + ->and($content()['props']['animate-duration'] ?? null)->toBe(220.0); + + finishBeats($screen); + expect($content()['style']['opacity'] ?? 1.0)->toBe(1.0) + ->and($content()['props']['translate-y'] ?? null)->toBe(0.0); + + // Closing fades it out, and it goes once that's done. + $screen->tap('replies-c1')->assertSee('1 reply'); + expect($content()['style']['opacity'] ?? null)->toBe(0.0); + + finishBeats($screen); + expect(refNode($screen->tree(), 'thread-reply-r1'))->toBeNull(); +}); + +it('keeps a thread under a commit you star, and stars a reply in it in place', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(1)])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 1))], + 'POST /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 1, 'starred' => true])]], + 'POST /api/v1/commits/r1/star' => [['data' => commitJson(['id' => 'r1', 'stars_count' => 1, 'starred' => true, 'author' => grace()])]], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('star-c1')->tap('star-r1'); + + $screen->assertSee('Reply r1'); + expect($screen->instance()->commits[0]->starred)->toBeTrue() + ->and($screen->instance()->threads['c1'][0]->starred)->toBeTrue(); +}); + +it('pops a star you give, as the web does, and leaves it as it was', function () { + holdRefreshes(); + keep('log/following', pageJson([commitJson(['id' => 'c1', 'author' => threadAda(), 'starred' => false])])); + serveApi(fn () => Http::response(['data' => commitJson(['id' => 'c1', 'starred' => true, 'stars_count' => 1, 'author' => threadAda()])])); + + $screen = Native::visit('/log', platform: 'ios'); + $star = fn (): array => findNode(nodeByRef($screen, 'star-c1'), fn (array $node): bool => ($node['type'] ?? null) === 'icon'); + + expect($star()['props'])->not->toHaveKey('scale'); + + $screen->tap('star-c1'); + expect($screen->instance()->popping)->toBe(['star-c1' => Pop::Ready]) + ->and($star()['props'])->toMatchArray(['scale' => 1.0, 'animate-duration' => 150.0]); + + finishBeats($screen, 1); + expect($star()['props'])->toMatchArray(['scale' => 1.35, 'rotate' => -12.0]); + + finishBeats($screen, 1); + expect($star()['props'])->toMatchArray(['scale' => 1.0, 'rotate' => 0.0, 'animate-easing' => 'spring']); + + finishBeats($screen); + expect($screen->instance()->popping)->toBe([]) + ->and($star()['props'])->not->toHaveKey('scale'); +}); + +it("doesn't pop a star you take back, as the web doesn't", function () { + holdRefreshes(); + keep('log/following', pageJson([commitJson(['id' => 'c1', 'author' => threadAda(), 'starred' => true, 'stars_count' => 1])])); + serveApi(fn () => Http::response(['data' => commitJson(['id' => 'c1', 'starred' => false, 'stars_count' => 0, 'author' => threadAda()])])); + + $screen = Native::visit('/log', platform: 'ios')->tap('star-c1'); + + expect($screen->instance()->popping)->toBe([]); +}); + +it("runs the commit's rail on past its thread when the author's run carries on below", function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(1, ['id' => 'c2']), commitJson(['id' => 'c1', 'author' => threadAda()])])], + 'GET /api/v1/commits/c2/replies' => [pageJson(repliesJson('c2', 1))], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c2'); + $lane = config('native-ui.theme.light.lane-1'); + $solidRail = fn (array $node): bool => ($node['layout']['width'] ?? null) === 2.0 && ($node['style']['bg_color'] ?? null) === $lane; + + expect(findNode(nodeByRef($screen, 'thread-reply-r1'), $solidRail))->not->toBeNull() + ->and(refNode(nodeByRef($screen, 'commit-c2'), 'end-dot'))->toBeNull() + ->and(railNode($screen, 'commit-c1'))->toBe('dot'); +}); + +it('ends a commit alone in its run with a dot inside its action row, level with the actions', function (string $platform) { + Http::fake(['devnull.test/*' => Http::response(pageJson([ + commitJson(['id' => 'c3', 'author' => threadAda()]), + commitJson(['id' => 'c2', 'author' => threadAda()]), + commitJson(['id' => 'c1', 'author' => grace(), 'replies_count' => 4]), + commitJson(['id' => 'c0', 'author' => threadAda(), 'body' => str_repeat('A long body that wraps. ', 20)]), + ]))]); + + $screen = Native::visit('/log', platform: $platform); + + expect(railNode($screen, 'commit-c3'))->toBe('avatar') + ->and(railNode($screen, 'commit-c2'))->toBe('dot') + ->and(refNode(nodeByRef($screen, 'commit-c3'), 'end-dot'))->toBeNull() + ->and(refNode(nodeByRef($screen, 'commit-c2'), 'end-dot'))->toBeNull(); + + foreach (['c1', 'c0'] as $id) { + $dot = refNode(nodeByRef($screen, "actions-{$id}"), 'end-dot'); + + // Centred in the 36pt row, at the rail's x: the row starts 56pt in, the dot's middle is at 32. + expect($dot)->not->toBeNull() + ->and($dot['layout'])->toMatchArray(['width' => 18.0, 'height' => 18.0]) + ->and($dot['layout']['position'][0])->toBe(9.0) + ->and($dot['layout']['position'][3])->toBe(-33.0) + ->and(nodeByRef($screen, "actions-{$id}")['layout']['height'])->toBe(36.0); + } +})->with(['ios', 'android']); + +it('stops the rail at the end dot, past the replies line, and carries it on in dashes once the replies open', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'author' => grace(), 'replies_count' => 1])])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 1))], + ]); + + $screen = Native::visit('/log', platform: 'ios'); + $lane = config('native-ui.theme.light.lane-4'); + $tail = fn (): ?array => findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['layout']['width'] ?? null) === 2.0 && ($node['style']['bg_color'] ?? null) === $lane); + + // Closed: 7pt padding with the hairline, the replies line (4pt gap and 36pt) and half the action row (18pt) put + // the dot's middle 65pt up, and the rail stops 2pt into its ring, 9pt above that. + expect($tail()['layout']['position'][2])->toBe(72.0); + + $screen->tap('replies-c1'); + + // Open: no padding under the replies line, and the dashes run on from the dot's foot to the row's. + $dashes = findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['props']['border_style'] ?? null) === 1 && ($node['layout']['position'][2] ?? null) === 0.0); + + expect($tail()['layout']['position'][2])->toBe(65.0) + ->and($dashes['layout']['height'] ?? null)->toBe(49.0); +}); + +it('drops a reply that went from an open thread when the log refreshes, and keeps the pages loaded after the first', function () { + $gone = false; + + Http::fake(function (Request $request) use (&$gone) { + return Http::response(match (true) { + str_contains($request->url(), '/log/following') => pageJson([threadedJson(12)]), + str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 2, from: 11), path: 'http://devnull.test/api/v1/commits/c1/replies'), + default => pageJson(array_values(array_filter(repliesJson('c1', 10), fn (array $reply): bool => ! ($gone && $reply['id'] === 'r3'))), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), + }); + }); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('more-replies-c1')->assertSee('Reply r12'); + + $gone = true; + $screen->call('load'); + + expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c1']))->toBe(['r1', 'r2', ...array_map(fn (int $n): string => "r{$n}", range(4, 12))]); +}); + +it('opens a thread at once from the replies kept last time, and refreshes it behind', function () { + holdRefreshes(); + keep('log/following', pageJson([threadedJson(2)])); + keep('commits/c1/replies', pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First kept']), replyJson(['id' => 'r2', 'parent_id' => 'c1'])])); + serveApi(fn () => Http::response(pageJson([]))); + + $screen = Native::visit('/log', platform: 'ios'); + $requests = count(Http::recorded()); + + $screen->tap('replies-c1')->assertSee('First kept'); + + expect(count(Http::recorded()))->toBe($requests) + ->and(refreshesSent($screen))->toBeGreaterThan(1); +}); + +/** + * Runs the Beats a screen is waiting on, $times rounds of them or until none are left. + */ +function finishBeats(TestableComponent $screen, int $times = PHP_INT_MAX): TestableComponent +{ + $done = []; + + for ($round = 0; $round < $times; $round++) { + $beats = array_filter($screen->bridge()->callsTo('AsyncTask.Dispatch'), function (array $call) use (&$done): bool { + $payload = \Native\Mobile\Support\AsyncTaskTransport::readPayload($call['params']['id']); + + return ! isset($done[$call['params']['id']]) && $payload !== null && str_contains($payload, 'App\\Devnull\\Beat'); + }); + + if ($beats === []) { + break; + } + + foreach ($beats as $call) { + $done[$call['params']['id']] = true; + $screen->emitNative(\Native\Mobile\Events\Async\AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); + } + } + + return $screen; +} diff --git a/tests/Feature/Screens/LogWindowTest.php b/tests/Feature/Screens/LogWindowTest.php index 539f02ba..98546ae2 100644 --- a/tests/Feature/Screens/LogWindowTest.php +++ b/tests/Feature/Screens/LogWindowTest.php @@ -7,16 +7,25 @@ config(['devnull.url' => 'http://devnull.test']); signIn(); - // A day marker and 300 commits, with a reply under c220, then the row loading the next page. + // A day marker and 300 commits, with a reply under c220 (opened by visit()), then the row loading the next page. fakeApi([ + 'GET /api/v1/commits/c220/replies' => [pageJson([replyJson(['id' => 'r220', 'parent_id' => 'c220'])])], 'GET /api/v1/log/following' => [pageJson(array_map(fn (int $n): array => commitJson([ 'id' => "c{$n}", 'body' => "Commit {$n}", - ...($n === 220 ? ['replies_count' => 1, 'reply_preview' => ['data' => [replyJson(['id' => 'r220', 'parent_id' => 'c220'])], 'next_cursor' => null]] : []), + ...($n === 220 ? ['replies_count' => 1] : []), ]), range(0, 299)), nextCursor: 'more')], ]); }); +/** + * The log, with c220's reply opened under it. + */ +function visitWithThread(): TestableComponent +{ + return Native::visit('/log')->call('toggleReplies', 'c220'); +} + /** * Each row of the log's list as its ref, or "placeholder". * @@ -41,7 +50,7 @@ function windowRowIds(TestableComponent $screen): array } it('draws the first rows and those near the top, and puts placeholders in the rest', function () { - $rows = windowRows(Native::visit('/log')); + $rows = windowRows(visitWithThread()); // The first 151 rows of the timeline: the day marker and c0 to c149. expect($rows)->toHaveCount(303) @@ -53,7 +62,7 @@ function windowRowIds(TestableComponent $screen): array }); it('draws the rows around the ones on screen as you scroll, each keeping its place in the list', function () { - $screen = Native::visit('/log'); + $screen = visitWithThread(); $ids = windowRowIds($screen); // On screen: c229 to c234, which come after c220 and its reply. Drawn: the first ten rows of the timeline, and @@ -71,21 +80,21 @@ function windowRowIds(TestableComponent $screen): array it('draws more rows above the screen once you scroll back up and stop', function () { // Down to c229, then back up to c199: drawn from 150 above c199 (c49). - $rows = windowRows(Native::visit('/log')->call('showRows', 231, 236)->call('showRows', 200, 205)->call('scrollEnded', 200, 205)); + $rows = windowRows(visitWithThread()->call('showRows', 231, 236)->call('showRows', 200, 205)->call('scrollEnded', 200, 205)); expect($rows[49])->toBe('placeholder') ->and($rows[50])->toBe('commit-c49'); }); it('only asks the log you are on where it is scrolled to, and when it stops', function () { - $screen = Native::visit('/log'); + $screen = visitWithThread(); expect(showingLog($screen)['props'])->toHaveKeys(['on_visible_range', 'on_scroll_end']) ->and(nodeByRef($screen, 'log-latest')['props'] ?? [])->not->toHaveKey('on_visible_range')->not->toHaveKey('on_scroll_end'); }); it('draws the top again when the log goes back to the top of a new list', function () { - $screen = Native::visit('/log')->call('showRows', 231, 236)->call('show', 'following'); + $screen = visitWithThread()->call('showRows', 231, 236)->call('show', 'following'); $rows = windowRows($screen); expect($rows[21])->toBe('commit-c20') diff --git a/tests/Feature/Screens/PasteisTest.php b/tests/Feature/Screens/PasteisTest.php index 6f580305..1e7192fa 100644 --- a/tests/Feature/Screens/PasteisTest.php +++ b/tests/Feature/Screens/PasteisTest.php @@ -85,7 +85,7 @@ function textInside(TestableComponent $screen, string $ref): ?string $screen = Native::visit('/log', platform: 'ios')->assertSee('3 replies'); - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'more-c2', 'end-dot']) ->and(findNode($screen->tree(), fn (array $node): bool => str_starts_with((string) ($node['ref'] ?? ''), 'pastel')))->toBeNull() ->and(findNode($screen->tree(), fn (array $node): bool => ($node['props']['src'] ?? null) === Pasteis::Image))->toBeNull(); @@ -103,7 +103,7 @@ function textInside(TestableComponent $screen, string $ref): ?string $screen = Native::visit('/log', platform: 'ios'); - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'more-c2']) ->and(nodeByRef($screen, 'pastel-c2')['props']['a11y_label'])->toBe('Give a pastel, 3 pastéis, 7 left today') ->and(nodeByRef($screen, 'pastel-c1')['props']['a11y_label'])->toBe('Give a pastel, 0 pastéis, 7 left today') // The web shows the count even when it's 0. @@ -280,11 +280,12 @@ function textInside(TestableComponent $screen, string $ref): ?string pasteisOn(); $reply = commitJson(['id' => 'r1', 'parent_id' => 'c1', 'pasteis_count' => 1, 'author' => pastelAuthor()]); fakeApi([ - 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'replies_count' => 1, 'author' => pastelAuthor(), 'reply_preview' => ['data' => [$reply], 'next_cursor' => null]])])], + 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'replies_count' => 1, 'author' => pastelAuthor()])])], + 'GET /api/v1/commits/c1/replies' => [pageJson([$reply])], 'POST /api/v1/commits/r1/pasteis' => [pastelAnswer([...$reply, 'pasteis_count' => 2], remaining: 9)], ]); - $screen = Native::visit('/log', platform: 'ios')->tap('pastel-r1'); + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('pastel-r1'); expect(pasteisSent())->toBe(['r1']) ->and(textInside($screen, 'pastel-r1'))->toBe('2'); diff --git a/tests/Feature/Screens/ProfileTest.php b/tests/Feature/Screens/ProfileTest.php index eea451e5..02e88cbb 100644 --- a/tests/Feature/Screens/ProfileTest.php +++ b/tests/Feature/Screens/ProfileTest.php @@ -58,7 +58,7 @@ function adaCommitJson(array $overrides = []): array ->assertSee("That's @ada's root commit."); }); -it("shows Reply as just its icon beside a commit's replies, so the row still fits a phone", function () { +it("labels Reply, with a commit's replies on their own line under the actions", function () { fakeApi([ 'GET /api/v1/users/ada' => [profileJson()], 'GET /api/v1/users/ada/commits' => [pageJson([ @@ -71,8 +71,9 @@ function adaCommitJson(array $overrides = []): array $labels = fn (string $ref): array => findNodes(nodeByRef($screen, $ref), fn (array $node): bool => ($node['type'] ?? null) === 'text'); expect(nodeByRef($screen, 'reply-to-c1')['props']['a11y_label'])->toBe('Reply') - ->and($labels('reply-to-c1'))->toBe([]) - ->and($labels('reply-to-c2'))->toHaveCount(1); + ->and($labels('reply-to-c1'))->toHaveCount(1) + ->and($labels('reply-to-c2'))->toHaveCount(1) + ->and(findNode(nodeByRef($screen, 'actions-c1'), fn (array $node): bool => ($node['ref'] ?? null) === 'replies-c1'))->toBeNull(); }); it('lists what GitHub says about them under the bio, as the web does', function () { diff --git a/tests/Feature/Screens/ReplyPreviewTest.php b/tests/Feature/Screens/ReplyPreviewTest.php deleted file mode 100644 index ca38f205..00000000 --- a/tests/Feature/Screens/ReplyPreviewTest.php +++ /dev/null @@ -1,252 +0,0 @@ - 'http://devnull.test']); - signIn(); -}); - -function grace(): array -{ - return userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace', 'lane' => 4]); -} - -/** - * A commit by Ada in a list, with the newest reply devnull previews under it. - * - * @param list> $replies - * @param array $overrides - * @return array - */ -function previewedJson(array $replies, bool $more = false, array $overrides = []): array -{ - return commitJson([ - 'id' => 'c1', - 'body' => 'Ship it?', - 'replies_count' => count($replies) + ($more ? 2 : 0), - 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]), - 'reply_preview' => ['data' => $replies, 'next_cursor' => $more ? 'eyJjcmVhdGVkX2F0IjoiMjAyNiJ9' : null], - ...$overrides, - ]); -} - -/** - * The colours of the dashed lines in a node, in order. - * - * @return list - */ -function dashColours(array $node): array -{ - return array_values(array_unique(array_map( - fn (array $line): string => $line['style']['border_color'] ?? '', - findNodes($node, fn (array $child): bool => ($child['props']['border_style'] ?? null) === 1), - ))); -} - -it('hangs the newest reply under a commit, on a dashed elbow in its lane, instead of a replies toggle', function () { - Http::fake(['devnull.test/*' => Http::response(pageJson([previewedJson([ - replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()]), - ])]))]); - - $screen = Native::visit('/log', platform: 'ios') - ->assertSee('Ship it?') - ->assertSee('The newest reply') - ->assertDontSee('1 reply') - ->assertDontSee('Show more'); - - $reply = nodeByRef($screen, 'thread-reply-r9'); - $elbow = findNode($reply, fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow'); - - expect($elbow)->not->toBeNull() - ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-1')]) - // One dashed border down from the rail, round a 12pt corner and across to 1pt short of the avatar. - ->and($elbow['props'])->toMatchArray(['border_l' => 1.0, 'border_b' => 1.0, 'border_t' => 0.0, 'border_r' => 0.0, 'radius_bl' => 12.0]) - ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 22.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) - // A reply's own actions: the star and Reply, but no Quote. - ->and(findNode($reply, fn (array $node): bool => ($node['ref'] ?? null) === 'reply-to-r9'))->not->toBeNull() - ->and(findNode($reply, fn (array $node): bool => ($node['ref'] ?? null) === 'quote-r9'))->toBeNull(); - - // The commit ends its rail in a dot, and the dashes carry on from it to the reply. - expect(findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['ref'] ?? null) === 'end-dot'))->not->toBeNull(); - - $screen->tap('thread-reply-r9')->assertNavigatedTo('/log/commits/r9'); -}); - -it('frames a reply avatar in its own lane without shifting the thread', function (string $platform) { - Http::fake(['devnull.test/*' => Http::response(pageJson([previewedJson([ - replyJson(['id' => 'r9', 'parent_id' => 'c1', 'author' => grace()]), - ])]))]); - - $screen = Native::visit('/log', platform: $platform); - $reply = nodeByRef($screen, 'thread-reply-r9'); - $ring = findNode($reply, fn (array $node): bool => ($node['style']['border_color'] ?? null) === config('native-ui.theme.light.lane-4') - && ($node['layout']['width'] ?? null) === 24.0 - && ($node['layout']['height'] ?? null) === 24.0); - - expect($ring)->not->toBeNull() - ->and($ring['style']['border_radius'])->toBeGreaterThanOrEqual(12.0) - ->and($ring['style'])->toMatchArray(['border_width' => 1.0, 'bg_color' => config('native-ui.theme.light.surface')]) - ->and($ring['children'])->toHaveCount(1) - ->and($ring['children'][0]['layout'])->toMatchArray(['width' => 20.0, 'height' => 20.0]); -})->with(['ios', 'android']); - -it('opens the rest of the thread in place, newest first, from Show more', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([previewedJson([replyJson(['id' => 'r3', 'parent_id' => 'c1', 'body' => 'Third', 'author' => grace()])], more: true)])], - 'GET /api/v1/commits/c1/replies' => [pageJson([ - replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First']), - replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second', 'author' => grace()]), - replyJson(['id' => 'r3', 'parent_id' => 'c1', 'body' => 'Third', 'author' => grace()]), - ])], - ]); - - $screen = Native::visit('/log', platform: 'ios') - ->assertSee('Third') - ->assertDontSee('Second') - ->assertSee('Show more'); - - $screen->tap('more-replies-c1') - ->assertNoNavigation() - ->assertSee('First') - ->assertSee('Second') - ->assertDontSee('Show more'); - - expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c1']))->toBe(['r3', 'r2', 'r1']); - - // Each reply after the first hangs on a short link in the lane of the reply above it. - expect(dashColours(nodeByRef($screen, 'thread-reply-r2')))->toContain(config('native-ui.theme.light.lane-4')) - ->and(findNode(nodeByRef($screen, 'thread-reply-r2'), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow'))->toBeNull(); - - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c1/replies?limit=5'); -}); - -it('opens Show more at once from the thread kept last time, and refreshes it behind', function () { - holdRefreshes(); - keep('log/following', pageJson([previewedJson([replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second'])], more: true)])); - keep('commits/c1/replies', pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First kept']), replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second'])])); - serveApi(fn () => Http::response(pageJson([]))); - - $screen = Native::visit('/log', platform: 'ios'); - $requests = count(Http::recorded()); - - $screen->tap('more-replies-c1')->assertSee('First kept'); - - expect(count(Http::recorded()))->toBe($requests) - ->and(refreshesSent($screen))->toBeGreaterThan(1); -}); - -it('opens the commit with its replies showing instead when its thread is longer than a page', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([previewedJson([replyJson(['id' => 'r60', 'parent_id' => 'c1'])], more: true)])], - 'GET /api/v1/commits/c1/replies' => [pageJson(array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c1']), range(1, 5)), 'page2')], - 'GET /api/v1/commits/c1' => [commitPageJson(previewedJson([], more: true))], - ]); - - Native::visit('/log', platform: 'ios') - ->tap('more-replies-c1') - ->assertNavigatedTo('/log/commits/c1') - ->follow() - ->assertSet('repliesShown', true); -}); - -it('stars a reply in the thread in place', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([previewedJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'author' => grace(), 'stars_count' => 0])])])], - 'POST /api/v1/commits/r1/star' => [['data' => commitJson(['id' => 'r1', 'stars_count' => 1, 'starred' => true, 'author' => grace()])]], - ]); - - $screen = Native::visit('/log')->tap('star-r1'); - - expect($screen->instance()->commits[0]->replyPreview->replies[0]->starred)->toBeTrue() - ->and($screen->instance()->commits[0]->replyPreview->replies[0]->starsCount)->toBe(1); -}); - -it('keeps the thread under a commit you star below a quote of it, and unstars it on the next tap', function () { - $quoted = previewedJson([]); - unset($quoted['reply_preview']); - - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([ - commitJson(['id' => 'q1', 'body' => 'Look at this', 'quoted_commit_id' => 'c1', 'quoted_commit' => $quoted]), - previewedJson([replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()])]), - ])], - 'POST /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 1, 'starred' => true])]], - 'DELETE /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 0, 'starred' => false])]], - ]); - $screen = Native::visit('/log', platform: 'ios'); - - $screen->tap('star-c1')->assertSee('The newest reply'); - $starred = $screen->instance()->commits[1]->starred; - $screen->tap('star-c1'); - - expect($starred)->toBeTrue() - ->and($screen->instance()->commits[1]->starred)->toBeFalse() - ->and(sentTo('DELETE', 'commits/c1/star'))->toHaveCount(1); -}); - -it('keeps the thread under a commit you star that is also the reply previewed under its parent', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([])], - 'GET /api/v1/log/latest' => [pageJson([ - previewedJson([replyJson(['id' => 'c1', 'parent_id' => 'p1', 'body' => 'Ship it?', 'replies_count' => 1, 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1])])], overrides: ['id' => 'p1', 'body' => 'Should we ship?']), - previewedJson([replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()])], overrides: ['parent_id' => 'p1']), - ], path: 'http://devnull.test/api/v1/log/latest')], - 'POST /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 1, 'starred' => true])]], - ]); - $screen = tapLogTab(Native::visit('/log', platform: 'ios'), 'latest'); - - $screen->call('toggleStar', 'c1'); - - $screen->assertSee('The newest reply'); - expect($screen->instance()->commits[0]->replyPreview->replies[0]->starred)->toBeTrue() - ->and($screen->instance()->commits[1]->starred)->toBeTrue(); -}); - -it("runs the commit's rail on past its thread when the author's run carries on below", function () { - $ada = userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]); - - Http::fake(['devnull.test/*' => Http::response(pageJson([ - previewedJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'author' => grace()])], overrides: ['id' => 'c2', 'author' => $ada]), - commitJson(['id' => 'c1', 'author' => $ada]), - ]))]); - - $screen = Native::visit('/log', platform: 'ios'); - $lane = config('native-ui.theme.light.lane-1'); - $solidRail = fn (array $node): bool => ($node['layout']['width'] ?? null) === 2.0 && ($node['style']['bg_color'] ?? null) === $lane; - - expect(findNode(nodeByRef($screen, 'thread-reply-r1'), $solidRail))->not->toBeNull() - ->and(findNode(nodeByRef($screen, 'commit-c2'), fn (array $node): bool => ($node['ref'] ?? null) === 'end-dot'))->toBeNull() - ->and(railNode($screen, 'commit-c1'))->toBe('dot'); -}); - -it('ends a commit alone in its run with a dot, and joins a run of one author', function () { - $ada = userJson(['id' => 'u2', 'handle' => 'ada', 'lane' => 1]); - - Http::fake(['devnull.test/*' => Http::response(pageJson([ - commitJson(['id' => 'c3', 'author' => $ada]), - commitJson(['id' => 'c2', 'author' => $ada]), - commitJson(['id' => 'c1', 'author' => grace()]), - ]))]); - - $screen = Native::visit('/log', platform: 'ios'); - $endDot = fn (string $ref): bool => findNode(nodeByRef($screen, $ref), fn (array $node): bool => ($node['ref'] ?? null) === 'end-dot') !== null; - - expect(railNode($screen, 'commit-c3'))->toBe('avatar') - ->and(railNode($screen, 'commit-c2'))->toBe('dot') - ->and($endDot('commit-c3'))->toBeFalse() - ->and($endDot('commit-c2'))->toBeFalse() - ->and($endDot('commit-c1'))->toBeTrue(); -}); - -it("closes a commit's row in the log with a hairline after its last previewed reply", function () { - Http::fake(['devnull.test/*' => Http::response(pageJson([previewedJson([ - replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()]), - ])]))]); - - $screen = Native::visit('/log', platform: 'ios'); - - expect(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-end-r9'))->not->toBeNull(); -}); From f6c54e27e789c786b15d633fe993d03450d02d65 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 16 Nov 2026 02:00:07 +0000 Subject: [PATCH 02/30] Move the commit reply bar onto the Remotes composer box The reply bar is now the same rounded box as the Remotes composer: the field across the top, and under it the expand button on the left and a round send button in your colour on the right. The bar is Liquid Glass on iOS and the solid surface on Android. The text Reply button is gone. The expand button no longer opens the composer sheet. Presenting a sheet takes the keyboard down and puts it back up on both platforms, however early its field asks for focus, so the box grows in place instead (8 lines, up to 12) and the keyboard stays where it is. Grown, the box gets a photos and preview button that opens the sheet as before. Photos attached there show as a count in the box. A restored draft's stash@{0} and drop sit under the box, since the grown row has no room for them. A reply long enough to be folded in feeds now says "folded in feeds" in small muted text, here and in the sheet. The FoldVertical icon read as a button that did nothing, so it's gone. Related commits start closed under a header with their count. Tapping it fades them in one after another and turns the chevron; tapping again fades them out, then takes them out. It uses the Beat task from the Log threads work (PR 179), copied as is so the two branches merge cleanly. The old composer-plate partial had no users left, so it's deleted. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Beat.php | 34 +++++ app/Devnull/Display.php | 40 +++--- app/Icons/Lucide.php | 4 +- app/NativeComponents/CommitDetail.php | 91 ++++++++++++- resources/icons/fold-vertical.svg | 1 - resources/icons/minimize-2.svg | 1 + .../views/native/commit-detail.blade.php | 85 ++++++------ .../native/partials/body-counter.blade.php | 15 +-- .../native/partials/composer-plate.blade.php | 24 ---- .../native/partials/composer-tool.blade.php | 11 +- .../native/partials/related-commits.blade.php | 50 ++++--- .../native/partials/reply-field.blade.php | 12 +- tests/Feature/Screens/CommitDetailTest.php | 124 +++++++++++++----- tests/Feature/Screens/ComposerPhotosTest.php | 12 +- tests/Feature/Screens/DraftStashTest.php | 5 +- tests/Feature/Screens/LaneButtonsTest.php | 29 ++-- tests/Feature/Screens/RelatedCommitsTest.php | 119 +++++++++++++++-- 17 files changed, 482 insertions(+), 175 deletions(-) create mode 100644 app/Devnull/Beat.php delete mode 100644 resources/icons/fold-vertical.svg create mode 100644 resources/icons/minimize-2.svg delete mode 100644 resources/views/native/partials/composer-plate.blade.php diff --git a/app/Devnull/Beat.php b/app/Devnull/Beat.php new file mode 100644 index 00000000..c6598cfe --- /dev/null +++ b/app/Devnull/Beat.php @@ -0,0 +1,34 @@ +runningUnitTests()) { + usleep(max(0, $milliseconds) * 1000); + } + + return true; + } +} diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index d8da90be..fbe4a1bd 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -12,19 +12,22 @@ final class Display { /** - * The commit page's reply bar with one line of draft: its hairline, the - * field and the padding around them, as drawn on an iPhone. + * How much a line of draft adds to a composer bar's field. */ - public const int ReplyBarHeight = 53; - public const int ReplyBarLineHeight = 21; public const int ReplyBarMaxLines = 5; - public const int ReplyBarCharactersPerLine = 34; + /** + * The reply box on a commit's page grown by its expand button: it starts this many lines tall, and grows to + * ExpandedReplyMaxLines. + */ + public const int ExpandedReplyMinLines = 8; + + public const int ExpandedReplyMaxLines = 12; /** - * The row under the reply bar's field that marks a restored draft (see partials/stash-label) and counts its photos. + * The row under the reply box that marks a restored draft (see partials/stash-label). */ public const int ReplyBarStashLabelHeight = 28; @@ -35,8 +38,7 @@ final class Display public const int ComposerBoxBarHeight = 97; /** - * About how many characters fit on a line of the box's field. It runs the width of the box, so more fit than - * beside the reply bar's tools and button. + * About how many characters fit on a line of the box's field, which runs the width of the box. */ public const int ComposerBoxCharactersPerLine = 46; @@ -228,16 +230,22 @@ public static function maskedKey(string $openSsh): string * How far a commit page has to scroll past its last reply to clear the * reply bar. A pushed screen is drawn under its bottom bar and the home * indicator, with no inset for either, so the page pads its own end: the - * bar as the draft grows to its five lines, and the indicator below it. - * With the keyboard up the bar sits on the keyboard instead, which only - * leaves a little more room. A restored draft, or one with photos, adds - * the row under the field ($draftRow). + * bar (partials/composer-box) as the draft grows to its five lines, and + * the indicator below it. With the keyboard up the bar sits on the + * keyboard instead, which only leaves a little more room. Grown by its + * expand button ($expanded), the box is ExpandedReplyMinLines tall to + * start with. A restored draft adds the row under the box that marks it + * ($restored), and a link too long for devnull the line that says so. */ - public static function replyBarClearance(string $draft, bool $draftRow = false): int + public static function replyBarClearance(string $draft, bool $expanded = false, bool $restored = false): int { - return self::ReplyBarHeight - + (min(self::ReplyBarMaxLines, self::lineCount($draft, self::ReplyBarCharactersPerLine)) - 1) * self::ReplyBarLineHeight - + ($draftRow ? self::ReplyBarStashLabelHeight : 0) + $lines = $expanded + ? max(self::ExpandedReplyMinLines, min(self::ExpandedReplyMaxLines, self::lineCount($draft, self::ComposerBoxCharactersPerLine))) + : null; + + return self::ComposerBoxBarHeight + + ($lines === null ? self::composerBoxGrowth($draft) : ($lines - 1) * self::ReplyBarLineHeight) + + ($restored ? self::ReplyBarStashLabelHeight : 0) + (CommitBody::hasOversizedUrl($draft) ? 3 * self::ReplyBarLineHeight : 0) + self::HomeIndicatorHeight; } diff --git a/app/Icons/Lucide.php b/app/Icons/Lucide.php index b6ea5bb9..b6e5c0e1 100644 --- a/app/Icons/Lucide.php +++ b/app/Icons/Lucide.php @@ -49,7 +49,6 @@ enum Lucide case UserPlus; case UserCheck; case AtSign; - case FoldVertical; case Award; case Ellipsis; case Flag; @@ -75,6 +74,7 @@ enum Lucide case EyeOff; case Plus; case Maximize2; + case Minimize2; case Vibrate; // The achievement badges, named as devnull names their icons (see forBadge()). @@ -189,7 +189,6 @@ public function custom(bool $filled = false): string self::UserPlus => 'user-plus', self::UserCheck => 'user-check', self::AtSign => 'at-sign', - self::FoldVertical => 'fold-vertical', self::Award => 'award', self::Ellipsis => 'ellipsis', self::Flag => 'flag', @@ -216,6 +215,7 @@ public function custom(bool $filled = false): string self::EyeOff => 'eye-off', self::Plus => 'plus', self::Maximize2 => 'maximize-2', + self::Minimize2 => 'minimize-2', self::Vibrate => 'vibrate', self::Terminal => 'terminal', self::FileCode => 'file-code', diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index f20c88a3..0647820f 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -3,6 +3,7 @@ namespace App\NativeComponents; use App\Devnull\Account; +use App\Devnull\Beat; use App\Devnull\Client; use App\Devnull\Data\Commit; use App\Devnull\Data\CommitThread; @@ -50,11 +51,18 @@ * leaving the page keeps it, and it's in the reply bar again, marked as * restored, when you come back to the commit. * - * The reply bar has no room for photos or a preview, so its expand button - * opens the reply in the composer sheet, which has them (see replyInSheet()). + * The reply bar's expand button gives the reply more room where it is: the + * box grows taller over the page, with the same field in it, so the keyboard + * stays up (see toggleReplyExpanded()). A sheet can't do that: presenting + * one takes the keyboard down and puts it back up on both platforms, however + * soon its field takes focus. Grown, the box has the photos and preview + * button, which opens the reply in the composer sheet (see replyInSheet()). * The draft goes with it, and back to the bar if the sheet closes unsent. - * Photos left in it show as a count under the bar's field, which opens the - * sheet on them, and Reply in the bar sends them with the text. + * Photos left in it show as a count in the box, which opens the sheet on + * them, and Reply in the bar sends them with the text. + * + * Related commits wait under a header with their count, closed, and open + * in place when it's tapped (see toggleRelated()). * * A reply goes at once: the bar empties and the reply shows staged under the * commit while it goes to devnull from the outbox (see SyncsOutbox), then the @@ -101,6 +109,36 @@ class CommitDetail extends NativeComponent */ public array $related = []; + /** + * Whether the reply box has grown to give the reply more room. + */ + public bool $replyExpanded = false; + + /** + * Whether the related commits show under their header. + */ + public bool $relatedShown = false; + + /** + * Whether the related commits are drawn see-through: about to fade in, or fading out on their way to closing. + */ + public bool $relatedFaded = false; + + /** + * Whether the related commits are fading out, still drawn until they have. + */ + public bool $relatedClosing = false; + + /** + * How long the related commits take to fade in or out, in milliseconds, as a Log thread's replies do. + */ + public const int RelatedFade = 220; + + /** + * How much later each related commit starts fading in than the one above it, in milliseconds. + */ + public const int RelatedStagger = 40; + /** * Whether the replies have been kept or fetched. Until then they show as loading. */ @@ -278,6 +316,50 @@ public function toggleReplies(): void $this->repliesShown = ! $this->repliesShown; } + /** + * The expand button in the reply box: the box grows taller where it is, + * the same field in it, so the keyboard stays where it was, and again it + * shrinks back. + */ + public function toggleReplyExpanded(): void + { + $this->replyExpanded = ! $this->replyExpanded; + } + + /** + * The related commits' header opens them, and closes them again. EDGE + * can't animate a node coming into the page or leaving it, so they're + * drawn see-through first and shown once a Beat comes back, which each + * row fades and slides to, a little after the one above. Closing fades + * them out the same way, then takes them out. + */ + public function toggleRelated(): void + { + if ($this->relatedClosing) { + return; + } + + if (! $this->relatedShown) { + $this->relatedShown = true; + $this->relatedFaded = true; + $shown = fn () => $this->relatedFaded = false; + + Beat::dispatch(Beat::Step)->finished($shown)->failed($shown); + + return; + } + + $this->relatedFaded = true; + $this->relatedClosing = true; + $closed = function (): void { + $this->relatedShown = false; + $this->relatedFaded = false; + $this->relatedClosing = false; + }; + + Beat::dispatch(self::RelatedFade)->finished($closed)->failed($closed); + } + /** * A deleted reply has no page of its own, so its replies open in place below it. */ @@ -357,6 +439,7 @@ public function sendReply(): void $this->reply = ''; $this->replyImages = []; + $this->replyExpanded = false; $this->forgetMention('reply'); $this->updatedReply(); $this->repliesShown = true; diff --git a/resources/icons/fold-vertical.svg b/resources/icons/fold-vertical.svg deleted file mode 100644 index f24194ca..00000000 --- a/resources/icons/fold-vertical.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/icons/minimize-2.svg b/resources/icons/minimize-2.svg new file mode 100644 index 00000000..f3cb0e4b --- /dev/null +++ b/resources/icons/minimize-2.svg @@ -0,0 +1 @@ + diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index c633a3d0..54930e8e 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -108,68 +108,73 @@ Display::replyBarClearance): the last reply and its actions end above the bar, keyboard up or down. --}} @if ($commit) - + @endif @if ($commit) {{-- - The bar is painted from its first child's background: native:bottom-bar takes no classes of its own, so - the surface and the hairline above it belong to this column, or the replies show through. On iOS the bar - is bare and the field is a Liquid Glass plate instead, the way the HIG floats controls over content; the - hairline stays as a clear 1pt so the bar keeps the height Display::ReplyBarHeight counts on. + The reply bar, drawn as the Remotes composer is: one rounded box with the field across the top and a row + under it with the tools on the left and the round send button on the right (see partials/composer-box). The + bar is Liquid Glass tinted with the surface on iOS, so the thread scrolling under it blurs, and the solid + surface with a hairline on Android. native:bottom-bar takes no classes of its own, so the bar is painted + from this column. - The expand button opens the reply in the composer sheet, which has the photos and preview the bar has no - room for. It sits where partials/composer-plate puts a composer's tools: inside the plate on iOS, ahead of - the field on Android. + The expand button grows the box where it is, the same field in it, so the keyboard stays up, and shrinks + it back. A sheet can't take the reply over with the keyboard up: presenting one takes the keyboard down + and back up on both platforms. Grown, the box also has the button for photos and a preview, which opens + the reply in the composer sheet, and once the sheet has put photos on the draft, their count opens the + sheet on them. Beside the send button, how long the reply is. A reply that came back when you returned to + the commit has the web's stash@{0} and drop under the box, on a row of its own, since the box's row has no + room left for it once it has grown. --}} - + {{-- - The people to mention keep a slot above the field, empty and no height when there's no one, so the - field's row never moves. Android rebuilds a row that moves among its siblings, field and all, which - drops the keyboard. + The people to mention keep a slot above the box, empty and 0.1pt tall when there's no one, so the + box's row never moves. Android rebuilds a row that moves among its siblings, field and all, which + drops the keyboard. On iOS an empty slot would otherwise take 10pt of the bar, and EDGE drops a + height of 0. --}} @php($mentioning = ($mention['field'] ?? null) === 'reply' && ($mentionPeople !== [] || $mentionOrganizations !== [])) - + @include('native.partials.mention-suggestions', ['field' => 'reply', 'label' => 'Mention a developer']) - - @include('native.partials.composer-plate', [ + + @php($photoCount = $replyImages === [] ? null : \App\Devnull\Display::count(count($replyImages), 'photo', 'photos')) + @include('native.partials.composer-box', [ 'ref' => 'reply', 'field' => 'native.partials.reply-field', - 'tools' => [['ref' => 'reply-expand', 'icon' => \App\Icons\Lucide::Maximize2, 'label' => 'Reply with photos or a preview', 'press' => "replyInSheet('{$commit->id}')"]], + 'tools' => [ + $replyExpanded + ? ['ref' => 'reply-expand', 'icon' => \App\Icons\Lucide::Minimize2, 'label' => 'Give the reply less room', 'press' => 'toggleReplyExpanded'] + : ['ref' => 'reply-expand', 'icon' => \App\Icons\Lucide::Maximize2, 'label' => 'Give the reply more room', 'press' => 'toggleReplyExpanded'], + ...($replyExpanded ? [ + ['ref' => 'reply-attach', 'icon' => \App\Icons\Lucide::ImagePlus, 'label' => 'Reply with photos or a preview', 'press' => "replyInSheet('{$commit->id}')"], + ] : []), + ...($photoCount === null ? [] : [ + ['ref' => 'reply-photos', 'icon' => \App\Icons\Lucide::ImagePlus, 'text' => $photoCount, 'label' => $photoCount.' attached', 'hint' => 'Opens the reply with its photos', 'press' => "replyInSheet('{$commit->id}')"], + ]), + ], + 'counter' => ['native.partials.body-counter', ['body' => $reply, 'ref' => 'reply-budget']], + 'send' => [ + 'ref' => 'send-reply', + 'label' => 'Reply', + 'press' => 'sendReply', + 'disabled' => ! \App\Devnull\Data\Draft::canCommit($reply, $replyImages), + ], ]) - @include('native.partials.body-counter', ['body' => $reply, 'ref' => 'reply-budget']) - Reply + @if ($replyRestored) + + @include('native.partials.stash-label', ['ref' => 'reply-stash', 'drop' => 'dropReplyStash', 'size' => 'text-xs']) + + @endif @if (\App\Devnull\Data\CommitBody::hasOversizedUrl($reply)) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. @endif - {{-- - A reply stashed when you left the commit comes back with the web's stash@{0} and drop under it. - Photos attached in the sheet show as a count on the left, which opens the sheet on them, and Reply - sends them. - --}} - @if ($replyRestored || $replyImages !== []) - - @if ($replyImages !== []) - @php($photoCount = \App\Devnull\Display::count(count($replyImages), 'photo', 'photos')) - - - - {{ $photoCount }} - - - - @endif - @if ($replyRestored) - @include('native.partials.stash-label', ['ref' => 'reply-stash', 'drop' => 'dropReplyStash', 'size' => 'text-xs']) - @endif - - @endif @endif diff --git a/resources/views/native/partials/body-counter.blade.php b/resources/views/native/partials/body-counter.blade.php index 6bdd9736..86f4db9f 100644 --- a/resources/views/native/partials/body-counter.blade.php +++ b/resources/views/native/partials/body-counter.blade.php @@ -1,21 +1,14 @@ {{-- The web's BodyCounter, next to Commit or Reply: nothing until 200 characters are left, then the count in mono, amber - from 20 and Rm Red at none. Before that, a body long enough to be folded in lists says so. - - The composer sheet and the reply bar show the fold icon. In partials/composer-box ($foldHint), where the row has - room for words, it says "folded in feeds" in small muted text instead: people read the icon alone as a button they - couldn't work out, and text that isn't a button can't be mistaken for one. + from 20 and Rm Red at none. Before that, a body long enough to be folded in lists says "folded in feeds" in small + muted text. It used to be the FoldVertical icon, which people read as a button they couldn't work out, and text + that isn't a button can't be mistaken for one. --}} -@php($foldHint ??= false) @php($remaining = \App\Devnull\Data\Commit::MaxLength - (($literal ?? false) ? mb_strlen(\App\Devnull\Data\CommitBody::normalize($body)) : \App\Devnull\Data\CommitBody::characterCount($body))) @php($isCounting = $remaining <= \App\Devnull\Data\Commit::CountFrom) @php($foldExplained = 'Feeds show the first '.\App\Devnull\Data\Commit::PreviewLength.' characters or '.\App\Devnull\Data\Commit::PreviewLines.' lines, then Show more.') @if ($isCounting) {{ $remaining }} @elseif (\App\Devnull\Data\Commit::isFoldedInLists($body)) - @if ($foldHint) - folded in feeds - @else - - @endif + folded in feeds @endif diff --git a/resources/views/native/partials/composer-plate.blade.php b/resources/views/native/partials/composer-plate.blade.php deleted file mode 100644 index d5ec3f0f..00000000 --- a/resources/views/native/partials/composer-plate.blade.php +++ /dev/null @@ -1,24 +0,0 @@ -{{-- - A composer bar's field and its tools, as the reply bar on a commit's page and a Remotes thread's message bar draw - them, for the row that holds them with what follows (a counter, the send button). On iOS the field is a Liquid - Glass plate and the tools sit inside it at its trailing edge, where iOS puts a field's own controls, staying at the - bottom as the draft grows. On Android the tools lead the row, ahead of the field, and the row starts closer to the - edge for them (ios:pl-4 android:pl-2). - - $ref names the plate ("{$ref}-plate", also its key, so the field keeps its place as rows above it come and go), - $field is the partial that draws the field, and $tools are composer-tool's, in the web's order. ---}} -@php($toolsInField = \Native\Mobile\Platform::isIos()) -@unless ($toolsInField) - @foreach ($tools as $tool) - @include('native.partials.composer-tool', $tool) - @endforeach -@endunless - - @include($field) - @if ($toolsInField) - @foreach ($tools as $tool) - @include('native.partials.composer-tool', $tool) - @endforeach - @endif - diff --git a/resources/views/native/partials/composer-tool.blade.php b/resources/views/native/partials/composer-tool.blade.php index 92027763..6ae256f4 100644 --- a/resources/views/native/partials/composer-tool.blade.php +++ b/resources/views/native/partials/composer-tool.blade.php @@ -1,11 +1,13 @@ {{-- One of the composer's tools, as the web's ghost icon buttons: a 44pt target with the icon in muted ink, on Blue Wash in Commit Blue while it's on ($active). While it can't be used ($disabled), it's faded, with nothing to press. - With $menu (TopBarAction items), a tap opens that menu instead of pressing. + With $menu (TopBarAction items), a tap opens that menu instead of pressing. With $text, the icon is smaller and the + words follow it in muted ink, as the reply box counts the photos on its draft. --}} @php($active ??= false) @php($disabled ??= false) @php($menu ??= null) +@php($text ??= null) @if ($menu !== null) {{-- iOS's menu reads its icon to VoiceOver rather than the pressable's label, so the icon carries it too. --}} @@ -17,6 +19,13 @@ +@elseif ($text !== null) + + + + {{ $text }} + + @else diff --git a/resources/views/native/partials/related-commits.blade.php b/resources/views/native/partials/related-commits.blade.php index a7398456..452eaedf 100644 --- a/resources/views/native/partials/related-commits.blade.php +++ b/resources/views/native/partials/related-commits.blade.php @@ -1,19 +1,35 @@ -{{-- Other threads, in relevance order, on a fresh rail below this thread as on the web. --}} +{{-- + Other threads, in relevance order, on a fresh rail below this thread as on the web. They start closed under a + header with their count, which opens them in place and closes them again, its chevron turning as they do (see + CommitDetail::toggleRelated()). Each commit fades and slides into place a little after the one above it, and fades + out together as they close. The header is the whole row, so it's an easy target at the foot of the page. +--}} +@php($relatedOpen = $relatedShown && ! $relatedClosing) +@php($relatedLabel = \App\Devnull\Display::count(count($relatedRows), 'related commit', 'related commits')) - - Related commits - - @foreach ($relatedRows as $relatedRow) - @include('native.partials.commit-row', [ - 'commit' => $relatedRow->commit, - 'previousLane' => $relatedRow->previousLane, - 'continuesRun' => $relatedRow->continuesRun, - 'continuesNext' => null, - 'focused' => false, - 'muted' => false, - 'seriesExpanded' => false, - 'threadBelow' => false, - 'withTail' => ! $loop->last, - ]) - @endforeach + + + Related commits + {{ count($relatedRows) }} + + + + + @if ($relatedShown) + @foreach ($relatedRows as $relatedRow) + + @include('native.partials.commit-row', [ + 'commit' => $relatedRow->commit, + 'previousLane' => $relatedRow->previousLane, + 'continuesRun' => $relatedRow->continuesRun, + 'continuesNext' => null, + 'focused' => false, + 'muted' => false, + 'seriesExpanded' => false, + 'threadBelow' => false, + 'withTail' => ! $loop->last, + ]) + + @endforeach + @endif diff --git a/resources/views/native/partials/reply-field.blade.php b/resources/views/native/partials/reply-field.blade.php index 04f37457..6400973d 100644 --- a/resources/views/native/partials/reply-field.blade.php +++ b/resources/views/native/partials/reply-field.blade.php @@ -1,11 +1,12 @@ {{-- - The reply bar's field on a commit's page (see partials/composer-plate). EDGE sends no focus event, so a press on the - field is how the page learns you're replying. The expand button is beside it rather than in it, so pressing it + The reply bar's field on a commit's page, across the top of partials/composer-box. EDGE sends no focus event, so a + press on the field is how the page learns you're replying. The expand button is in the row under it, so pressing it doesn't count. Where the caret is goes to the page as it moves, for the "@" suggestions above the bar (see SuggestsMentions). It keeps the keyboard up through presses elsewhere on the page (keep-focus), as the Remotes - field does, so picking someone to mention leaves you typing after them. + field does, so picking someone to mention leaves you typing after them. The expand button grows it to + Display::ExpandedReplyMinLines tall: the same field, only taller, so the keyboard doesn't move. --}} - + diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index fc0da284..9716ce8c 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -105,17 +105,88 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->and(idsDownTo($screen->tree(), 'reply-input'))->toBe($field); }); -it('puts the expand button inside the reply field on iOS, and ahead of it on Android', function (string $platform, array $row, array $plate) { +it('draws the reply bar as one box, the field over the expand button and a round Reply, on both platforms', function (string $platform) { fakeThread(); $screen = Native::visit('/log/commits/c2', platform: $platform); + $actions = childRefs($screen, 'reply-actions'); - expect(childRefs($screen, 'reply-row'))->toBe($row) - ->and(childRefs($screen, 'reply-plate'))->toBe($plate); -})->with([ - 'iOS' => ['ios', ['reply-plate', 'send-reply'], ['reply-field', 'reply-expand']], - 'Android' => ['android', ['reply-expand', 'reply-plate', 'send-reply'], ['reply-field']], -]); + expect(childRefs($screen, 'reply-row'))->toBe(['reply-box']) + ->and(childRefs($screen, 'reply-box'))->toBe(['reply-field-row', 'reply-actions']) + ->and(childRefs($screen, 'reply-field-row'))->toBe(['reply-field']) + ->and($actions[0])->toBe('reply-expand') + ->and(end($actions))->toBe('send-reply') + ->and(nodeByRef($screen, 'send-reply')['props']['a11y_label'] ?? nodeByRef($screen, 'send-reply')['a11y_label'] ?? null)->toBe('Reply') + ->and(canSend($screen, 'send-reply'))->toBeFalse(); + + $screen->input('reply-input', 'Ready'); + + expect(canSend($screen, 'send-reply'))->toBeTrue(); +})->with(['ios', 'android']); + +it('grows the reply box where it is for more room, keeping the same field so the keyboard stays up', function (string $platform) { + fakeThread(); + + $screen = Native::visit('/log/commits/c2', platform: $platform)->input('reply-input', 'A long one'); + $field = idsDownTo($screen->tree(), 'reply-input'); + $clearance = nodeByRef($screen, 'reply-bar-clearance')['layout']['height']; + + expect(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(5) + ->and(rendersRef($screen, 'reply-attach'))->toBeFalse(); + + $screen->tap('reply-expand'); + + expect(idsDownTo($screen->tree(), 'reply-input'))->toBe($field) + ->and(nodeByRef($screen, 'reply-input')['props']['min_lines'])->toBe(8) + ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(12) + ->and(nodeByRef($screen, 'reply-expand')['props']['a11y_label'] ?? null)->toBe('Give the reply less room') + ->and(childRefs($screen, 'reply-actions')[1])->toBe('reply-attach') + ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse() + ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance + 7 * 21); + + // Photos and a preview are a tap further, in the composer sheet, with the draft. + $screen->tap('reply-attach'); + + expect(nodeByRef($screen, 'sheet')['props']['visible'])->toBeTrue() + ->and($screen->instance()->sheetBody)->toBe('A long one'); + + $screen->dismissSheet('sheet')->tap('reply-expand'); + + expect(idsDownTo($screen->tree(), 'reply-input'))->toBe($field) + ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(5) + ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance); +})->with(['ios', 'android']); + +it('shrinks the grown reply box back once the reply is sent', function () { + fakeThread(extra: ['POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Sent'])], 201]]); + + $screen = Native::visit('/log/commits/c2')->tap('reply-expand')->input('reply-input', 'Sent')->tap('send-reply'); + + expect($screen->instance()->replyExpanded)->toBeFalse() + ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(5); +}); + +it('says a reply long enough to be folded in feeds is, in words beside Reply and in the sheet, rather than an icon', function () { + fakeThread(); + + $screen = Native::visit('/log/commits/c2')->input('reply-input', 'Short'); + + expect(rendersRef($screen, 'reply-budget-fold'))->toBeFalse(); + + $screen->input('reply-input', str_repeat('a', 281)); + $hint = nodeByRef($screen, 'reply-budget-fold'); + + expect($hint['type'])->toBe('text') + ->and($hint['props']['text'])->toBe('folded in feeds') + ->and($hint['props']['a11y_label'] ?? $hint['a11y_label'] ?? null)->toBe('Feeds show the first 280 characters or 8 lines, then Show more.') + ->and(array_slice(childRefs($screen, 'reply-actions'), -2))->toBe(['reply-budget-fold', 'send-reply']) + ->and(findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'icon' && ($node['ref'] ?? null) === 'reply-budget-fold'))->toBeNull(); + + $screen->tap('reply-expand')->tap('reply-attach'); + + expect(nodeByRef($screen, 'sheet-budget-fold')['type'])->toBe('text') + ->and(nodeByRef($screen, 'sheet-budget-fold')['props']['text'])->toBe('folded in feeds'); +}); it('runs the rail from the folded ancestors into the parent, which shows its avatar', function () { $ada = userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]); @@ -320,7 +391,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): Native::visit('/log/commits/c2') ->input('reply-input', ' ') - ->tap('send-reply') + ->call('sendReply') ->input('reply-input', str_repeat('a', 4000)) ->assertElement('text', fn (array $node): bool => ($node['ref'] ?? null) === 'reply-budget' && ($node['text'] ?? $node['props']['text'] ?? null) === '0' @@ -333,7 +404,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): fakeThread(extra: ['POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => $body])], 201]]); $screen = Native::visit('/log/commits/c2')->input('reply-input', $body); - expect(nodeByRef($screen, 'send-reply')['props']['disabled'] ?? false)->toBeFalse() + expect(canSend($screen, 'send-reply'))->toBeTrue() ->and(nodeByRef($screen, 'reply-input')['props']['max_length'])->toBe(40000); $screen->tap('send-reply')->assertSet('reply', ''); @@ -344,7 +415,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): fakeThread(); $screen = Native::visit('/log/commits/c2')->input('reply-input', 'https://example.com/'.str_repeat('x', 2030)) ->assertSee('Each link must not be greater than 2048 characters.'); - expect(nodeByRef($screen, 'send-reply')['props']['disabled'])->toBeTrue(); + expect(canSend($screen, 'send-reply'))->toBeFalse(); $screen->call('sendReply'); Http::assertNotSent(fn (Request $request): bool => $request->method() === 'POST'); }); @@ -766,29 +837,20 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(pressFeedbackInScroller($screen))->toBe([]); }); -it('paints the reply bar solid on Android, with its hairline, so the replies never show through', function () { +it('puts the reply bar on Liquid Glass tinted with the surface on iOS, and on the solid surface on Android', function () { fakeThread(); - $screen = Native::visit('/log/commits/c2', platform: 'android'); - $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); + $ios = Native::visit('/log/commits/c2', platform: 'ios'); + $android = Native::visit('/log/commits/c2', platform: 'android'); + $bar = findNode($android->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); - expect($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') + expect(nodeByRef($ios, 'reply-bar')['props']['glass'] ?? null)->toBe(1) + ->and(nodeByRef($ios, 'reply-bar')['style']['bg_color'] ?? null)->not->toBeNull() + ->and($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') + ->and($bar['children'][0]['props']['glass'] ?? null)->toBeNull() ->and($bar['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) ->and($bar['children'][0]['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) - ->and($bar['children'][0]['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.hairline')) - ->and(nodeByRef($screen, 'reply-plate')['props']['glass'] ?? null)->toBeNull(); -}); - -it('leaves the reply bar bare on iOS and floats the field on Liquid Glass', function () { - fakeThread(); - - $screen = Native::visit('/log/commits/c2', platform: 'ios'); - $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); - - expect($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') - ->and($bar['children'][0]['style']['bg_color'] ?? null)->toBeNull() - ->and($bar['children'][0]['children'][0]['style']['bg_color'] ?? null)->toBeNull() - ->and(nodeByRef($screen, 'reply-plate')['props']['glass'] ?? null)->toBe(1); + ->and($bar['children'][0]['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.hairline')); }); it('ends the page above the reply bar, and further as the draft grows', function () { @@ -800,13 +862,13 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): // The clearance is the last thing on the page, under the last reply: the bar's line and the home indicator. expect(end($page)['ref'] ?? null)->toBe('reply-bar-clearance') - ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 53 + 34); + ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 97 + 34); $screen->input('reply-input', "Three lines\nof a\ndraft"); - expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 53 + 2 * 21 + 34); + expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 97 + 2 * 21 + 34); $screen->input('reply-input', str_repeat("A line\n", 12)); - expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 53 + 4 * 21 + 34); + expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 97 + 4 * 21 + 34); }); diff --git a/tests/Feature/Screens/ComposerPhotosTest.php b/tests/Feature/Screens/ComposerPhotosTest.php index 9338fce8..81d2bd8a 100644 --- a/tests/Feature/Screens/ComposerPhotosTest.php +++ b/tests/Feature/Screens/ComposerPhotosTest.php @@ -237,7 +237,7 @@ function isTool(TestableComponent $screen, string $ref): bool $screen = Native::visit('/log/commits/c2') ->input('reply-input', 'Here it') - ->tap('reply-expand') + ->tap('reply-expand')->tap('reply-attach') ->assertSee('Reply to @ada'); expect(nodeByRef($screen, 'sheet-body')['props'])->toMatchArray(['value' => 'Here it', 'placeholder' => 'Reply to @ada']) @@ -267,7 +267,7 @@ function isTool(TestableComponent $screen, string $ref): bool $screen = Native::visit('/log/commits/c2') ->input('reply-input', 'Half') - ->tap('reply-expand') + ->tap('reply-expand')->tap('reply-attach') ->input('sheet-body', 'Half a reply') ->dismissSheet('sheet'); @@ -284,12 +284,14 @@ function isTool(TestableComponent $screen, string $ref): bool 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Look'])], 201], ]); - $screen = photosPicked(Native::visit('/log/commits/c2')->input('reply-input', 'Look')->tap('reply-expand'), [testPhoto()]) + $screen = photosPicked(Native::visit('/log/commits/c2')->input('reply-input', 'Look')->tap('reply-expand')->tap('reply-attach'), [testPhoto()]) ->dismissSheet('sheet'); $path = $screen->instance()->replyImages[0]->path; expect(treeShows(nodeByRef($screen, 'reply-photos'), '1 photo'))->toBeTrue() - ->and(nodeByRef($screen, 'reply-photos')['props']['a11y_label'] ?? null)->toBe('1 photo attached'); + ->and(nodeByRef($screen, 'reply-photos')['props']['a11y_label'] ?? null)->toBe('1 photo attached') + // In the box, after its other tools. + ->and(array_slice(childRefs($screen, 'reply-actions'), 0, 3))->toBe(['reply-expand', 'reply-attach', 'reply-photos']); // Coming back to the commit, the bar has them still. $screen = Native::visit('/log/commits/c2'); @@ -322,7 +324,7 @@ function isTool(TestableComponent $screen, string $ref): bool 'GET /api/v1/commits/c2/replies' => [pageJson([])], ]); - $screen = photosPicked(Native::visit('/log/commits/c2', platform: 'android')->input('reply-input', 'Half')->tap('reply-expand'), [testPhoto()]) + $screen = photosPicked(Native::visit('/log/commits/c2', platform: 'android')->input('reply-input', 'Half')->tap('reply-expand')->tap('reply-attach'), [testPhoto()]) ->input('sheet-body', 'Half a reply') ->tap('sheet-cancel') ->input('reply-input', 'Half a reply, and more'); diff --git a/tests/Feature/Screens/DraftStashTest.php b/tests/Feature/Screens/DraftStashTest.php index 46baedf4..139954a7 100644 --- a/tests/Feature/Screens/DraftStashTest.php +++ b/tests/Feature/Screens/DraftStashTest.php @@ -206,8 +206,9 @@ function stashLabel(TestableComponent $screen, string $ref): array expect(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('A reply in progress') ->and(stashLabel($screen, 'reply-stash'))->toBe(['stash@{0}', 'Discard the restored draft']) - ->and(nodeByRef($screen, 'send-reply')['props']['disabled'] ?? false)->toBeFalse() - // The page ends above the row that marks it, too. + ->and(canSend($screen, 'send-reply'))->toBeTrue() + // It's marked on a row under the box, and the page ends above that too. + ->and(childRefs($screen, 'reply-stash-row'))->toBe(['reply-stash']) ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance + Display::ReplyBarStashLabelHeight); }); diff --git a/tests/Feature/Screens/LaneButtonsTest.php b/tests/Feature/Screens/LaneButtonsTest.php index 3e966d04..40689705 100644 --- a/tests/Feature/Screens/LaneButtonsTest.php +++ b/tests/Feature/Screens/LaneButtonsTest.php @@ -72,14 +72,6 @@ function laneLog(): TestableComponent return Native::visit('/log/users/ada/followers'); }, 'follow-grace'], - 'Reply' => [function (): TestableComponent { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2']))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - ]); - - return Native::visit('/log/commits/c2'); - }, 'send-reply'], 'Edit on GitHub, on the Account screen' => [function (): TestableComponent { serveApi(['GET /api/v1/me' => [currentUserJson(['lane' => app(Account::class)->user()?->lane()])]]); @@ -115,6 +107,27 @@ function laneLog(): TestableComponent 'rose, checked in white' => 4, ]); +it("fills the reply bar's round Reply with your lane, with an arrow that reads on it", function (int $lane) { + signIn(['lane' => $lane]); + serveApi([ + 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2']))], + 'GET /api/v1/commits/c2/replies' => [pageJson([])], + ]); + + $circle = nodeByRef(Native::visit('/log/commits/c2')->input('reply-input', 'Agreed'), 'send-reply-circle'); + $icon = findNode($circle, fn (array $node): bool => $node['type'] === 'icon')['props']; + + expect(array_map(strtolower(...), [$circle['style']['bg_color'], $circle['props']['dark_bg_color'], $icon['color'], $icon['dark_color']]))->toBe(array_map(strtolower(...), [ + config("native-ui.theme.light.lane-{$lane}"), + config("native-ui.theme.dark.lane-{$lane}"), + config("native-ui.theme.light.on-lane-{$lane}"), + config("native-ui.theme.dark.on-lane-{$lane}"), + ])); +})->with([ + 'green, an arrow in ink' => 1, + 'rose, a white arrow' => 4, +]); + it('draws the tab underline in your lane, in its light and dark shades', function (string $path, int $lane) { signIn(['lane' => $lane]); Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); diff --git a/tests/Feature/Screens/RelatedCommitsTest.php b/tests/Feature/Screens/RelatedCommitsTest.php index a6265735..9e8f15b6 100644 --- a/tests/Feature/Screens/RelatedCommitsTest.php +++ b/tests/Feature/Screens/RelatedCommitsTest.php @@ -1,9 +1,13 @@ 'http://devnull.test']); @@ -25,6 +29,45 @@ function serveRelatedThread(array $related = [], array $extra = []): void ]); } +/** + * Lets every Beat the screen has dispatched come back, as the phone would once it had drawn the step before, and + * leaves any other task (a held refresh) where it is. Like finishBeats() in LogThreadTest, except that it opens a + * task's sealed payload without reading it through AsyncTaskTransport::readPayload(), which deletes it, so a held + * refresh would have nothing left for finishRefreshes() to run. + */ +function landBeats(TestableComponent $screen): TestableComponent +{ + $done = []; + + while (true) { + $beats = array_filter($screen->bridge()->callsTo('AsyncTask.Dispatch'), function (array $call) use (&$done): bool { + $id = $call['params']['id']; + $path = AsyncTaskTransport::directory('payload').DIRECTORY_SEPARATOR.$id.'.task'; + $unseal = Closure::bind(fn (string $id, string $sealed): ?string => static::unseal($id, $sealed), null, AsyncTaskTransport::class); + + return ! isset($done[$id]) && is_file($path) && str_contains((string) $unseal($id, (string) file_get_contents($path)), serialize(Beat::class)); + }); + + if ($beats === []) { + return $screen; + } + + foreach ($beats as $call) { + $done[$call['params']['id']] = true; + AsyncTaskTransport::forgetPayload($call['params']['id']); + $screen->emitNative(AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); + } + } +} + +/** + * Opens the related commits under their header, and lets them fade in. + */ +function openRelated(TestableComponent $screen): TestableComponent +{ + return landBeats($screen->tap('related-commits-toggle')); +} + it('shows related commits below the thread in relevance order on their own rail', function (string $platform) { serveRelatedThread([ commitJson(['id' => 'c9', 'body' => 'Closest match', 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])]), @@ -34,7 +77,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'GET /api/v1/commits/c1/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'A reply'])])], ]); - $screen = Native::visit('/log/commits/c1', ['replies' => true], platform: $platform) + $screen = openRelated(Native::visit('/log/commits/c1', ['replies' => true], platform: $platform)) ->assertSee('The focused commit') ->assertSee('A reply') ->assertSee('Related commits') @@ -43,7 +86,8 @@ function serveRelatedThread(array $related = [], array $extra = []): void ->assertSee('Third match'); expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) - ->and(childRefs($screen, 'related-commits'))->toBe(['related-commits-heading', 'commit-c9', 'commit-c3', 'commit-c7']) + ->and(childRefs($screen, 'related-commits'))->toBe(['related-commits-toggle', 'related-c9', 'related-c3', 'related-c7']) + ->and(childRefs($screen, 'related-c9'))->toBe(['commit-c9']) ->and(railNode($screen, 'commit-c9'))->toBe('avatar') ->and(pressFeedbackInScroller($screen))->toBe([]); @@ -73,7 +117,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void Http::assertNothingSent(); - finishRefreshes($screen)->assertSee('Closest match')->input('reply-input', 'A draft'); + openRelated(finishRefreshes($screen))->assertSee('Closest match')->input('reply-input', 'A draft'); expect(collect(Http::recorded())->filter(fn (array $sent): bool => str_ends_with($sent[0]->url(), '/related')))->toHaveCount(1); }); @@ -84,7 +128,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void keep('commits/c1/related', ['data' => [commitJson(['id' => 'c9', 'body' => 'Old match'])]]); serveRelatedThread([commitJson(['id' => 'c3', 'body' => 'Fresh match'])]); - $screen = Native::visit('/log/commits/c1')->assertSee('Old match'); + $screen = openRelated(Native::visit('/log/commits/c1'))->assertSee('Old match'); finishRefreshes($screen)->assertSee('Fresh match')->assertDontSee('Old match'); @@ -128,7 +172,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'GET /api/v1/commits/c9/replies' => [pageJson([replyJson(['id' => 'r9', 'parent_id' => 'c9', 'body' => 'Answer to the match'])])], ]); - Native::visit("/{$tab}/commits/c1") + openRelated(Native::visit("/{$tab}/commits/c1")) ->tap($ref) ->assertNavigatedTo("/{$tab}/commits/c9") ->follow() @@ -146,7 +190,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'POST /api/v1/commits/c9/star' => [['data' => [...$related, 'starred' => true, 'stars_count' => 1]]], ]); - $screen = Native::visit('/log/commits/c1')->tap('star-c9'); + $screen = openRelated(Native::visit('/log/commits/c1'))->tap('star-c9'); expect($screen->instance()->related[0]->starred)->toBeTrue() ->and(kept('commits/c1/related')['data'][0]['starred'])->toBeTrue() @@ -158,7 +202,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'POST /api/v1/commits/c9/star' => [['message' => 'Cannot star now.'], 422], ]); - $screen = Native::visit('/log/commits/c1')->tap('star-c9'); + $screen = openRelated(Native::visit('/log/commits/c1'))->tap('star-c9'); expect($screen->instance()->related[0]->starred)->toBeFalse() ->and(kept('commits/c1/related')['data'][0]['starred'])->toBeFalse(); @@ -169,8 +213,67 @@ function serveRelatedThread(array $related = [], array $extra = []): void keep('commits/c1', commitPageJson(commitJson(['id' => 'c1', 'body' => 'The focused commit']))); keep('commits/c1/related', ['data' => [commitJson(['id' => 'c9', 'body' => 'Closest match'])]]); - $screen = Native::visit('/log/commits/c1')->assertSee('Closest match'); + $screen = openRelated(Native::visit('/log/commits/c1'))->assertSee('Closest match'); app(ResponseCache::class)->commitDeleted('c9'); $screen->call('onResume')->assertDontSee('Closest match')->assertDontSee('Related commits'); }); + +it('keeps related commits closed under a header with their count until it is tapped', function (string $platform) { + serveRelatedThread([ + commitJson(['id' => 'c9', 'body' => 'Closest match']), + commitJson(['id' => 'c3', 'body' => 'Next match']), + ]); + + $screen = Native::visit('/log/commits/c1', platform: $platform) + ->assertSee('Related commits') + ->assertDontSee('Closest match') + ->assertDontSee('Next match'); + + expect(childRefs($screen, 'related-commits'))->toBe(['related-commits-toggle']) + ->and(nodeByRef($screen, 'related-commits-count')['props']['text'])->toBe('2') + ->and(nodeByRef($screen, 'related-commits-toggle')['props']['a11y_label'] ?? null)->toBe('2 related commits') + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'] ?? 0.0)->toEqual(0.0); + + openRelated($screen)->assertSee('Closest match')->assertSee('Next match'); + + expect(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'])->toEqual(90.0); + + landBeats($screen->tap('related-commits-toggle'))->assertDontSee('Closest match')->assertSee('Related commits'); + + expect(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'] ?? 0.0)->toEqual(0.0); +})->with(['ios', 'android']); + +it('fades related commits in one after another as they open, and out together as they close', function () { + holdRefreshes(); + serveRelatedThread([ + commitJson(['id' => 'c9', 'body' => 'Closest match']), + commitJson(['id' => 'c3', 'body' => 'Next match']), + ]); + + $screen = finishRefreshes(Native::visit('/log/commits/c1', platform: 'ios')); + + // Drawn see-through and nudged up first, with the animation each eases in by, the second a beat later. + $screen->tap('related-commits-toggle'); + expect(nodeByRef($screen, 'related-c9')['style']['opacity'] ?? null)->toBe(0.0) + ->and(nodeByRef($screen, 'related-c9')['props']['translate-y'] ?? null)->toBe(-8.0) + ->and(nodeByRef($screen, 'related-c9')['props']['animate-duration'] ?? null)->toBe(220.0) + ->and(nodeByRef($screen, 'related-c9')['props']['animate-delay'] ?? 0.0)->toEqual(0.0) + ->and(nodeByRef($screen, 'related-c3')['props']['animate-delay'] ?? null)->toEqual(40.0) + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'])->toEqual(90.0) + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['animate-duration'] ?? null)->toBe(220.0); + + landBeats($screen); + expect(nodeByRef($screen, 'related-c9')['style']['opacity'] ?? 1.0)->toBe(1.0) + ->and(nodeByRef($screen, 'related-c9')['props']['translate-y'] ?? null)->toBe(0.0); + + // Closing fades them out together, chevron back first, and they go once that's done. A tap meanwhile does nothing. + $screen->tap('related-commits-toggle')->tap('related-commits-toggle')->assertSee('Closest match'); + expect(nodeByRef($screen, 'related-c9')['style']['opacity'] ?? null)->toBe(0.0) + ->and(nodeByRef($screen, 'related-c3')['props']['animate-delay'] ?? 0.0)->toEqual(0.0) + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'] ?? 0.0)->toEqual(0.0); + + landBeats($screen)->assertDontSee('Closest match'); + expect($screen->instance()->relatedShown)->toBeFalse() + ->and($screen->instance()->relatedFaded)->toBeFalse(); +}); From 22079e3a918bbcc7d3a616cb992a57738a2acfe8 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 16 Nov 2026 13:13:39 +0000 Subject: [PATCH 03/30] Keep a commit's row the same height with its replies open or shut On the Log, opening or closing a commit's replies dropped or added the 7pt under its replies line, where the hairline sits. When the commit's top was off screen, the iPhone's list held the row below still instead, so the commit's photo jumped by 7pt. The row now keeps that padding, the hairline's 1pt included, with its replies open, and only the hairline goes. The first reply takes the 7pt off its own top, so the thread looks the same, and the elbow and the lines beside a reply are placed from its avatar. The commit page is left as it was: it's a scroll view, which holds its top. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Display.php | 6 -- app/Devnull/ThreadRows.php | 10 +++ .../partials/commit-row-content.blade.php | 9 ++- .../native/partials/thread-elbow.blade.php | 7 ++- .../native/partials/thread-links.blade.php | 9 +-- .../native/partials/thread-reply.blade.php | 10 ++- tests/Feature/Screens/LogThreadTest.php | 63 ++++++++++++++++--- 7 files changed, 88 insertions(+), 26 deletions(-) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index 09d43f94..6cb0ecdf 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -35,12 +35,6 @@ final class Display */ public const int HomeIndicatorHeight = 34; - /** - * How far below the top of a reply's row its elbow comes level with the - * middle of the reply's avatar. - */ - public const int ElbowLevel = 22; - /** * How long ago a commit was made, as the web prints it beside the commit: * "now", "5m", "3h", "2d", then the date, in the same time zone as dayLabel(). diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php index 3affe2a7..337766d9 100644 --- a/app/Devnull/ThreadRows.php +++ b/app/Devnull/ThreadRows.php @@ -26,6 +26,15 @@ final class ThreadRows */ public const int Fade = 220; + /** + * The space above the first reply's avatar, 7pt less than a reply's usual + * 10pt. The commit's row keeps the 7pt of padding under its replies line, + * where its hairline was, so it's as tall with its thread open as shut, + * and a list never moves the commit when the thread opens or closes (see + * partials/commit-row-content). + */ + public const int FirstReplyTop = 3; + /** * @param array> $threads Open threads, by the id of the commit or reply they answer. * @param array $cursors Where each open thread with more carries on. @@ -58,6 +67,7 @@ public static function under(Commit $commit, array $threads, array $cursors, arr 'railLane' => $railLane, 'thread' => $commit, 'repliesInPlace' => true, + ...($index === 0 ? ['top' => self::FirstReplyTop] : []), ]); foreach ($nested as $nestedIndex => $nestedReply) { diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 8e3c8ea5..c42584dc 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -20,6 +20,13 @@ A list builds and measures every node of a row as it scrolls in, so the content is one column: the rail's 64pt gutter is its left margin, and the hairline under it is its bottom border. A border draws inside the box, so the bottom padding takes the hairline's 1pt to keep the row as tall as it was. + + In a feed the row is as tall with its replies open as shut. The replies are rows of their own, and when a row + whose top is off screen changes height, an iOS list can hold the row below it still and move this one instead, + so its photo jumped by the difference. With the replies open the row keeps its bottom padding, the hairline's 1pt + included, and only the hairline goes. The first reply takes that padding off its own top (see ThreadRows), so the + thread looks the same. A commit page's scroll view holds its top, so there the commit it's about ($focused) lets + its replies come straight up under it. --}} @php($author = $commit->author) @php($muted ??= false) @@ -34,7 +41,7 @@ @php($hasHairline = $hairline && ! $threadBelow) @php($inset = $focused ? 16 : 12) {{-- The action row's 36pt reaches 6pt into the inset below it, as its buttons are taller than their icons. --}} -@php($bottom = $threadBelow ? 0 : $inset - 6 + ($hasHairline ? 1 : 0)) +@php($bottom = $threadBelow && $focused ? 0 : $inset - 6 + ($hairline ? 1 : 0)) @php($padding = 'pt-['.$inset.']'.($bottom > 0 ? ' pb-['.$bottom.']' : '')) @php($repliesLine = ! $commit->isStaged() && ! $commit->isDeleted() && ($focused ? ($replyCount ?? $commit->repliesCount) : $commit->repliesCount) > 0 ? 40 : 0) @php($dotInActions = $endsWithDot && ! $commit->isStaged()) diff --git a/resources/views/native/partials/thread-elbow.blade.php b/resources/views/native/partials/thread-elbow.blade.php index 063ab961..f53f9afe 100644 --- a/resources/views/native/partials/thread-elbow.blade.php +++ b/resources/views/native/partials/thread-elbow.blade.php @@ -1,8 +1,9 @@ {{-- Where a thread leaves the rail, as the web's thread elbow from #121: a dashed line in the commit's lane down from - the rail ($from), round a 12pt corner, and across to the first reply's avatar ($to), level with its middle. A - nested reply's elbow leaves the spine of the reply above it the same way. It stops 1pt short of the avatar. + the rail ($from), round a 12pt corner, and across to the first reply's avatar ($to), level with its middle ($level + below the top of the reply's row). A nested reply's elbow leaves the spine of the reply above it the same way. It + stops 1pt short of the avatar. --}} @php($from ??= 31.5) @php($to ??= 64) - + diff --git a/resources/views/native/partials/thread-links.blade.php b/resources/views/native/partials/thread-links.blade.php index 858869c5..8f2c9084 100644 --- a/resources/views/native/partials/thread-links.blade.php +++ b/resources/views/native/partials/thread-links.blade.php @@ -11,12 +11,13 @@ @endif @if ($previousLane === null) - @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 75.5 : 31.5, 'to' => 64 + $indent]) + @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 75.5 : 31.5, 'to' => 64 + $indent, 'level' => $top + 12]) @else - @include('native.partials.dashed-line', ['position' => 'top-0 h-[6]', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) + @include('native.partials.dashed-line', ['position' => 'top-0 h-['.($top - 4).']', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) @endif @if ($hasNext) - {{-- Down to the next reply, or to the top of Show more's dot: 12pt under it, its padding and the hairline below. --}} - @include('native.partials.dashed-line', ['position' => 'top-[38] '.($more !== null ? 'bottom-[34]' : 'bottom-0'), 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) + {{-- From 4pt under the avatar down to the next reply, or to the top of Show more's dot: 12pt under it, its padding + and the hairline below. --}} + @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] '.($more !== null ? 'bottom-[34]' : 'bottom-0'), 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) @endif diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index b93ec9b0..18fb7eef 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -14,6 +14,9 @@ The last reply carries the thread's "Show more" when there's more ($more, what it presses), with the line from its avatar running down to it. + $top is the space above the avatar, 10pt, less for the first reply in a feed, which sits under the commit row's + bottom padding (see ThreadRows::FirstReplyTop). The lines beside it are placed from the avatar, so they move with it. + A commit page draws its replies $muted, smaller and in muted ink, so the commit they answer stays the main thing. A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. @@ -33,13 +36,14 @@ @php($avatarLine = 76 + $indent) @php($repliesInPlace ??= false) @php($fades ??= false) +@php($top ??= 10) @php($faded = $fades && in_array($reply->id, $fadedRows ?? [], true)) @if ($reply->isDeleted()) @php($opened = $tombstones && array_key_exists($reply->id, $tombstoneReplies ?? [])) - + @include('native.partials.dashed-ring', ['size' => 24, 'lane' => \App\Devnull\Lane::Rail]) @@ -67,7 +71,7 @@ @include('native.partials.thread-links') @if ($opened && ($tombstoneReplies[$reply->id] ?? []) !== []) {{-- The spine its own replies hang off, down from its ring. --}} - @include('native.partials.dashed-line', ['position' => 'top-[38] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => \App\Devnull\Lane::Rail]) + @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => \App\Devnull\Lane::Rail]) @endif @else @@ -76,7 +80,7 @@ - + @include('native.partials.rail-avatar', ['user' => $reply->author, 'lane' => $reply->lane(), 'size' => 24, 'staged' => false]) diff --git a/tests/Feature/Screens/LogThreadTest.php b/tests/Feature/Screens/LogThreadTest.php index 2e6fa5ba..e17e2da9 100644 --- a/tests/Feature/Screens/LogThreadTest.php +++ b/tests/Feature/Screens/LogThreadTest.php @@ -3,6 +3,8 @@ use App\Devnull\Pop; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; +use Native\Mobile\Events\Async\AsyncTaskFinished; +use Native\Mobile\Support\AsyncTaskTransport; use Native\Mobile\Testing\Native; use Native\Mobile\Testing\TestableComponent; @@ -99,7 +101,8 @@ function refNode(array $node, string $ref): ?array expect($elbow)->not->toBeNull() ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-1')]) ->and($elbow['props'])->toMatchArray(['border_l' => 1.0, 'border_b' => 1.0, 'border_t' => 0.0, 'border_r' => 0.0, 'radius_bl' => 12.0]) - ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 22.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) + // Level with the middle of the avatar, which sits 3pt down, under the commit row's 7pt of bottom padding. + ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 15.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) // A reply's own actions: the star and Reply, but no Quote. ->and(refNode($reply, 'reply-to-r1'))->not->toBeNull() ->and(refNode($reply, 'quote-r1'))->toBeNull() @@ -343,21 +346,63 @@ function refNode(array $node, string $ref): ?array $screen->tap('replies-c1'); - // Open: no padding under the replies line, and the dashes run on from the dot's foot to the row's. + // Open: the same 7pt padding without the hairline, so the dot stays put, and the dashes run on from the dot's foot + // to the row's, where the first reply's elbow takes over. $dashes = findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['props']['border_style'] ?? null) === 1 && ($node['layout']['position'][2] ?? null) === 0.0); - expect($tail()['layout']['position'][2])->toBe(65.0) - ->and($dashes['layout']['height'] ?? null)->toBe(49.0); + expect($tail()['layout']['position'][2])->toBe(72.0) + ->and($dashes['layout']['height'] ?? null)->toBe(56.0) + ->and(refNode(nodeByRef($screen, 'thread-reply-r1'), 'thread-elbow')['layout']['position'][0])->toBe(0.0); }); +it("keeps a commit's row the same height with its replies shut, opening, open and closing, so the list never moves it", function (string $platform) { + holdRefreshes(); + keep('log/following', pageJson([commitJson(['id' => 'c1', 'author' => grace(), 'replies_count' => 2])])); + keep('commits/c1/replies', pageJson(repliesJson('c1', 2))); + serveApi(fn () => Http::response(pageJson([]))); + + $screen = Native::visit('/log', platform: $platform); + $content = fn (): array => nodeByRef($screen, 'commit-c1')['children'][0]; + $heights = fn (): array => [ + $content()['layout'], + nodeByRef($screen, 'actions-c1')['layout'], + nodeByRef($screen, 'replies-c1')['layout'], + ]; + $hairline = fn (): ?float => $content()['props']['border_b'] ?? null; + + $shut = $heights(); + + // 12pt above, and under the replies line the 6pt the action row leaves and the hairline's 1pt. + expect($shut[0]['padding'])->toEqual([12, 16, 7, 0]) + ->and($hairline())->toBe(1.0); + + $screen->tap('replies-c1'); + expect($heights())->toBe($shut); + + finishBeats($screen); + expect($heights())->toBe($shut) + ->and($hairline())->toBeNull() + // The first reply takes the 7pt off its 10pt top, so the thread sits where it did; the next keeps its 10pt. + ->and(nodeByRef($screen, 'thread-reply-r1')['children'][0]['children'][1]['children'][0]['layout']['padding'][0])->toEqual(3) + ->and(nodeByRef($screen, 'thread-reply-r2')['children'][0]['children'][1]['children'][0]['layout']['padding'][0])->toEqual(10); + + $screen->tap('replies-c1')->assertSee('2 replies'); + expect($heights())->toBe($shut); + + finishBeats($screen); + expect(refNode($screen->tree(), 'thread-reply-r1'))->toBeNull() + ->and($heights())->toBe($shut) + ->and($hairline())->toBe(1.0); +})->with(['ios', 'android']); + it('drops a reply that went from an open thread when the log refreshes, and keeps the pages loaded after the first', function () { $gone = false; Http::fake(function (Request $request) use (&$gone) { return Http::response(match (true) { - str_contains($request->url(), '/log/following') => pageJson([threadedJson(12)]), - str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 2, from: 11), path: 'http://devnull.test/api/v1/commits/c1/replies'), - default => pageJson(array_values(array_filter(repliesJson('c1', 10), fn (array $reply): bool => ! ($gone && $reply['id'] === 'r3'))), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), + str_contains($request->url(), '/log/following') => pageJson([threadedJson(12)]), + str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 2, from: 11), path: 'http://devnull.test/api/v1/commits/c1/replies'), + default => pageJson(array_values(array_filter(repliesJson('c1', 10), fn (array $reply): bool => ! ($gone && $reply['id'] === 'r3'))), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), }); }); @@ -393,7 +438,7 @@ function finishBeats(TestableComponent $screen, int $times = PHP_INT_MAX): Testa for ($round = 0; $round < $times; $round++) { $beats = array_filter($screen->bridge()->callsTo('AsyncTask.Dispatch'), function (array $call) use (&$done): bool { - $payload = \Native\Mobile\Support\AsyncTaskTransport::readPayload($call['params']['id']); + $payload = AsyncTaskTransport::readPayload($call['params']['id']); return ! isset($done[$call['params']['id']]) && $payload !== null && str_contains($payload, 'App\\Devnull\\Beat'); }); @@ -404,7 +449,7 @@ function finishBeats(TestableComponent $screen, int $times = PHP_INT_MAX): Testa foreach ($beats as $call) { $done[$call['params']['id']] = true; - $screen->emitNative(\Native\Mobile\Events\Async\AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); + $screen->emitNative(AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); } } From e082ad509ab65df393b040cf3f37ca3e1d89cea1 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Tue, 17 Nov 2026 00:57:13 +0000 Subject: [PATCH 04/30] Post as an organization you're in, as the web does The web lets a member of a GitHub organization post a commit, a quote or a reply as that organization. The app now does too. - GET /me's organizations are kept on the phone (Account), and refreshed whenever /me is. - The composer sheet shows who the commit goes out as above the field. A tap opens a menu of you and your organizations. The reply bar on a commit's page has the same avatar at its start, and hands its choice to the reply sheet and back. - The choice goes to devnull as `author`, which the API already takes, and rides in the outbox, so a staged commit shows the organization as its author. Commit and Reply use the organization's lane. - A scheduled commit goes out as the organization too, and the Scheduled list says "As @handle" as the web's does. - If devnull turns a commit down (you left the organization, or it's rate limited), the usual toast says why and the draft comes back with the organization still picked. The app asks /me again, and a composer whose organization is gone posts as you. - Tapping an organization in Notifications opens its page. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Account.php | 29 +- app/Devnull/Client.php | 26 +- app/Devnull/Data/CurrentUser.php | 22 ++ app/Devnull/Data/ScheduledCommit.php | 5 +- app/Devnull/PostAs.php | 106 ++++++ app/Models/PendingWrite.php | 43 ++- app/NativeComponents/CommitDetail.php | 38 +++ .../Concerns/OpensCommitSheet.php | 56 +++- .../Concerns/RefreshesInBackground.php | 1 + app/NativeComponents/Concerns/SyncsOutbox.php | 27 +- app/NativeComponents/Notifications.php | 15 +- app/NativeComponents/Onboarding.php | 1 + app/NativeComponents/ThisDevice.php | 1 + .../views/native/commit-detail.blade.php | 9 +- .../native/partials/commit-sheet.blade.php | 14 +- .../native/partials/dashed-ring.blade.php | 6 +- .../views/native/partials/post-as.blade.php | 28 ++ .../native/partials/rail-avatar.blade.php | 4 +- .../partials/sheet-bar-button.blade.php | 8 +- .../views/native/scheduled-commits.blade.php | 7 + tests/Feature/Screens/NotificationsTest.php | 7 + tests/Feature/Screens/PostAsTest.php | 312 ++++++++++++++++++ 22 files changed, 721 insertions(+), 44 deletions(-) create mode 100644 app/Devnull/PostAs.php create mode 100644 resources/views/native/partials/post-as.blade.php create mode 100644 tests/Feature/Screens/PostAsTest.php diff --git a/app/Devnull/Account.php b/app/Devnull/Account.php index 22917423..2163391d 100644 --- a/app/Devnull/Account.php +++ b/app/Devnull/Account.php @@ -36,6 +36,8 @@ final class Account private const string TermsKey = 'devnull.terms-to-accept'; + private const string OrganizationsKey = 'devnull.organizations'; + public function user(): ?User { $attributes = Cache::get(self::CacheKey); @@ -215,7 +217,31 @@ public function rememberTermsToAccept(?string $version): void } /** - * Signs this phone out: who it was, the badges, its pastéis and Remotes, your timezone, the terms you owe, every + * The GitHub organizations you can post as, as devnull last said, oldest membership first. None until it has. + * + * @return list + */ + public function organizations(): array + { + $kept = Cache::get(self::OrganizationsKey); + + return is_array($kept) ? array_values(array_map(User::fromArray(...), array_filter($kept, is_array(...)))) : []; + } + + /** + * Remembers the organizations you can post as. With null, from a devnull too old to say, it keeps what it had. + * + * @param list|null $organizations + */ + public function rememberOrganizations(?array $organizations): void + { + if ($organizations !== null) { + Cache::forever(self::OrganizationsKey, array_map(fn (User $organization): array => $organization->toArray(), $organizations)); + } + } + + /** + * Signs this phone out: who it was, the badges, its pastéis and Remotes, your organizations, your timezone, the terms you owe, every * answer, image and voice note kept for a quick start, and your unsent drafts and recordings. */ public function forget(): void @@ -234,5 +260,6 @@ public function forget(): void Cache::forget(self::PinWarningKey); Cache::forget(self::TimezoneKey); Cache::forget(self::TermsKey); + Cache::forget(self::OrganizationsKey); } } diff --git a/app/Devnull/Client.php b/app/Devnull/Client.php index b6538ae5..a2b74bea 100644 --- a/app/Devnull/Client.php +++ b/app/Devnull/Client.php @@ -301,13 +301,15 @@ public function replies(string $id, ?string $cursor = null): Page /** * Commits, as a reply to $parentId or quoting $quotedCommitId, as the web's * composer, reply box and Quote do. devnull takes one or the other, not both. - * A new commit or a quote may start a poll (see PollDraft::payload()). + * A new commit or a quote may start a poll (see PollDraft::payload()). With + * $author, the handle of an organization you're a member of, it goes out as + * that organization, as the web's Post as picks (see PostAs). * * @param array{options: list, duration: int}|null $poll */ - public function createCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null): Commit + public function createCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null, ?string $author = null): Commit { - $commit = $this->data($this->send('POST', 'commits', payload: self::commitPayload($body, $parentId, $quotedCommitId, poll: $poll))); + $commit = $this->data($this->send('POST', 'commits', payload: self::commitPayload($body, $parentId, $quotedCommitId, $poll, $author))); $this->cache->commitAdded($commit); return Commit::fromArray($commit); @@ -319,9 +321,9 @@ public function createCommit(string $body, ?string $parentId = null, ?string $qu * * @param array{options: list, duration: int}|null $poll */ - public function signedCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null): SignedRequest + public function signedCommit(string $body, ?string $parentId = null, ?string $quotedCommitId = null, ?array $poll = null, ?string $author = null): SignedRequest { - return $this->signedWrite('POST', 'commits', self::commitPayload($body, $parentId, $quotedCommitId, poll: $poll)); + return $this->signedWrite('POST', 'commits', self::commitPayload($body, $parentId, $quotedCommitId, $poll, $author)); } /** @@ -331,9 +333,9 @@ public function signedCommit(string $body, ?string $parentId = null, ?string $qu * * @param list $images */ - public function signedCommitWithImages(string $body, array $images, ?string $parentId = null, ?string $quotedCommitId = null): SignedRequest + public function signedCommitWithImages(string $body, array $images, ?string $parentId = null, ?string $quotedCommitId = null, ?string $author = null): SignedRequest { - return $this->signedWithImages('commits', self::commitPayload($body, $parentId, $quotedCommitId), $images); + return $this->signedWithImages('commits', self::commitPayload($body, $parentId, $quotedCommitId, author: $author), $images); } /** @@ -360,14 +362,15 @@ public function signedMessage(string $threadPath, string $body, string $clientId * Signs a commit to be submitted at $at, as the web's Schedule commit * does, for the background to send. Only you see it until then. With * photos it goes as multipart, as a commit with photos does, and a poll - * goes in its JSON. + * goes in its JSON. With $author it goes out as that organization when it's + * due, as long as you're still in it then. * * @param list $images * @param array|null $poll */ - public function signedScheduledCommit(string $body, CarbonInterface $at, array $images = [], ?array $poll = null): SignedRequest + public function signedScheduledCommit(string $body, CarbonInterface $at, array $images = [], ?array $poll = null, ?string $author = null): SignedRequest { - $payload = array_filter(['body' => $body, 'scheduled_at' => self::scheduleTime($at), 'poll' => $poll], fn (mixed $value): bool => $value !== null); + $payload = array_filter(['body' => $body, 'scheduled_at' => self::scheduleTime($at), 'poll' => $poll, 'author' => $author], fn (mixed $value): bool => $value !== null); return $images === [] ? $this->signedWrite('POST', self::ScheduledCommitsPath, $payload) @@ -976,13 +979,14 @@ private function send(string $method, string $path, array $query = [], ?array $p * @param array{options: list, duration: int}|null $poll * @return array */ - private static function commitPayload(string $body, ?string $parentId, ?string $quotedCommitId, ?array $poll = null): array + private static function commitPayload(string $body, ?string $parentId, ?string $quotedCommitId, ?array $poll = null, ?string $author = null): array { return array_filter([ 'body' => $body, 'parent_id' => $parentId, 'quoted_commit_id' => $quotedCommitId, 'poll' => $poll, + 'author' => $author, ], fn (mixed $value): bool => $value !== null); } diff --git a/app/Devnull/Data/CurrentUser.php b/app/Devnull/Data/CurrentUser.php index 9fead8f8..32b1701d 100644 --- a/app/Devnull/Data/CurrentUser.php +++ b/app/Devnull/Data/CurrentUser.php @@ -19,9 +19,16 @@ * And the terms: the version in force, which is the moment it took effect, when * you last accepted them, and whether that was this version. A devnull too old * to say leaves all three null. + * + * And the GitHub organizations you're a member of, admin or not, oldest + * membership first, which you can post as, as the web's Post as menu lists + * them. A devnull too old to say leaves it null. */ final readonly class CurrentUser { + /** + * @param list|null $organizations + */ public function __construct( public User $user, public int $unreadNotificationsCount = 0, @@ -37,6 +44,7 @@ public function __construct( public ?string $termsVersion = null, public ?CarbonImmutable $termsAcceptedAt = null, public ?bool $termsAccepted = null, + public ?array $organizations = null, ) {} /** @@ -69,9 +77,23 @@ public static function fromArray(array $json): self termsVersion: is_string($data['terms_version'] ?? null) && $data['terms_version'] !== '' ? $data['terms_version'] : null, termsAcceptedAt: Commit::date($data['terms_accepted_at'] ?? null), termsAccepted: is_bool($data['terms_accepted'] ?? null) ? $data['terms_accepted'] : null, + organizations: is_array($data['organizations'] ?? null) ? self::organizations($data['organizations']) : null, ); } + /** + * The organizations you can post as, each drawn as an organization whatever the answer said. + * + * @param array $organizations + * @return list + */ + private static function organizations(array $organizations): array + { + $users = array_map(fn (array $organization): User => User::fromArray([...$organization, 'type' => 'organization']), array_values(array_filter($organizations, is_array(...)))); + + return array_values(array_filter($users, fn (User $organization): bool => $organization->username !== '')); + } + /** * The version of the terms devnull is waiting for you to accept, exactly as it sent it, or null when you have. */ diff --git a/app/Devnull/Data/ScheduledCommit.php b/app/Devnull/Data/ScheduledCommit.php index 31280b98..dcdf0b0e 100644 --- a/app/Devnull/Data/ScheduledCommit.php +++ b/app/Devnull/Data/ScheduledCommit.php @@ -10,7 +10,8 @@ * page, which only you see. Until it's submitted it has its body, the options * of its poll, and how many images it carries. Once submitted, those are its * commit's, and its status is that commit's: pending review, approved, - * rejected, or deleted. + * rejected, or deleted. $author is the organization it goes out as, or null + * when it goes out as you. */ final readonly class ScheduledCommit { @@ -39,6 +40,7 @@ public function __construct( public CarbonImmutable $scheduledAt, public ?CarbonImmutable $submittedAt, public string $status, + public ?User $author = null, ) {} /** @@ -62,6 +64,7 @@ public static function fromArray(array $data): self scheduledAt: Commit::date($data['scheduled_at'] ?? null) ?? CarbonImmutable::now(), submittedAt: Commit::date($data['submitted_at'] ?? null), status: is_string($status) && ($status === 'scheduled' || array_key_exists($status, self::Labels)) ? $status : 'scheduled', + author: is_array($data['author'] ?? null) ? User::fromArray([...$data['author'], 'type' => 'organization']) : null, ); } diff --git a/app/Devnull/PostAs.php b/app/Devnull/PostAs.php new file mode 100644 index 00000000..03902d77 --- /dev/null +++ b/app/Devnull/PostAs.php @@ -0,0 +1,106 @@ + + */ + public static function organizations(): array + { + return app(Account::class)->organizations(); + } + + /** + * The organization the commit goes out as, or null when it goes out as you. + */ + public static function author(?string $picked): ?User + { + if ($picked === null || $picked === '') { + return null; + } + + foreach (self::organizations() as $organization) { + if (strcasecmp($organization->username, $picked) === 0) { + return $organization; + } + } + + return null; + } + + /** + * Whether the composer shows whom it posts as: you're in an organization, or picked one you've left since. + */ + public static function offered(?string $picked): bool + { + return self::organizations() !== [] || ($picked !== null && $picked !== ''); + } + + /** + * The menu: you first, then your organizations, the one posting now ticked. $method is called with the handle + * picked, or '' for you. + * + * @return list + */ + public static function menu(User $me, ?User $author, string $method): array + { + return array_map(fn (User $identity): TopBarAction => NavAction::make('post-as-'.$identity->username) + ->label($identity->name.' (@'.$identity->username.')') + ->icon(...self::icon($identity, $author)) + ->press($method."('".($identity->isOrganization ? $identity->username : '')."')") + ->toElement() + ->ref('post-as-'.$identity->username), [$me, ...self::organizations()]); + } + + /** + * What the composer's avatar says to a screen reader. + */ + public static function label(User $me, ?User $author): string + { + return 'Posting as @'.($author ?? $me)->username.'. Choose who to post as'; + } + + /** + * The lane the composer's main button is drawn in: yours, or the organization's. + */ + public static function colour(User $me, ?User $author): string + { + return Lane::token(($author ?? $me)->lane()); + } + + /** + * A tick beside whoever posts now, and what each is beside the rest, as the menu has no room for avatars. + * + * @return array{ios: string, android: string} + */ + private static function icon(User $identity, ?User $author): array + { + $posting = $author === null ? ! $identity->isOrganization : $identity->isOrganization && $identity->username === $author->username; + $icon = match (true) { + $posting => Lucide::Check, + $identity->isOrganization => Lucide::Building2, + default => Lucide::UserRound, + }; + + return ['ios' => $icon->ios(), 'android' => $icon->android()]; + } +} diff --git a/app/Models/PendingWrite.php b/app/Models/PendingWrite.php index 917bc654..74fb060b 100644 --- a/app/Models/PendingWrite.php +++ b/app/Models/PendingWrite.php @@ -19,8 +19,8 @@ * $target is what it's about: the commit starred, or the Remotes thread a * message goes to. $payload is what's sent, and for a commit what the * composer needs to have it back: its body, what it replies to or quotes, - * its poll, its photos with their descriptions, and the draft it was - * stashed under. + * its poll, its photos with their descriptions, the draft it was stashed + * under, and the organization it goes out as, if not as you. * * It's queued until it goes, sending while it's on its way, and failed once * devnull turned it down, when a commit stays for you to edit and a message @@ -132,6 +132,34 @@ public function quotedCommitId(): ?string return is_string($this->payload['quoted_commit_id'] ?? null) ? $this->payload['quoted_commit_id'] : null; } + /** + * The handle of the organization a commit goes out as, or null when it goes out as you. + */ + public function author(): ?string + { + return is_string($this->payload['author'] ?? null) && $this->payload['author'] !== '' ? $this->payload['author'] : null; + } + + /** + * The organization a commit goes out as, as the composer knew it, for the staged commit to show it, or null. + */ + public function authorProfile(): ?User + { + $profile = $this->payload['author_profile'] ?? null; + + return $this->author() !== null && is_array($profile) ? User::fromArray([...$profile, 'type' => 'organization']) : null; + } + + /** + * The payload's part for who a commit goes out as: nothing for you, and an organization's handle and profile. + * + * @return array{author?: string, author_profile?: array} + */ + public static function authorPayload(?User $organization): array + { + return $organization === null ? [] : ['author' => $organization->username, 'author_profile' => $organization->toArray()]; + } + /** * The commit's poll as devnull takes it, or null with none. * @@ -200,12 +228,15 @@ public static function imagePayload(array $images): array } /** - * The commit a commit on its way stands in as, by you, at once: what you - * wrote and its photos, marked staged, as the web's git words go, until - * devnull has it and the real one takes its place. + * The commit a commit on its way stands in as, at once: by you, or by the + * organization it goes out as, with what you wrote and its photos, marked + * staged, as the web's git words go, until devnull has it and the real one + * takes its place. */ - public function stagedCommit(User $author): Commit + public function stagedCommit(User $me): Commit { + $author = $this->authorProfile() ?? $me; + return new Commit( id: self::StagedPrefix.$this->client_id, body: $this->body(), diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index f20c88a3..322153b7 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -13,6 +13,7 @@ use App\Devnull\Display; use App\Devnull\DraftImages; use App\Devnull\Outbox; +use App\Devnull\PostAs; use App\Devnull\ResponseCache; use App\Devnull\RowCache; use App\Devnull\Stash; @@ -62,6 +63,10 @@ * wrote is back in the bar, or in the sheet with its photos. Edit, on the * toast of a reply or a quote turned down after you'd left, opens its commit * here with it ($data['edit']). + * + * A member of a GitHub organization can reply as it, from the avatar at the + * start of the bar, as the web's reply composer does (see PostAs). The sheet + * takes the choice with the draft, and gives it back. */ class CommitDetail extends NativeComponent { @@ -129,6 +134,11 @@ class CommitDetail extends NativeComponent */ public array $replyImages = []; + /** + * The handle of the organization the reply bar posts as, or null for you (see PostAs). + */ + public ?string $replyAuthor = null; + /** * Whether the reply was stashed when the page opened, which the bar marks until you empty it or drop it. */ @@ -349,6 +359,7 @@ public function sendReply(): void 'images' => PendingWrite::imagePayload($this->replyImages), 'stash' => $this->replyStashName(), 'composer' => 'bar', + ...PendingWrite::authorPayload(PostAs::author($this->replyAuthor)), ]); if ($write === null) { @@ -364,6 +375,32 @@ public function sendReply(): void $this->sendFromOutbox($write); } + /** + * Post as, from the reply bar's avatar: an organization's handle, or '' for you. + */ + public function postAsInReply(string $handle = ''): void + { + $this->replyAuthor = PostAs::author($handle)?->username; + } + + /** + * The reply in the sheet starts as whoever the bar posts as. + */ + protected function sheetAuthorFor(string $view): ?string + { + return $view === 'reply' && $this->sheetCommit?->id === $this->id ? $this->replyAuthor : null; + } + + /** + * A choice made in the reply's sheet goes back to the bar with the draft. + */ + protected function sheetAuthorChanged(): void + { + if ($this->sheetView === 'reply' && $this->sheetCommit?->id === $this->id) { + $this->replyAuthor = $this->sheetAuthor; + } + } + /** * The reply bar suggests whom devnull suggests for a reply to this commit, the people in its thread first, as * the web's reply composer asks, and so does the composer sheet over it (see SuggestsMentions). @@ -535,6 +572,7 @@ private function takeFailedReply(PendingWrite $write): void { $this->reply = $write->body(); $this->replyImages = $write->images(); + $this->replyAuthor = $write->author(); $this->replyRestored = true; $this->focusReply = true; $this->updatedReply(); diff --git a/app/NativeComponents/Concerns/OpensCommitSheet.php b/app/NativeComponents/Concerns/OpensCommitSheet.php index 19ac3922..cae605a7 100644 --- a/app/NativeComponents/Concerns/OpensCommitSheet.php +++ b/app/NativeComponents/Concerns/OpensCommitSheet.php @@ -9,6 +9,7 @@ use App\Devnull\Data\StashedDraft; use App\Devnull\DraftImages; use App\Devnull\Outbox; +use App\Devnull\PostAs; use App\Devnull\ReportReason; use App\Devnull\ResponseCache; use App\Devnull\SignedRequest; @@ -56,6 +57,11 @@ * web's does: devnull's people for a new commit, a reply or a quote (see * SuggestsMentions). * + * A member of a GitHub organization can post as it instead, from the avatar + * over the field, as the web's Post as menu does, in a new commit, a quote or + * a reply (see PostAs). It starts as you each time, as the web's does, and + * the commit shows staged as the organization while it goes. + * * The sheet keeps its commit while it slides away, so it doesn't empty on the * way down, and lets go of it once iOS says it's gone, however it was closed. */ @@ -104,6 +110,11 @@ trait OpensCommitSheet */ public string $sheetBody = ''; + /** + * The handle of the organization the sheet posts as, or null for you (see PostAs). + */ + public ?string $sheetAuthor = null; + /** * Whether the sheet opened on a stashed draft, which it marks until you empty it or drop it. */ @@ -249,6 +260,24 @@ public function composeInSheet(): void $this->restoreSheetDraft(); } + /** + * Post as, from the sheet's avatar: an organization's handle, or '' for you. + */ + public function postAsInSheet(string $handle = ''): void + { + $this->sheetAuthor = PostAs::author($handle)?->username; + $this->sheetError = null; + $this->sheetAuthorChanged(); + } + + /** + * The sheet's author changed. A screen whose own composer handed it the draft keeps the choice too. + */ + protected function sheetAuthorChanged(): void + { + // + } + /** * The web's clock button, in a new commit's composer: it opens "Submit at" under the field, with no time picked, * or closes it, and the commit goes now again. Its photos or its poll go with it either way, as on the web. @@ -335,6 +364,7 @@ public function commitFromSheet(): void 'images' => PendingWrite::imagePayload($this->sheetImages), 'stash' => $stashName, 'composer' => $this->sheetView, + ...PendingWrite::authorPayload(PostAs::author($this->sheetAuthor)), ]); if ($write === null) { @@ -549,10 +579,11 @@ private function scheduleFromSheet(string $body, string $stashName): void $images = $this->sheetImages; $poll = $this->sheetPollPayload(); + $author = PostAs::author($this->sheetAuthor)?->username; $this->sendingSchedule = true; $this->sheetError = null; - $this->sendInBackground(fn (Client $devnull): SignedRequest => $devnull->signedScheduledCommit($body, $at, $images, $poll), function () use ($me, $stashName, $images): void { + $this->sendInBackground(fn (Client $devnull): SignedRequest => $devnull->signedScheduledCommit($body, $at, $images, $poll, $author), function () use ($me, $stashName, $images): void { $this->sendingSchedule = false; app(ResponseCache::class)->forget(Client::ScheduledCommitsPath); app(Stash::class)->put($me->id, $stashName, new StashedDraft); @@ -560,9 +591,13 @@ private function scheduleFromSheet(string $body, string $stashName): void $this->sheetImages = []; $this->closeCommitSheet(); Toasts::say(self::Scheduled); - }, function (string $message): void { + }, function (string $message) use ($author): void { $this->sendingSchedule = false; $this->sheetError = $message; + + if ($author !== null && method_exists($this, 'refreshUnreadNotifications')) { + $this->refreshUnreadNotifications(); + } }, timeout: $images === [] ? 30 : 120); } @@ -574,6 +609,7 @@ private function forgetCommitSheet(): void $this->reportReason = ''; $this->reportDetails = ''; $this->sheetBody = ''; + $this->sheetAuthor = null; $this->sheetRestored = false; $this->sheetError = null; $this->forgetMention('sheetBody'); @@ -621,16 +657,20 @@ protected function stashSheetDraft(): void } /** - * The sheet starts from its stashed draft, with its photos and poll. A + * The sheet starts from its stashed draft, with its photos and poll, as + * you, or as the screen's own composer had it (see sheetAuthorFor()). A * commit devnull turned down that was written under it comes back whole, - * and leaves the outbox: from here it's a draft again. + * as the organization it was to go out as, and leaves the outbox: from + * here it's a draft again. */ private function restoreSheetDraft(): void { $name = $this->sheetStashName(); $failed = $name === null ? null : app(Outbox::class)->failedDraft($name); + $this->sheetAuthor = $this->sheetAuthorFor($this->sheetView); if ($failed !== null) { + $this->sheetAuthor = $failed->author(); $this->takeFailedCommit($failed); } @@ -643,6 +683,14 @@ private function restoreSheetDraft(): void $this->sheetRestored = ! $draft->isEmpty(); } + /** + * Who the sheet starts out posting as for $view: you, unless the screen's own composer handed it a choice. + */ + protected function sheetAuthorFor(string $view): ?string + { + return null; + } + private function takeFailedCommit(PendingWrite $write): void { $poll = $write->poll(); diff --git a/app/NativeComponents/Concerns/RefreshesInBackground.php b/app/NativeComponents/Concerns/RefreshesInBackground.php index 600f5c37..a64a3a82 100644 --- a/app/NativeComponents/Concerns/RefreshesInBackground.php +++ b/app/NativeComponents/Concerns/RefreshesInBackground.php @@ -155,6 +155,7 @@ protected function refreshUnreadNotifications(): void app(Account::class)->remember($current->user); app(Account::class)->rememberPasteis($current->pasteis()); app(Account::class)->rememberRemotes($current->remotes); + app(Account::class)->rememberOrganizations($current->organizations); $this->takeTerms($current); } diff --git a/app/NativeComponents/Concerns/SyncsOutbox.php b/app/NativeComponents/Concerns/SyncsOutbox.php index 52b9a63e..eeb43c7a 100644 --- a/app/NativeComponents/Concerns/SyncsOutbox.php +++ b/app/NativeComponents/Concerns/SyncsOutbox.php @@ -42,11 +42,11 @@ * - A star comes back off the commit, here and in every kept copy, and the * toast offers Retry. * - A commit or a reply leaves the screen, and its draft goes back where you - * wrote it: the text in its stash, and the photos and poll with the failed - * write in the outbox, for the composer to take when it opens. The screen - * that owns the composer opens it again with the lot. Anywhere else the - * toast offers Edit, which opens it here when it can, or the commit the - * reply or quote was for. + * wrote it: the text in its stash, and the photos, poll and organization + * it was to go out as with the failed write in the outbox, for the + * composer to take when it opens. The screen that owns the composer opens + * it again with the lot. Anywhere else the toast offers Edit, which opens + * it here when it can, or the commit the reply or quote was for. * - A message stays in its thread as rejected, with its Retry, and the toast * offers Retry too. Its photos or voice note stay on the phone with it * until it goes. @@ -310,6 +310,7 @@ private function turnDownCommit(PendingWrite $write, string $error, bool $reopen } $this->showCommitTurnedDown($write); + $this->checkOrganizations($write); if ($reopen && $this->reopenFailedCommit($write)) { Toasts::failed($error); @@ -320,6 +321,18 @@ private function turnDownCommit(PendingWrite $write, string $error, bool $reopen Toasts::failed($error, ['label' => 'Edit', 'id' => 'edit', 'data' => ['write' => $write->id]]); } + /** + * A commit that was to go out as an organization asks devnull which ones + * you're still in, since leaving it is a reason devnull turns one down. Its + * composer then posts as you, as the web's does (see PostAs). + */ + private function checkOrganizations(PendingWrite $write): void + { + if ($write->author() !== null && method_exists($this, 'refreshUnreadNotifications')) { + $this->refreshUnreadNotifications(); + } + } + /** * Signs a write as devnull takes it, here on the UI thread. */ @@ -333,8 +346,8 @@ private function signWrite(PendingWrite $write): SignedRequest PendingWrite::Unstar => $devnull->signedWrite('DELETE', $commit), PendingWrite::Message => $devnull->signedMessage((string) $write->target, $write->body(), $write->client_id, $write->replyToId(), $write->images(), $write->voice()), default => $write->images() === [] - ? $devnull->signedCommit($write->body(), $write->parentId(), $write->quotedCommitId(), $write->poll()) - : $devnull->signedCommitWithImages($write->body(), $write->images(), $write->parentId(), $write->quotedCommitId()), + ? $devnull->signedCommit($write->body(), $write->parentId(), $write->quotedCommitId(), $write->poll(), $write->author()) + : $devnull->signedCommitWithImages($write->body(), $write->images(), $write->parentId(), $write->quotedCommitId(), $write->author()), }; } diff --git a/app/NativeComponents/Notifications.php b/app/NativeComponents/Notifications.php index 58b7dd7b..f22944de 100644 --- a/app/NativeComponents/Notifications.php +++ b/app/NativeComponents/Notifications.php @@ -270,13 +270,16 @@ public function open(string $id): void $commitId = $notification->commitToOpen(); - $this->openInTab($commitId !== null - ? '/commits/'.$commitId - : '/users/'.$notification->actor->username); + $this->openInTab(match (true) { + $commitId !== null => '/commits/'.$commitId, + $notification->actor->isOrganization => '/organizations/'.rawurlencode($notification->actor->username), + default => '/users/'.$notification->actor->username, + }); } /** - * Names and avatars open their profile independently of the notification's commit. + * Names and avatars open their profile independently of the notification's commit: an organization's page for + * one that replied, quoted or mentioned you. */ public function openActor(string $username): void { @@ -287,7 +290,9 @@ public function openActor(string $username): void foreach ([$notification->actor, ...$notification->actors] as $actor) { if ($username !== '' && $actor->username === $username) { - $this->openInTab('/users/'.$actor->username, ['user' => $actor]); + $actor->isOrganization + ? $this->openInTab('/organizations/'.rawurlencode($actor->username)) + : $this->openInTab('/users/'.$actor->username, ['user' => $actor]); return; } diff --git a/app/NativeComponents/Onboarding.php b/app/NativeComponents/Onboarding.php index 2b3cef0a..77914150 100644 --- a/app/NativeComponents/Onboarding.php +++ b/app/NativeComponents/Onboarding.php @@ -272,6 +272,7 @@ private function signInWithExistingKey(): void app(Account::class)->rememberUnreadNotifications($current->unreadNotificationsCount); app(Account::class)->rememberPasteis($current->pasteis()); app(Account::class)->rememberRemotes($current->remotes); + app(Account::class)->rememberOrganizations($current->organizations); app(Account::class)->rememberTermsToAccept($current->termsToAccept()); $this->keepProfile($current->user); $this->replace($current->termsToAccept() === null ? '/log' : AcceptTerms::Path); diff --git a/app/NativeComponents/ThisDevice.php b/app/NativeComponents/ThisDevice.php index 25c2c46c..dd17af64 100644 --- a/app/NativeComponents/ThisDevice.php +++ b/app/NativeComponents/ThisDevice.php @@ -989,6 +989,7 @@ private function takeMe(array $json): void app(Account::class)->rememberUnreadNotifications($current->unreadNotificationsCount); app(Account::class)->rememberPasteis($current->pasteis()); app(Account::class)->rememberRemotes($current->remotes); + app(Account::class)->rememberOrganizations($current->organizations); app(ResponseCache::class)->meChanged($json); $this->takeTerms($current); } diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index c633a3d0..d73c27f8 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -120,10 +120,14 @@ is bare and the field is a Liquid Glass plate instead, the way the HIG floats controls over content; the hairline stays as a clear 1pt so the bar keeps the height Display::ReplyBarHeight counts on. + A member of a GitHub organization has the web's Post as at the start of the row: the avatar of whoever the + reply goes out as, which opens the menu (see PostAs), and Reply in that one's lane. + The expand button opens the reply in the composer sheet, which has the photos and preview the bar has no room for. It sits where partials/composer-plate puts a composer's tools: inside the plate on iOS, ahead of the field on Android. --}} + @php($replyPostingMe = app(\App\Devnull\Account::class)->user()) @@ -137,13 +141,16 @@ @include('native.partials.mention-suggestions', ['field' => 'reply', 'label' => 'Mention a developer']) + @if ($replyPostingMe !== null && \App\Devnull\PostAs::offered($replyAuthor)) + @include('native.partials.post-as', ['ref' => 'reply-post-as', 'me' => $replyPostingMe, 'picked' => $replyAuthor, 'method' => 'postAsInReply', 'size' => 32]) + @endif @include('native.partials.composer-plate', [ 'ref' => 'reply', 'field' => 'native.partials.reply-field', 'tools' => [['ref' => 'reply-expand', 'icon' => \App\Icons\Lucide::Maximize2, 'label' => 'Reply with photos or a preview', 'press' => "replyInSheet('{$commit->id}')"]], ]) @include('native.partials.body-counter', ['body' => $reply, 'ref' => 'reply-budget']) - Reply + Reply @if (\App\Devnull\Data\CommitBody::hasOversizedUrl($reply)) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index 97a5b0b1..9a3cb463 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -19,6 +19,10 @@ field, its placeholder in it, and Open issue (the same check) in Commit's place in the bar. Opened, the sheet says so, with View issue and Done. + A member of a GitHub organization sees who the commit goes out as above the field, as the web's composer shows its + avatar: theirs, or the organization's, with its name and handle. A tap opens Post as (see PostAs). Commit is then + filled with the organization's lane. An issue always comes from you, so it hides there. + A commit's page opens its reply here too, as "Reply to @handle", with the commit being answered as a static card over the field, for the photos and the preview its reply bar has no room for. Commit says Reply there. @@ -51,6 +55,8 @@ @php($quoting = $sheetView === 'quote') @php($replying = $sheetView === 'reply') @php($issueCommand = $sheetIssue === null ? null : \App\Devnull\IssueCommand::from($sheetIssue)) + @php($postingMe = app(\App\Devnull\Account::class)->user()) + @php($postsAs = $postingMe !== null && ! $issueCommand && \App\Devnull\PostAs::offered($sheetAuthor)) @php($canCommit = \App\Devnull\Data\Draft::canCommit($sheetBody, $sheetImages, $replying ? null : $sheetPoll)) @@ -60,12 +66,18 @@ @include('native.partials.sheet-bar-button', ['ref' => 'sheet-open-issue', 'icon' => \App\Icons\Lucide::Check, 'label' => 'Open issue', 'main' => true, 'loading' => $openingIssue, 'press' => $openingIssue || ! \App\Devnull\IssueCommand::fits($sheetBody) ? null : 'openIssueFromSheet']) @else @php($schedulingThis = $scheduling && $sheetView === 'compose') - @include('native.partials.sheet-bar-button', ['ref' => 'sheet-commit', 'icon' => \App\Icons\Lucide::Check, 'label' => match (true) { $schedulingThis => 'Schedule commit', $replying => 'Reply', default => 'Commit' }, 'main' => true, 'loading' => $sendingSchedule, 'press' => $sendingSchedule || ! $canCommit || ($schedulingThis && ! $hasScheduledTime) ? null : 'commitFromSheet']) + @include('native.partials.sheet-bar-button', ['ref' => 'sheet-commit', 'icon' => \App\Icons\Lucide::Check, 'label' => match (true) { $schedulingThis => 'Schedule commit', $replying => 'Reply', default => 'Commit' }, 'main' => true, 'mainColour' => $postingMe === null ? $myColour : \App\Devnull\PostAs::colour($postingMe, \App\Devnull\PostAs::author($sheetAuthor)), 'loading' => $sendingSchedule, 'press' => $sendingSchedule || ! $canCommit || ($schedulingThis && ! $hasScheduledTime) ? null : 'commitFromSheet']) @endif + @if ($postsAs) + + @include('native.partials.post-as', ['ref' => 'sheet-post-as', 'me' => $postingMe, 'picked' => $sheetAuthor, 'method' => 'postAsInSheet', 'size' => 36, 'withName' => true]) + + @endif + @if ($sheetError) {{ $sheetError }} @endif diff --git a/resources/views/native/partials/dashed-ring.blade.php b/resources/views/native/partials/dashed-ring.blade.php index 97d43a19..67e9bf36 100644 --- a/resources/views/native/partials/dashed-ring.blade.php +++ b/resources/views/native/partials/dashed-ring.blade.php @@ -1,4 +1,6 @@ {{-- - A 2pt ring in dashes of $lane's colour, as the web's `border-2 border-dashed rounded-full`, $size across. + A 2pt ring in dashes of $lane's colour, as the web's `border-2 border-dashed rounded-full`, $size across. $rounded + makes it a rounded square instead, around an organization. --}} - +@php($rounded ??= 'rounded-full') + diff --git a/resources/views/native/partials/post-as.blade.php b/resources/views/native/partials/post-as.blade.php new file mode 100644 index 00000000..64f9d176 --- /dev/null +++ b/resources/views/native/partials/post-as.blade.php @@ -0,0 +1,28 @@ +{{-- + Who a composer posts as (see PostAs): the avatar of whoever it is now, round for you and a rounded square for an + organization, with a small chevron on its corner, as the web's Post as button draws it. A tap opens the menu of you + and your organizations, which calls $method with the handle picked, or '' for you. With $withName, their name and + handle follow the avatar, for the sheet, which has the room. + + $picked is the handle the composer holds. An organization you've left since posts as you, so your avatar shows. +--}} +@php($size ??= 32) +@php($withName ??= false) +@php($author = \App\Devnull\PostAs::author($picked)) +@php($identity = $author ?? $me) + + + + @include('native.partials.avatar', ['user' => $identity, 'size' => $size]) + + + + + @if ($withName) + + {{ $identity->name }} + {{ $identity->handle() }} + + @endif + + diff --git a/resources/views/native/partials/rail-avatar.blade.php b/resources/views/native/partials/rail-avatar.blade.php index e5055af0..d000bc54 100644 --- a/resources/views/native/partials/rail-avatar.blade.php +++ b/resources/views/native/partials/rail-avatar.blade.php @@ -13,8 +13,8 @@ @php($position ??= '') @php($live = ! $staged && $user->isLive()) @if ($staged) - - @include('native.partials.dashed-ring', ['size' => 48, 'lane' => $lane]) + + @include('native.partials.dashed-ring', ['size' => 48, 'lane' => $lane, 'rounded' => $user->isOrganization ? 'rounded-lg' : 'rounded-full']) @include('native.partials.avatar', ['user' => $user, 'size' => 40]) diff --git a/resources/views/native/partials/sheet-bar-button.blade.php b/resources/views/native/partials/sheet-bar-button.blade.php index a554285b..1dac031a 100644 --- a/resources/views/native/partials/sheet-bar-button.blade.php +++ b/resources/views/native/partials/sheet-bar-button.blade.php @@ -1,16 +1,18 @@ {{-- A round button in a sheet's bar, as Apple draws a sheet's cross and check: the same 44pt circle on both platforms. - It's glass on iOS and a tonal circle on Android, or filled with your colour as the bar's main button ($main). + It's glass on iOS and a tonal circle on Android, or filled with your colour as the bar's main button ($main), or + with $mainColour's, the lane of the organization a composer posts as. Without $press it's drawn muted, and not as a button, as a disabled button would be. Its action checks again anyway. $loading swaps the icon for a spinner in the same circle. --}} @php($main ??= false) +@php($mainColour ??= $myColour) @php($loading ??= false) @php($hint ??= null) @php($filled = $main && ($press !== null || $loading)) -@php($circle = 'rounded-full '.($filled ? 'bg-theme-'.$myColour : 'android:bg-theme-surface-variant ios:glass'.($press === null ? '' : ':interactive'))) -@php($iconColour = $filled ? 'text-theme-on-'.$myColour : ($press === null ? 'text-theme-ink-muted' : 'text-theme-ink')) +@php($circle = 'rounded-full '.($filled ? 'bg-theme-'.$mainColour : 'android:bg-theme-surface-variant ios:glass'.($press === null ? '' : ':interactive'))) +@php($iconColour = $filled ? 'text-theme-on-'.$mainColour : ($press === null ? 'text-theme-ink-muted' : 'text-theme-ink')) @if ($press !== null) diff --git a/resources/views/native/scheduled-commits.blade.php b/resources/views/native/scheduled-commits.blade.php index 06f07ac1..3dbf2dda 100644 --- a/resources/views/native/scheduled-commits.blade.php +++ b/resources/views/native/scheduled-commits.blade.php @@ -47,6 +47,13 @@ {{ $item->label($now) }} {{ Display::scheduleTime($item->scheduledAt, $timezone) }} + @if ($item->author) + {{-- The organization it goes out as, as the web's list shows it under the time. --}} + + @include('native.partials.avatar', ['user' => $item->author, 'size' => 16]) + As {{ $item->author->handle() }} + + @endif @if ($item->isWaiting()) @php($when = Display::scheduleTime($item->scheduledAt, $timezone)) diff --git a/tests/Feature/Screens/NotificationsTest.php b/tests/Feature/Screens/NotificationsTest.php index b160b4ef..06cef232 100644 --- a/tests/Feature/Screens/NotificationsTest.php +++ b/tests/Feature/Screens/NotificationsTest.php @@ -84,6 +84,13 @@ function ringColour(TestableComponent $screen, string $id): ?string Native::visit('/notifications')->tap('group-n-starred')->tap('group-actor-older')->assertNavigatedTo('/notifications/users/linus'); }); +it('opens the page of an organization that replied to you, from its name', function () { + $organization = [...personJson('dev-null-sh', '/dev/null'), 'type' => 'organization']; + fakeApi(['GET /api/v1/notifications' => [inboxJson([notificationJson('replied', ['actor' => $organization, 'actors' => [$organization]])])]]); + + Native::visit('/notifications')->tap('actor-name-n-replied')->assertNavigatedTo('/notifications/organizations/dev-null-sh'); +}); + it('does not navigate to an actor absent from the displayed notifications', function () { fakeApi(['GET /api/v1/notifications' => [inboxJson([])]]); Native::visit('/notifications')->call('openActor', 'nobody')->assertNoNavigation(); diff --git a/tests/Feature/Screens/PostAsTest.php b/tests/Feature/Screens/PostAsTest.php new file mode 100644 index 00000000..ed22582f --- /dev/null +++ b/tests/Feature/Screens/PostAsTest.php @@ -0,0 +1,312 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * An organization as `GET /me` lists one you're a member of. + * + * @param array $overrides + * @return array + */ +function memberOrganizationJson(array $overrides = []): array +{ + return [ + 'type' => 'organization', + 'id' => '0199e5c4-0000-7000-8000-0000000000aa', + 'role' => 'admin', + 'handle' => 'dev-null-sh', + 'name' => '/dev/null', + 'avatar_url' => 'https://avatars.githubusercontent.com/u/9?v=4', + 'bio' => null, + 'location' => null, + 'website' => null, + 'github_url' => 'https://github.com/dev-null-sh', + 'html_url' => 'http://devnull.test/@dev-null-sh', + 'lane' => null, + ...$overrides, + ]; +} + +/** + * Makes you a member of these organizations, as the last `GET /me` said. + * + * @param list> $organizations + */ +function memberOf(array $organizations): void +{ + app(Account::class)->rememberOrganizations(CurrentUser::fromArray(currentUserJson(['organizations' => $organizations]))->organizations); +} + +/** + * The Log with its composer open in the sheet, devnull answering a new commit with $answer. + * + * @param array{0: mixed, 1?: int}|null $answer + * @param array $extra + */ +function composeOnLogAs(?array $answer = null, array $extra = []): TestableComponent +{ + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'body' => 'An older commit', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])])])], + 'POST /api/v1/commits' => $answer ?? [['data' => commitJson(['id' => '0199e5c4-2222-7000-8000-00000000cafe', 'body' => 'From the org.', 'author' => memberOrganizationJson()])], 201], + ...$extra, + ]); + + return Native::visit('/log', platform: 'ios')->press('composeInSheet'); +} + +/** + * The JSON of the commits sent to devnull. + * + * @return list> + */ +function commitsSent(): array +{ + return collect(Http::recorded()) + ->filter(fn (array $sent): bool => $sent[0]->method() === 'POST' && str_ends_with(parse_url($sent[0]->url(), PHP_URL_PATH), '/commits')) + ->map(fn (array $sent): array => json_decode($sent[0]->body(), true)) + ->values() + ->all(); +} + +it('reads the organizations you can post as from GET /me, oldest membership first', function () { + $current = CurrentUser::fromArray(currentUserJson(['organizations' => [ + memberOrganizationJson(), + memberOrganizationJson(['id' => 'o2', 'handle' => 'nativephp', 'name' => 'NativePHP', 'role' => 'member', 'lane' => 5, 'type' => 'user']), + ['handle' => ''], + ]])); + + expect(array_map(fn (User $organization): array => [$organization->username, $organization->isOrganization, $organization->lane()], $current->organizations)) + ->toBe([['dev-null-sh', true, 'primary'], ['nativephp', true, 5]]) + ->and(CurrentUser::fromArray(currentUserJson())->organizations)->toBeNull(); +}); + +it('keeps the organizations GET /me lists, and what it had when devnull is too old to say', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([])], + 'GET /api/v1/me' => [currentUserJson(['organizations' => [memberOrganizationJson()]])], + ]); + + Native::visit('/log'); + + expect(array_map(fn (User $organization): string => $organization->username, app(Account::class)->organizations()))->toBe(['dev-null-sh']); + + app(Account::class)->rememberOrganizations(null); + + expect(app(Account::class)->organizations())->toHaveCount(1); + + app(Account::class)->forget(); + + expect(app(Account::class)->organizations())->toBe([]); +}); + +it('shows no Post as to someone in no organization, as the web hides it', function () { + composeOnLogAs() + ->assertSee('New commit') + ->assertMissingElement('pressable', fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-post-as'); +}); + +it('starts the composer as you, and lists you and your organizations under Post as', function () { + memberOf([memberOrganizationJson(), memberOrganizationJson(['id' => 'o2', 'handle' => 'nativephp', 'name' => 'NativePHP', 'role' => 'member', 'lane' => 5])]); + + $screen = composeOnLogAs(); + + expect(nodeByRef($screen, 'sheet-post-as-name')['props']['text'])->toBe('Local Dev') + ->and(nodeByRef($screen, 'sheet-post-as-handle')['props']['text'])->toBe('@local_dev') + ->and(nodeByRef($screen, 'sheet-post-as')['props']['a11y_label'])->toBe('Posting as @local_dev. Choose who to post as') + ->and(array_map(fn (array $item): array => [$item[0], $item[1]], menuItems($screen, 'sheet-post-as')))->toBe([ + ['post-as-local_dev', 'Local Dev (@local_dev)'], + ['post-as-dev-null-sh', '/dev/null (@dev-null-sh)'], + ['post-as-nativephp', 'NativePHP (@nativephp)'], + ]); + + $screen->call('postAsInSheet', 'nativephp'); + + expect(nodeByRef($screen, 'sheet-post-as-name')['props']['text'])->toBe('NativePHP') + ->and(nodeByRef($screen, 'sheet-post-as-handle')['props']['text'])->toBe('@nativephp') + ->and(nodeByRef($screen, 'sheet-post-as')['props']['a11y_label'])->toBe('Posting as @nativephp. Choose who to post as'); + + $screen->input('sheet-body', 'a'); + $organizationFill = sheetButtonCircle($screen, 'sheet-commit')['style']['bg_color']; + + // Commit is filled with the organization's lane rather than yours. + $screen->call('postAsInSheet', ''); + + expect(sheetButtonCircle($screen, 'sheet-commit')['style']['bg_color'])->not->toBe($organizationFill); +}); + +it('commits as the organization picked, and shows it staged as the organization', function () { + memberOf([memberOrganizationJson()]); + holdRefreshes(); + + $screen = composeOnLogAs() + ->call('postAsInSheet', 'dev-null-sh') + ->input('sheet-body', 'From the org.') + ->tap('sheet-commit'); + + $staged = $screen->instance()->commits[0]; + + expect($staged->isStaged())->toBeTrue() + ->and($staged->author->username)->toBe('dev-null-sh') + ->and($staged->author->isOrganization)->toBeTrue() + ->and(PendingWrite::query()->sole()->author())->toBe('dev-null-sh'); + + finishRefreshes($screen); + + expect(commitsSent())->toBe([['body' => 'From the org.', 'author' => 'dev-null-sh']]) + ->and($screen->instance()->commits[0]->author->username)->toBe('dev-null-sh'); +}); + +it('commits as you again once you pick yourself, and ignores an organization you are not in', function () { + memberOf([memberOrganizationJson()]); + + composeOnLogAs() + ->call('postAsInSheet', 'laravel') + ->assertSet('sheetAuthor', null) + ->call('postAsInSheet', 'dev-null-sh') + ->call('postAsInSheet', '') + ->input('sheet-body', 'From me.') + ->tap('sheet-commit'); + + expect(commitsSent())->toBe([['body' => 'From me.']]); +}); + +it('quotes as the organization picked', function () { + memberOf([memberOrganizationJson()]); + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'body' => 'Quote me', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])])])], + 'POST /api/v1/commits' => [['data' => commitJson(['id' => 'q1', 'body' => 'Our take', 'quoted_commit_id' => 'c1', 'author' => memberOrganizationJson()])], 201], + ]); + + $screen = Native::visit('/log', platform: 'ios')->call('quoteCommit', 'c1'); + + expect(rendersRef($screen, 'sheet-post-as'))->toBeTrue(); + + $screen->call('postAsInSheet', 'dev-null-sh')->input('sheet-body', 'Our take')->tap('sheet-commit'); + + expect(commitsSent())->toBe([['body' => 'Our take', 'quoted_commit_id' => 'c1', 'author' => 'dev-null-sh']]); +}); + +it('replies from the commit page as the organization picked in the bar', function () { + memberOf([memberOrganizationJson()]); + fakeApi([ + 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit']))], + 'GET /api/v1/commits/c2/replies' => [pageJson([])], + 'GET /api/v1/commits/c2/related' => [['data' => []]], + 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'From the org', 'author' => memberOrganizationJson()])], 201], + ]); + + $screen = Native::visit('/log/commits/c2'); + + expect(childRefs($screen, 'reply-row')[0])->toBe('reply-post-as') + ->and(array_column(menuItems($screen, 'reply-post-as'), 0))->toBe(['post-as-local_dev', 'post-as-dev-null-sh']); + + $screen->call('postAsInReply', 'dev-null-sh') + ->input('reply-input', 'From the org') + ->tap('send-reply') + ->assertSee('From the org'); + + expect(commitsSent())->toBe([['body' => 'From the org', 'parent_id' => 'c2', 'author' => 'dev-null-sh']]) + ->and($screen->instance()->replies[0]->author->username)->toBe('dev-null-sh'); +}); + +it('hands the bar\'s choice to the reply sheet and takes the sheet\'s back', function () { + memberOf([memberOrganizationJson()]); + fakeApi([ + 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit']))], + 'GET /api/v1/commits/c2/replies' => [pageJson([])], + 'GET /api/v1/commits/c2/related' => [['data' => []]], + 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Sheet reply'])], 201], + ]); + + $screen = Native::visit('/log/commits/c2', platform: 'ios') + ->call('postAsInReply', 'dev-null-sh') + ->call('replyInSheet', 'c2') + ->assertSet('sheetAuthor', 'dev-null-sh'); + + $screen->call('postAsInSheet', '')->assertSet('replyAuthor', null); + $screen->call('postAsInSheet', 'dev-null-sh')->input('sheet-body', 'Sheet reply')->tap('sheet-commit'); + + expect(commitsSent())->toBe([['body' => 'Sheet reply', 'parent_id' => 'c2', 'author' => 'dev-null-sh']]); +}); + +it('puts a commit turned down for leaving the organization back in the sheet, asks devnull again, and then posts as you', function () { + memberOf([memberOrganizationJson()]); + $refused = 'You can only post as an organization you are a member of.'; + $routes = [ + 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1'])])], + 'GET /api/v1/me' => [currentUserJson(['organizations' => [memberOrganizationJson()]])], + ]; + serveApi($routes); + + $screen = Native::visit('/log', platform: 'ios') + ->press('composeInSheet') + ->call('postAsInSheet', 'dev-null-sh') + ->input('sheet-body', 'From the org.'); + + // You were taken out of the organization since the app last asked. + serveApi([ + ...$routes, + 'POST /api/v1/commits' => [['message' => $refused, 'errors' => ['author' => [$refused]]], 422], + 'GET /api/v1/me' => [currentUserJson(['organizations' => []])], + ]); + + $screen->tap('sheet-commit') + ->assertNativeCalled('ToastKit.Show', fn (array $params): bool => $params['message'] === $refused && $params['variant'] === 'error'); + + expect(commitsSent())->toBe([['body' => 'From the org.', 'author' => 'dev-null-sh']]) + ->and(app(Account::class)->organizations())->toBe([]); + + // The sheet opens on the draft again, as the organization picked, which now posts as you. + $screen->dismissSheet('sheet'); + + expect($screen->instance()) + ->sheetOpen->toBeTrue() + ->sheetBody->toBe('From the org.') + ->sheetAuthor->toBe('dev-null-sh'); + expect(nodeByRef($screen, 'sheet-post-as-handle')['props']['text'])->toBe('@local_dev') + ->and(menuItems($screen, 'sheet-post-as'))->toHaveCount(1); + + serveApi([...$routes, 'POST /api/v1/commits' => [['data' => commitJson(['id' => 'c9', 'body' => 'From the org.'])], 201]]); + $screen->tap('sheet-commit'); + + expect(commitsSent())->toBe([['body' => 'From the org.', 'author' => 'dev-null-sh'], ['body' => 'From the org.']]); +}); + +it('schedules a commit as the organization picked, and lists it as the organization', function () { + phoneIn('Europe/Lisbon'); + $this->travelTo(CarbonImmutable::parse('2026-10-19 15:30:00', 'UTC')); + memberOf([memberOrganizationJson()]); + + composeOnLogAs(extra: [ + 'POST /api/v1/scheduled-commits' => [['data' => scheduledCommitJson(['author' => memberOrganizationJson()])], 201], + 'GET /api/v1/scheduled-commits' => [scheduledPageJson([scheduledCommitJson(['author' => memberOrganizationJson()]), scheduledCommitJson(['id' => 's2'])])], + ]) + ->call('postAsInSheet', 'dev-null-sh') + ->input('sheet-body', 'Shipping this tomorrow.') + ->tap('sheet-schedule') + ->pickDateTime('scheduled-at', '2026-10-20T09:00') + ->tap('sheet-commit'); + + Http::assertSent(fn (Request $request): bool => $request->method() === 'POST' + && str_ends_with($request->url(), '/scheduled-commits') + && $request['author'] === 'dev-null-sh'); + + $list = Native::visit('/log/scheduled'); + + expect(rendersRef($list, 'scheduled-author-0199e5c4-3333-7000-8000-00000000da7e'))->toBeTrue() + ->and(rendersRef($list, 'scheduled-author-s2'))->toBeFalse(); + $list->assertSee('As @dev-null-sh'); +}); From a5d112cd2d80a03502def696c5aa6adef3f173b6 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 00:34:38 +0000 Subject: [PATCH 05/30] Reply with photos and a preview from the bar, and drop any time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reply bar no longer has the expand button or grows in place, and it never opens the composer sheet. Its row has a photo button (a menu with the library and the camera) and Preview. Photos show above the field with their ✕ and ALT, go in the reply's stash, and send with it. Preview shows the reply as it will look in the field's place, with the body devnull keeps, and pressed again brings the field back with the keyboard. The field grows with the reply to five lines and then scrolls. Nothing in PHP changes its line limits any more. Drop shows beside Reply as soon as the reply has anything in it, so a draft can be thrown away at any time. stash@{0} still marks a draft that came back from the stash. Both moved into the row, so the bar no longer gets taller for them. The page fades out above the bar, as Remotes does, from the stack now around its scroll view. composer-preview takes its draft as parameters so the sheet and the bar share it. The expand icons are gone. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/ComposerMenu.php | 14 ++ app/Devnull/Display.php | 40 +++-- app/Icons/Lucide.php | 4 - app/NativeComponents/CommitDetail.php | 128 +++++++++++++--- resources/icons/maximize-2.svg | 1 - resources/icons/minimize-2.svg | 1 - .../views/native/commit-detail.blade.php | 82 ++++++----- .../native/partials/commit-sheet.blade.php | 10 +- .../partials/composer-preview.blade.php | 20 ++- .../native/partials/reply-field.blade.php | 9 +- .../native/partials/reply-preview.blade.php | 19 +++ .../native/partials/stash-label.blade.php | 10 +- tests/Feature/Screens/CommitDetailTest.php | 116 +++++++++------ tests/Feature/Screens/ComposerPhotosTest.php | 139 +++++++++--------- tests/Feature/Screens/DraftStashTest.php | 10 +- 15 files changed, 383 insertions(+), 220 deletions(-) delete mode 100644 resources/icons/maximize-2.svg delete mode 100644 resources/icons/minimize-2.svg create mode 100644 resources/views/native/partials/reply-preview.blade.php diff --git a/app/Devnull/ComposerMenu.php b/app/Devnull/ComposerMenu.php index 71e5716e..533a0303 100644 --- a/app/Devnull/ComposerMenu.php +++ b/app/Devnull/ComposerMenu.php @@ -28,6 +28,20 @@ public static function items(bool $photosFull, bool $voiceNotesGoAlone, string $ ]; } + /** + * What the photo button in the reply bar on a commit's page opens: the photo library, or the camera, as the + * composer sheet's two photo buttons do. + * + * @return list + */ + public static function photoItems(): array + { + return [ + self::item('reply-pick-photos', 'Choose photos', Lucide::ImagePlus, 'pickPhotos'), + self::item('reply-take-photo', 'Take a photo', Lucide::Camera, 'takePhoto'), + ]; + } + private static function item(string $ref, string $label, Lucide $icon, string $method, bool $disabled = false): TopBarAction { return NavAction::make($ref) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index 2c3515d9..42b339ef 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -19,17 +19,12 @@ final class Display public const int ReplyBarMaxLines = 5; /** - * The reply box on a commit's page grown by its expand button: it starts this many lines tall, and grows to - * ExpandedReplyMaxLines. + * The photos on a reply's draft, above the field in the reply bar (see partials/composer-photos), and the + * description of one under them while it's open. */ - public const int ExpandedReplyMinLines = 8; + public const int ReplyBarPhotosHeight = 88; - public const int ExpandedReplyMaxLines = 12; - - /** - * The row under the reply box that marks a restored draft (see partials/stash-label). - */ - public const int ReplyBarStashLabelHeight = 28; + public const int ReplyBarDescriptionHeight = 100; /** * A bar holding partials/composer-box with one line of draft, as drawn on an iPhone: the bar's padding, then the @@ -235,22 +230,21 @@ public static function maskedKey(string $openSsh): string * How far a commit page has to scroll past its last reply to clear the * reply bar. A pushed screen is drawn under its bottom bar and the home * indicator, with no inset for either, so the page pads its own end: the - * bar (partials/composer-box) as the draft grows to its five lines, and - * the indicator below it. With the keyboard up the bar sits on the - * keyboard instead, which only leaves a little more room. Grown by its - * expand button ($expanded), the box is ExpandedReplyMinLines tall to - * start with. A restored draft adds the row under the box that marks it - * ($restored), and a link too long for devnull the line that says so. + * fade over its foot (partials/composer-fade), the bar + * (partials/composer-box) as the draft grows to its five lines, and the + * indicator below it. With the keyboard up the bar sits on the keyboard + * instead, which only leaves a little more room. Photos on the draft add + * their row above the field ($hasPhotos), and an open description of one + * its box under them ($describing). A link too long for devnull adds the + * line that says so. */ - public static function replyBarClearance(string $draft, bool $expanded = false, bool $restored = false): int + public static function replyBarClearance(string $draft, bool $hasPhotos = false, bool $describing = false): int { - $lines = $expanded - ? max(self::ExpandedReplyMinLines, min(self::ExpandedReplyMaxLines, self::lineCount($draft, self::ComposerBoxCharactersPerLine))) - : null; - - return self::ComposerBoxBarHeight - + ($lines === null ? self::composerBoxGrowth($draft) : ($lines - 1) * self::ReplyBarLineHeight) - + ($restored ? self::ReplyBarStashLabelHeight : 0) + return self::ComposerFadeHeight + + self::ComposerBoxBarHeight + + self::composerBoxGrowth($draft) + + ($hasPhotos ? self::ReplyBarPhotosHeight : 0) + + ($hasPhotos && $describing ? self::ReplyBarDescriptionHeight : 0) + (CommitBody::hasOversizedUrl($draft) ? 3 * self::ReplyBarLineHeight : 0) + self::HomeIndicatorHeight; } diff --git a/app/Icons/Lucide.php b/app/Icons/Lucide.php index b6e5c0e1..3df5fa55 100644 --- a/app/Icons/Lucide.php +++ b/app/Icons/Lucide.php @@ -73,8 +73,6 @@ enum Lucide case Eye; case EyeOff; case Plus; - case Maximize2; - case Minimize2; case Vibrate; // The achievement badges, named as devnull names their icons (see forBadge()). @@ -214,8 +212,6 @@ public function custom(bool $filled = false): string self::Eye => 'eye', self::EyeOff => 'eye-off', self::Plus => 'plus', - self::Maximize2 => 'maximize-2', - self::Minimize2 => 'minimize-2', self::Vibrate => 'vibrate', self::Terminal => 'terminal', self::FileCode => 'file-code', diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 0647820f..169606fd 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -18,10 +18,12 @@ use App\Devnull\RowCache; use App\Devnull\Stash; use App\Devnull\Timeline; +use App\Devnull\Toasts; use App\Icons\Lucide; use App\Models\PendingWrite; use App\NativeComponents\Concerns\OpensInTab; use App\NativeComponents\Concerns\OpensLiveStream; +use App\NativeComponents\Concerns\RedrawsOnAppearanceChange; use App\NativeComponents\Concerns\RefreshesInBackground; use App\NativeComponents\Concerns\ShowsCommits; use App\NativeComponents\Concerns\TalksToDevnull; @@ -49,17 +51,16 @@ * * The reply is stashed as you type, per commit, as on the web (see Stash), so * leaving the page keeps it, and it's in the reply bar again, marked as - * restored, when you come back to the commit. + * restored, when you come back to the commit. Drop throws it away whenever + * there's anything in it. * - * The reply bar's expand button gives the reply more room where it is: the - * box grows taller over the page, with the same field in it, so the keyboard - * stays up (see toggleReplyExpanded()). A sheet can't do that: presenting - * one takes the keyboard down and puts it back up on both platforms, however - * soon its field takes focus. Grown, the box has the photos and preview - * button, which opens the reply in the composer sheet (see replyInSheet()). - * The draft goes with it, and back to the bar if the sheet closes unsent. - * Photos left in it show as a count in the box, which opens the sheet on - * them, and Reply in the bar sends them with the text. + * The reply bar does everything the composer sheet did for a reply, so a + * reply never needs the sheet: presenting one takes the keyboard down and + * puts it back up on both platforms, however soon its field takes focus. + * Photos come from the library or the camera into the bar, above the field, + * each with its ✕ and ALT (see AttachesPhotos), and Preview shows the reply + * as it will look in the field's place (see toggleReplyPreview()). Reply in + * the bar sends them all. * * Related commits wait under a header with their count, closed, and open * in place when it's tapped (see toggleRelated()). @@ -75,11 +76,16 @@ class CommitDetail extends NativeComponent { use OpensInTab; use OpensLiveStream; + use RedrawsOnAppearanceChange; use RefreshesInBackground; use ShowsCommits { reopenFailedCommit as private reopenFailedCommitInSheet; editFailedCommit as private editFailedCommitInSheet; mentionFields as private sheetMentionFields; + attachedPhotos as private sheetPhotos; + photosChanged as private sheetPhotosChanged; + takesPhotos as private sheetTakesPhotos; + photoFailed as private sheetPhotoFailed; } use TalksToDevnull; @@ -110,9 +116,16 @@ class CommitDetail extends NativeComponent public array $related = []; /** - * Whether the reply box has grown to give the reply more room. + * Whether the reply bar shows the reply as it will look, in the field's place. */ - public bool $replyExpanded = false; + public bool $replyPreviewing = false; + + /** + * What devnull sent back for the reply's body, with the body it was for under `draft`. + * + * @var array|null + */ + public ?array $replyPreview = null; /** * Whether the related commits show under their header. @@ -317,13 +330,34 @@ public function toggleReplies(): void } /** - * The expand button in the reply box: the box grows taller where it is, - * the same field in it, so the keyboard stays where it was, and again it - * shrinks back. + * The web's preview toggle, in the reply bar: the reply shows as it will + * look in the field's place, at once, and devnull is asked for its body, + * with its code and mentions, unless it already said for this one. The + * keyboard goes down with the field. Pressed again, the field comes back + * with the keyboard. */ - public function toggleReplyExpanded(): void + public function toggleReplyPreview(): void { - $this->replyExpanded = ! $this->replyExpanded; + $this->replyPreviewing = ! $this->replyPreviewing; + $this->describing = null; + + if (! $this->replyPreviewing) { + $this->focusReply = true; + + return; + } + + $body = trim($this->reply); + + if ($body === '' || ($this->replyPreview['draft'] ?? null) === $body) { + return; + } + + $this->writeInBackground('POST', Client::PreviewPath, ['body' => $body], function (array $json) use ($body): void { + if (is_array($json['data'] ?? null)) { + $this->replyPreview = [...$json['data'], 'draft' => $body]; + } + }, fn (): null => null); } /** @@ -439,7 +473,8 @@ public function sendReply(): void $this->reply = ''; $this->replyImages = []; - $this->replyExpanded = false; + $this->replyPreviewing = false; + $this->replyPreview = null; $this->forgetMention('reply'); $this->updatedReply(); $this->repliesShown = true; @@ -473,13 +508,17 @@ public function updatedReply(): void } /** - * The web's drop, beside a restored reply: it's thrown away, photos too, and the field starts again empty. + * The web's drop, beside the reply while there's anything in it: it's thrown away, photos too, and the field + * starts again empty. */ public function dropReplyStash(): void { app(DraftImages::class)->discard($this->replyImages); $this->reply = ''; $this->replyImages = []; + $this->replyPreviewing = false; + $this->replyPreview = null; + $this->describing = null; $this->updatedReply(); } @@ -552,6 +591,57 @@ protected function editFailedCommit(PendingWrite $write): void $this->takeFailedReply($write); } + /** + * The photos on the draft being written: the sheet's while it's up, otherwise the reply bar's. + * + * @return list + */ + protected function attachedPhotos(): array + { + return $this->sheetOpen ? $this->sheetPhotos() : $this->replyImages; + } + + /** + * Photos added in the reply bar, or taken off it, go in the reply's stash with its text. + * + * @param list $photos + */ + protected function photosChanged(array $photos): void + { + if ($this->sheetOpen) { + $this->sheetPhotosChanged($photos); + + return; + } + + $this->replyImages = $photos; + $this->updatedReply(); + } + + /** + * A reply can have photos, as on the web, unless its commit has gone. + */ + protected function takesPhotos(): bool + { + return $this->sheetOpen ? $this->sheetTakesPhotos() : $this->commit !== null && ! $this->commit->isDeleted(); + } + + /** + * Why a photo won't do comes as a toast, from the top, clear of the reply bar, as it does in Remotes. + */ + protected function photoFailed(?string $error): void + { + if ($this->sheetOpen) { + $this->sheetPhotoFailed($error); + + return; + } + + if ($error !== null) { + Toasts::failed($error); + } + } + /** * The reply bar takes back the draft it handed the sheet, as it was left there, photos too. */ diff --git a/resources/icons/maximize-2.svg b/resources/icons/maximize-2.svg deleted file mode 100644 index 12b88ce8..00000000 --- a/resources/icons/maximize-2.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/icons/minimize-2.svg b/resources/icons/minimize-2.svg deleted file mode 100644 index f3cb0e4b..00000000 --- a/resources/icons/minimize-2.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index fd724368..6469c124 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -5,7 +5,9 @@ @include('native.partials.live-stream-sheet') @include('native.partials.stargazers-sheet') - + {{-- The stack around the page holds the fade over its foot, just above the reply bar (see partials/composer-fade). --}} + + @if (! $commit && $error === null) @@ -105,60 +107,69 @@ {{-- A pushed screen runs under its bottom bar, so the page clears the reply bar itself (see - Display::replyBarClearance): the last reply and its actions end above the bar, keyboard up or down. + Display::replyBarClearance): the last reply and its actions end above the fade and the bar, keyboard + up or down. --}} @if ($commit) - + @endif + @if ($commit) + @include('native.partials.composer-fade', ['ref' => 'reply-fade']) + @endif + + @if ($commit) {{-- - The reply bar, drawn as the Remotes composer is: one rounded box with the field across the top and a row - under it with the tools on the left and the round send button on the right (see partials/composer-box). The - bar is Liquid Glass tinted with the surface on iOS, so the thread scrolling under it blurs, and the solid - surface with a hairline on Android. native:bottom-bar takes no classes of its own, so the bar is painted - from this column. + The reply bar, drawn as the Remotes composer is: the field across the top and a row under it with the + tools on the left and the round send button on the right (see partials/composer-box), straight on the + surface, with the page fading out above it. native:bottom-bar takes no classes of its own, so the bar is + painted from this column, which also fills the strip under the home indicator. + + The bar does everything the composer sheet did for a reply, so a reply never needs the sheet, whose + presenting takes the keyboard down and back up on both platforms. The photo button adds photos from the + library or the camera, which show above the field with their ✕ and ALT. Preview shows the reply as it will + look in the field's place, and pressed again brings the field back. Beside the send button, drop throws + the draft away whenever there's anything in it, after the web's stash@{0} when the draft came back from + the stash, then how long the reply is near the limit. - The expand button grows the box where it is, the same field in it, so the keyboard stays up, and shrinks - it back. A sheet can't take the reply over with the keyboard up: presenting one takes the keyboard down - and back up on both platforms. Grown, the box also has the button for photos and a preview, which opens - the reply in the composer sheet, and once the sheet has put photos on the draft, their count opens the - sheet on them. Beside the send button, how long the reply is. A reply that came back when you returned to - the commit has the web's stash@{0} and drop under the box, on a row of its own, since the box's row has no - room left for it once it has grown. + A "post as" avatar, for people in a GitHub organization, goes at the start of the row as composer-box's + $lead. --}} - - + {{-- - The people to mention keep a slot above the box, empty and 0.1pt tall when there's no one, so the - box's row never moves. Android rebuilds a row that moves among its siblings, field and all, which - drops the keyboard. On iOS an empty slot would otherwise take 10pt of the bar, and EDGE drops a - height of 0. + The people to mention and the photos on the reply keep a slot each above the field, empty and + 0.1pt tall when there's nothing in it, so the field's row never moves. Android rebuilds a row that + moves among its siblings, field and all, which drops the keyboard. On iOS an empty slot would + otherwise take 10pt of the bar, and EDGE drops a height of 0. --}} @php($mentioning = ($mention['field'] ?? null) === 'reply' && ($mentionPeople !== [] || $mentionOrganizations !== [])) @include('native.partials.mention-suggestions', ['field' => 'reply', 'label' => 'Mention a developer']) + @php($showsPhotos = $replyImages !== [] && ! $replyPreviewing) + + @if ($showsPhotos) + @include('native.partials.composer-photos', ['photos' => $replyImages, 'photoRef' => 'reply-photo']) + @endif + - @php($photoCount = $replyImages === [] ? null : \App\Devnull\Display::count(count($replyImages), 'photo', 'photos')) + @php($hasDraft = trim($reply) !== '' || $replyImages !== []) + @php($photosFull = count($replyImages) >= \App\Devnull\DraftImages::MaxImages) @include('native.partials.composer-box', [ 'ref' => 'reply', - 'field' => 'native.partials.reply-field', + 'field' => $replyPreviewing ? 'native.partials.reply-preview' : 'native.partials.reply-field', 'tools' => [ - $replyExpanded - ? ['ref' => 'reply-expand', 'icon' => \App\Icons\Lucide::Minimize2, 'label' => 'Give the reply less room', 'press' => 'toggleReplyExpanded'] - : ['ref' => 'reply-expand', 'icon' => \App\Icons\Lucide::Maximize2, 'label' => 'Give the reply more room', 'press' => 'toggleReplyExpanded'], - ...($replyExpanded ? [ - ['ref' => 'reply-attach', 'icon' => \App\Icons\Lucide::ImagePlus, 'label' => 'Reply with photos or a preview', 'press' => "replyInSheet('{$commit->id}')"], - ] : []), - ...($photoCount === null ? [] : [ - ['ref' => 'reply-photos', 'icon' => \App\Icons\Lucide::ImagePlus, 'text' => $photoCount, 'label' => $photoCount.' attached', 'hint' => 'Opens the reply with its photos', 'press' => "replyInSheet('{$commit->id}')"], - ]), + ['ref' => 'reply-add-photos', 'icon' => \App\Icons\Lucide::ImagePlus, 'label' => $photosFull ? 'A reply can have up to 3 photos' : 'Add photos', 'menu' => $photosFull ? null : \App\Devnull\ComposerMenu::photoItems(), 'disabled' => $photosFull], + ['ref' => 'reply-preview', 'icon' => \App\Icons\Lucide::Eye, 'label' => $replyPreviewing ? 'Edit' : 'Preview', 'press' => 'toggleReplyPreview', 'active' => $replyPreviewing], + ], + 'trail' => [ + ...($hasDraft ? [['native.partials.stash-label', ['ref' => 'reply-stash', 'drop' => 'dropReplyStash', 'size' => 'text-xs', 'restored' => $replyRestored]]] : []), + ['native.partials.body-counter', ['body' => $reply, 'ref' => 'reply-budget']], ], - 'trail' => [['native.partials.body-counter', ['body' => $reply, 'ref' => 'reply-budget']]], 'send' => [ 'ref' => 'send-reply', 'label' => 'Reply', @@ -167,11 +178,6 @@ ], ]) - @if ($replyRestored) - - @include('native.partials.stash-label', ['ref' => 'reply-stash', 'drop' => 'dropReplyStash', 'size' => 'text-xs']) - - @endif @if (\App\Devnull\Data\CommitBody::hasOversizedUrl($reply)) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. @endif diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index 97a5b0b1..d30a12ee 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -79,7 +79,15 @@ @endif @if ($previewing) - @include('native.partials.composer-preview') + @include('native.partials.composer-preview', [ + 'ref' => 'sheet-draft', + 'body' => $sheetBody, + 'preview' => $sheetPreview, + 'images' => $sheetImages, + 'poll' => $replying ? null : $sheetPoll, + 'pollLength' => $sheetPollLength, + 'quoted' => $quoting ? $sheetCommit : null, + ]) @else user() ?? \App\Devnull\Data\User::fromArray([]), $sheetBody, $sheetPreview, $sheetImages, $sheetView === 'reply' ? null : $sheetPoll, $sheetView === 'quote' ? $sheetCommit : null)) - - @if (trim($sheetBody) === '' && $sheetImages === [] && $sheetPoll === null) +@php($draftCommit = \App\Devnull\Data\Draft::asCommit($me ?? app(\App\Devnull\Account::class)->user() ?? \App\Devnull\Data\User::fromArray([]), $body, $preview, $images, $poll, $quoted)) + + @if (trim($body) === '' && $images === [] && $poll === null) Nothing to preview yet. @else @include('native.partials.commit-body', ['commit' => $draftCommit, 'focused' => true, 'static' => true]) @include('native.partials.commit-media', ['commit' => $draftCommit, 'withEmbeds' => false, 'scoreAction' => false]) @if ($draftCommit->poll) - + @foreach ($draftCommit->poll->options as $option) {{ $option->label }} @endforeach - {{ \App\Devnull\Data\PollDraft::runs($sheetPollLength) }} + {{ \App\Devnull\Data\PollDraft::runs($pollLength) }} @endif @if ($draftCommit->quotedCommit) diff --git a/resources/views/native/partials/reply-field.blade.php b/resources/views/native/partials/reply-field.blade.php index 6400973d..1879f43a 100644 --- a/resources/views/native/partials/reply-field.blade.php +++ b/resources/views/native/partials/reply-field.blade.php @@ -1,10 +1,10 @@ {{-- The reply bar's field on a commit's page, across the top of partials/composer-box. EDGE sends no focus event, so a - press on the field is how the page learns you're replying. The expand button is in the row under it, so pressing it + press on the field is how the page learns you're replying. The tools are in the row under it, so pressing them doesn't count. Where the caret is goes to the page as it moves, for the "@" suggestions above the bar (see SuggestsMentions). It keeps the keyboard up through presses elsewhere on the page (keep-focus), as the Remotes - field does, so picking someone to mention leaves you typing after them. The expand button grows it to - Display::ExpandedReplyMinLines tall: the same field, only taller, so the keyboard doesn't move. + field does, so picking someone to mention leaves you typing after them. It grows with the reply to five lines and + then scrolls, sized by the field itself, not by the page. --}} diff --git a/resources/views/native/partials/reply-preview.blade.php b/resources/views/native/partials/reply-preview.blade.php new file mode 100644 index 00000000..31ba70ad --- /dev/null +++ b/resources/views/native/partials/reply-preview.blade.php @@ -0,0 +1,19 @@ +{{-- + The reply as it will look, in the reply bar's field's place, while Preview is on (see CommitDetail::toggleReplyPreview()): + its body as devnull keeps it, with its photos. Held to about half a screen, and scrolls past that, so a long reply + doesn't push the commit off the top. +--}} + + + @include('native.partials.composer-preview', [ + 'ref' => 'reply-draft', + 'body' => $reply, + 'preview' => $replyPreview, + 'images' => $replyImages, + 'poll' => null, + 'pollLength' => \App\Devnull\Data\PollDraft::DefaultLength, + 'quoted' => null, + 'me' => $viewer, + ]) + + diff --git a/resources/views/native/partials/stash-label.blade.php b/resources/views/native/partials/stash-label.blade.php index b455da5c..a91815bb 100644 --- a/resources/views/native/partials/stash-label.blade.php +++ b/resources/views/native/partials/stash-label.blade.php @@ -1,11 +1,15 @@ {{-- The web's StashLabel, beside a draft that was stashed and has come back: stash@{0} in mono, then drop, which throws - the draft away. $drop is what drop presses, and drop is a full 44pt target. + the draft away. $drop is what drop presses, and drop is a full 44pt target. With $restored false, the draft is one + you're writing now, so there's no stash@{0}, only drop. --}} @php($size ??= 'text-[13px]') +@php($restored ??= true) - {{ 'stash@{0}' }} - + @if ($restored) + {{ 'stash@{0}' }} + @endif + drop diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 3c5ea1b3..45ef0fd2 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -107,7 +107,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->and(idsDownTo($screen->tree(), 'reply-input'))->toBe($field); }); -it('draws the reply bar as one box, the field over the expand button and a round Reply, on both platforms', function (string $platform) { +it('draws the reply bar with the field over the photo and preview buttons and a round Reply, on both platforms', function (string $platform) { fakeThread(); $screen = Native::visit('/log/commits/c2', platform: $platform); @@ -116,9 +116,11 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(childRefs($screen, 'reply-row'))->toBe(['reply-box']) ->and(childRefs($screen, 'reply-box'))->toBe(['reply-field-row', 'reply-actions']) ->and(childRefs($screen, 'reply-field-row'))->toBe(['reply-field']) - ->and($actions[0])->toBe('reply-expand') + ->and(array_slice($actions, 0, 2))->toBe(['reply-add-photos', 'reply-preview']) ->and(end($actions))->toBe('send-reply') + ->and(array_column(menuItems($screen, 'reply-add-photos'), 0))->toBe(['reply-pick-photos', 'reply-take-photo']) ->and(nodeByRef($screen, 'send-reply')['props']['a11y_label'] ?? nodeByRef($screen, 'send-reply')['a11y_label'] ?? null)->toBe('Reply') + ->and(rendersRef($screen, 'reply-expand'))->toBeFalse() ->and(canSend($screen, 'send-reply'))->toBeFalse(); $screen->input('reply-input', 'Ready'); @@ -126,46 +128,74 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(canSend($screen, 'send-reply'))->toBeTrue(); })->with(['ios', 'android']); -it('grows the reply box where it is for more room, keeping the same field so the keyboard stays up', function (string $platform) { +it('keeps the same field, up to five lines and then scrolling, however long the reply grows', function (string $platform) { fakeThread(); - $screen = Native::visit('/log/commits/c2', platform: $platform)->input('reply-input', 'A long one'); + $screen = Native::visit('/log/commits/c2', platform: $platform)->input('reply-input', 'A short one'); $field = idsDownTo($screen->tree(), 'reply-input'); - $clearance = nodeByRef($screen, 'reply-bar-clearance')['layout']['height']; - expect(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(5) - ->and(rendersRef($screen, 'reply-attach'))->toBeFalse(); - - $screen->tap('reply-expand'); + $screen->input('reply-input', str_repeat("A line of a long reply\n", 12)); + // The field sizes itself: the page only says how many lines it can take, which never changes as you type. expect(idsDownTo($screen->tree(), 'reply-input'))->toBe($field) - ->and(nodeByRef($screen, 'reply-input')['props']['min_lines'])->toBe(8) - ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(12) - ->and(nodeByRef($screen, 'reply-expand')['props']['a11y_label'] ?? null)->toBe('Give the reply less room') - ->and(childRefs($screen, 'reply-actions')[1])->toBe('reply-attach') - ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse() - ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance + 7 * 21); + ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(Display::ReplyBarMaxLines) + ->and(nodeByRef($screen, 'reply-input')['props']['min_lines'] ?? null)->toBeNull() + ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse(); +})->with(['ios', 'android']); - // Photos and a preview are a tap further, in the composer sheet, with the draft. - $screen->tap('reply-attach'); +it('previews the reply in the field\'s place, with the body devnull keeps, and brings the field back with the keyboard', function () { + fakeThread(extra: ['POST /api/v1/commits/preview' => [['data' => [ + 'body' => 'Shipped 🚀 with @ada', + 'body_segments' => [['type' => 'text', 'text' => 'Shipped 🚀 with @ada']], + 'preview_segments' => null, + 'mentions' => [['handle' => 'ada', 'offset' => 15, 'length' => 4]], + ]]]]); + $screen = Native::visit('/log/commits/c2')->input('reply-input', 'Shipped :rocket: with @ada'); + holdRefreshes(); + $screen->tap('reply-preview'); - expect(nodeByRef($screen, 'sheet')['props']['visible'])->toBeTrue() - ->and($screen->instance()->sheetBody)->toBe('A long one'); + // At once, the reply as written, in the field's place, while devnull is asked. The sheet never opens. + expect(rendersRef($screen, 'reply-input'))->toBeFalse() + ->and(childRefs($screen, 'reply-field-row'))->toBe(['reply-preview-pane']) + ->and(nodeByRef($screen, 'reply-preview')['props']['a11y_label'])->toBe('Edit') + ->and(treeShows(nodeByRef($screen, 'reply-draft-preview'), 'Shipped :rocket: with @ada'))->toBeTrue() + ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse(); - $screen->dismissSheet('sheet')->tap('reply-expand'); + finishRefreshes($screen); - expect(idsDownTo($screen->tree(), 'reply-input'))->toBe($field) - ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(5) - ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance); -})->with(['ios', 'android']); + expect(treeShows(nodeByRef($screen, 'reply-draft-preview'), 'Shipped 🚀 with '))->toBeTrue() + ->and(canSend($screen, 'send-reply'))->toBeTrue(); -it('shrinks the grown reply box back once the reply is sent', function () { - fakeThread(extra: ['POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Sent'])], 201]]); + Http::assertSent(fn (Request $request): bool => str_ends_with($request->url(), '/api/v1/commits/preview') + && $request->body() === '{"body":"Shipped :rocket: with @ada"}'); - $screen = Native::visit('/log/commits/c2')->tap('reply-expand')->input('reply-input', 'Sent')->tap('send-reply'); + $screen->tap('reply-preview'); - expect($screen->instance()->replyExpanded)->toBeFalse() - ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(5); + expect(nodeByRef($screen, 'reply-input')['props'])->toMatchArray(['value' => 'Shipped :rocket: with @ada', 'autofocus' => true]) + ->and(nodeByRef($screen, 'reply-preview')['props']['a11y_label'])->toBe('Preview'); +}); + +it('shows a drop beside Reply as soon as the reply has anything in it, which throws it away', function () { + fakeThread(); + + $screen = Native::visit('/log/commits/c2'); + + expect(rendersRef($screen, 'reply-stash'))->toBeFalse(); + + $screen->input('reply-input', 'Not this after all'); + $actions = childRefs($screen, 'reply-actions'); + + // A draft you're writing now has drop alone. Only one that came back from the stash says stash@{0}. + expect(array_slice($actions, -2))->toBe(['reply-stash', 'send-reply']) + ->and(childRefs($screen, 'reply-stash'))->toBe(['reply-stash-drop']) + ->and(nodeByRef($screen, 'reply-stash-drop')['props']['a11y_label'] ?? null)->toBe('Discard the draft'); + + $screen->tap('reply-stash-drop'); + + expect($screen->instance()->reply)->toBe('') + ->and(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('') + ->and(rendersRef($screen, 'reply-stash'))->toBeFalse() + ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); }); it('says nothing about a long reply being folded in feeds, beside Reply or in the sheet, and still counts down near the limit', function () { @@ -835,21 +865,21 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(pressFeedbackInScroller($screen))->toBe([]); }); -it('puts the reply bar on Liquid Glass tinted with the surface on iOS, and on the solid surface on Android', function () { +it('puts the reply bar on the surface with no glass or line, and fades the page out above it, on both platforms', function (string $platform) { fakeThread(); - $ios = Native::visit('/log/commits/c2', platform: 'ios'); - $android = Native::visit('/log/commits/c2', platform: 'android'); - $bar = findNode($android->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); + $screen = Native::visit('/log/commits/c2', platform: $platform); + $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); + $surface = strtoupper(config('native-ui.theme.light.surface')); - expect(nodeByRef($ios, 'reply-bar')['props']['glass'] ?? null)->toBe(1) - ->and(nodeByRef($ios, 'reply-bar')['style']['bg_color'] ?? null)->not->toBeNull() - ->and($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') + expect($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') ->and($bar['children'][0]['props']['glass'] ?? null)->toBeNull() ->and($bar['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) ->and($bar['children'][0]['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) - ->and($bar['children'][0]['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.hairline')); -}); + ->and(childRefs($screen, 'reply-bar')[0])->toBe('reply-mention-slot') + ->and(childRefs($screen, 'thread-stack'))->toBe(['thread-scroll', 'reply-fade']) + ->and(str_ends_with(nodeByRef($screen, 'reply-fade')['props']['gradient_stops'] ?? '', $surface))->toBeTrue(); +})->with(['ios', 'android']); it('ends the page above the reply bar, and further as the draft grows', function () { fakeThread(replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'The last reply'])]); @@ -858,15 +888,17 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $scroller = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'scroll_view'); $page = $scroller['children'][0]['children']; - // The clearance is the last thing on the page, under the last reply: the bar's line and the home indicator. + // The clearance is the last thing on the page, under the last reply: the fade, the bar and the home indicator. + $bar = 24 + Display::ComposerFadeHeight + Display::ComposerBoxBarHeight + 34; + expect(end($page)['ref'] ?? null)->toBe('reply-bar-clearance') - ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + Display::ComposerBoxBarHeight + 34); + ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($bar); $screen->input('reply-input', "Three lines\nof a\ndraft"); - expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + Display::ComposerBoxBarHeight + 2 * 21 + 34); + expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($bar + 2 * 21); $screen->input('reply-input', str_repeat("A line\n", 12)); - expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + Display::ComposerBoxBarHeight + 4 * 21 + 34); + expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($bar + 4 * 21); }); diff --git a/tests/Feature/Screens/ComposerPhotosTest.php b/tests/Feature/Screens/ComposerPhotosTest.php index 81d2bd8a..4ea4abd0 100644 --- a/tests/Feature/Screens/ComposerPhotosTest.php +++ b/tests/Feature/Screens/ComposerPhotosTest.php @@ -228,107 +228,106 @@ function isTool(TestableComponent $screen, string $ref): bool ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); }); -it('opens a commit\'s reply in the sheet with what the reply bar had, and replies with photos', function () { +/** + * The commit page for c2, by Ada, which a reply can be sent to. + */ +function replyPage(string $platform = 'ios'): TestableComponent +{ serveApi([ 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])]))], 'GET /api/v1/commits/c2/replies' => [pageJson([])], - 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Here it is'])], 201], + 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Look'])], 201], ]); - $screen = Native::visit('/log/commits/c2') - ->input('reply-input', 'Here it') - ->tap('reply-expand')->tap('reply-attach') - ->assertSee('Reply to @ada'); - - expect(nodeByRef($screen, 'sheet-body')['props'])->toMatchArray(['value' => 'Here it', 'placeholder' => 'Reply to @ada']) - ->and(nodeByRef($screen, 'quote-card')['props']['a11y_label'])->toBe('Replying to Ada') - ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-stash'))->toBeNull() - ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-poll'))->toBeNull() - ->and(nodeByRef($screen, 'sheet-commit')['props']['a11y_label'] ?? null)->toBe('Reply'); - - photosPicked($screen, [testPhoto()]) - ->input('sheet-body', 'Here it is') - ->tap('sheet-commit') - ->dismissSheet('sheet') - ->assertSee('Here it is'); + return Native::visit('/log/commits/c2', platform: $platform); +} - Http::assertSent(fn (Request $request): bool => $request->method() === 'POST' && multipartParts($request)[0]['contents'] === '{"body":"Here it is","parent_id":"c2"}'); +it('adds photos to a reply from the bar, from the library or the camera, without the sheet', function () { + $screen = replyPage()->input('reply-input', 'Look')->tap('reply-pick-photos'); - expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->replies))->toBe(['r9']) - ->and($screen->instance()->reply)->toBe('') - ->and(nodeByRef($screen, 'reply-input')['props']['value'])->toBe(''); -}); + $screen->assertNativeCalled('Camera.PickMedia', fn (array $params): bool => $params['mediaType'] === 'images' && $params['multiple'] === true && $params['maxItems'] === 3); -it('hands the reply back to the reply bar when the sheet goes unsent', function () { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - ]); + photosPicked($screen, [testPhoto()])->tap('reply-take-photo')->assertNativeCalled('Camera.GetPhoto'); + $screen->emitNative(PhotoTaken::class, ['path' => testPhoto('jpg', 30, 40), 'mimeType' => 'image/jpeg']); - $screen = Native::visit('/log/commits/c2') - ->input('reply-input', 'Half') - ->tap('reply-expand')->tap('reply-attach') - ->input('sheet-body', 'Half a reply') - ->dismissSheet('sheet'); + // They show above the field, which keeps its place, and go in the reply's stash with its text. + expect($screen->instance()->replyImages)->toHaveCount(2) + ->and(childRefs($screen, 'reply-bar'))->toBe(['reply-mention-slot', 'reply-photos-slot', 'reply-row']) + ->and(nodeByRef($screen, 'reply-photo-0'))->not->toBeNull() + ->and(nodeByRef($screen, 'reply-photo-1'))->not->toBeNull() + ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse() + ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(2); - expect(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('Half a reply') - ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->body)->toBe('Half a reply'); + // A third fills it, and the button can't add more. + photosPicked($screen, [testPhoto()]); - Http::assertNotSent(fn (Request $request): bool => $request->method() === 'POST'); + expect(menuItems($screen, 'reply-add-photos'))->toBe([]) + ->and(nodeByRef($screen, 'reply-add-photos')['a11y_label'] ?? nodeByRef($screen, 'reply-add-photos')['props']['a11y_label'] ?? null)->toBe('A reply can have up to 3 photos'); }); -it('hands the reply\'s photos back to the reply bar too, which counts them, keeps them and replies with them', function () { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Look'])], 201], - ]); +it('takes a photo off the reply in the bar with its ✕, and off the phone', function () { + $screen = photosPicked(replyPage(), [testPhoto(), testPhoto()]); + $removed = $screen->instance()->replyImages[0]->path; - $screen = photosPicked(Native::visit('/log/commits/c2')->input('reply-input', 'Look')->tap('reply-expand')->tap('reply-attach'), [testPhoto()]) - ->dismissSheet('sheet'); - $path = $screen->instance()->replyImages[0]->path; + $screen->tap('reply-photo-0-remove'); + + expect($screen->instance()->replyImages)->toHaveCount(1) + ->and(file_exists($removed))->toBeFalse() + ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(1); +}); - expect(treeShows(nodeByRef($screen, 'reply-photos'), '1 photo'))->toBeTrue() - ->and(nodeByRef($screen, 'reply-photos')['props']['a11y_label'] ?? null)->toBe('1 photo attached') - // In the box, after its other tools. - ->and(array_slice(childRefs($screen, 'reply-actions'), 0, 3))->toBe(['reply-expand', 'reply-attach', 'reply-photos']); +it('keeps a reply\'s photos for when you come back to the commit, and replies with them', function () { + photosPicked(replyPage()->input('reply-input', 'Look'), [testPhoto()]); - // Coming back to the commit, the bar has them still. $screen = Native::visit('/log/commits/c2'); + $path = $screen->instance()->replyImages[0]->path; expect($screen->instance()->reply)->toBe('Look') - ->and($screen->instance()->replyImages)->toHaveCount(1) + ->and(nodeByRef($screen, 'reply-photo-0'))->not->toBeNull() ->and(nodeByRef($screen, 'reply-stash'))->not->toBeNull(); - // The count opens the sheet on them. - $screen->tap('reply-photos'); - - expect(nodeByRef($screen, 'sheet')['props']['visible'])->toBeTrue() - ->and($screen->instance()->sheetImages[0]->path)->toBe($path); - - $screen->dismissSheet('sheet')->tap('send-reply')->assertSee('Look'); + $screen->tap('send-reply')->assertSee('Look'); Http::assertSent(fn (Request $request): bool => $request->method() === 'POST' && multipartParts($request)[0]['contents'] === '{"body":"Look","parent_id":"c2"}' && multipartParts($request)[1]['name'] === 'images[]'); expect($screen->instance()->replyImages)->toBe([]) - ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'reply-photos'))->toBeNull() + ->and(rendersRef($screen, 'reply-photo-0'))->toBeFalse() ->and(file_exists($path))->toBeFalse() ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); }); -it('hands the reply and its photos back to the reply bar when Cancel closes the sheet on Android, which never says it has gone', function () { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - ]); +it('previews a reply with its photos in the bar', function () { + $screen = photosPicked(replyPage()->input('reply-input', 'Look'), [testPhoto()])->tap('reply-preview'); - $screen = photosPicked(Native::visit('/log/commits/c2', platform: 'android')->input('reply-input', 'Half')->tap('reply-expand')->tap('reply-attach'), [testPhoto()]) - ->input('sheet-body', 'Half a reply') - ->tap('sheet-cancel') - ->input('reply-input', 'Half a reply, and more'); + // The photos move into the preview, as the reply will show them, and their row above the field goes. + expect(treeShows(nodeByRef($screen, 'reply-draft-preview'), 'Look'))->toBeTrue() + ->and(findNode(nodeByRef($screen, 'reply-draft-preview'), fn (array $node): bool => ($node['type'] ?? null) === 'image'))->not->toBeNull() + ->and(rendersRef($screen, 'reply-photo-0'))->toBeFalse(); +}); - expect($screen->instance()->replyImages)->toHaveCount(1) - ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(1); +it('drops a reply\'s photos with it, off the phone', function () { + $screen = photosPicked(replyPage(), [testPhoto()]); + $path = $screen->instance()->replyImages[0]->path; + + $screen->tap('reply-stash-drop'); + + expect($screen->instance()->replyImages)->toBe([]) + ->and(file_exists($path))->toBeFalse() + ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); }); + +it('hands a reply opened in the sheet back to the reply bar, photos too, when the sheet goes unsent', function (string $platform) { + $screen = replyPage($platform)->input('reply-input', 'Half')->call('replyInSheet', 'c2'); + + photosPicked($screen, [testPhoto()])->input('sheet-body', 'Half a reply'); + + $platform === 'ios' ? $screen->dismissSheet('sheet') : $screen->tap('sheet-cancel'); + + expect(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('Half a reply') + ->and($screen->instance()->replyImages)->toHaveCount(1) + ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(1); + + Http::assertNotSent(fn (Request $request): bool => $request->method() === 'POST'); +})->with(['ios', 'android']); diff --git a/tests/Feature/Screens/DraftStashTest.php b/tests/Feature/Screens/DraftStashTest.php index 139954a7..a346e29d 100644 --- a/tests/Feature/Screens/DraftStashTest.php +++ b/tests/Feature/Screens/DraftStashTest.php @@ -3,7 +3,6 @@ use App\Devnull\Account; use App\Devnull\Data\Pasteis; use App\Devnull\Data\StashedDraft; -use App\Devnull\Display; use App\Devnull\Stash; use Carbon\CarbonImmutable; use Illuminate\Http\Client\Request; @@ -199,17 +198,18 @@ function stashLabel(TestableComponent $screen, string $ref): array $screen = Native::visit('/log/commits/c2')->input('reply-input', 'A reply in progress'); $clearance = nodeByRef($screen, 'reply-bar-clearance')['layout']['height']; + // While you write it, there's only drop. expect(stashed('reply-c2'))->toBe('A reply in progress') - ->and(showsRef($screen, 'reply-stash'))->toBeFalse(); + ->and(stashLabel($screen, 'reply-stash'))->toBe(['drop', 'Discard the draft']); $screen = Native::visit('/log/commits/c2'); expect(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('A reply in progress') ->and(stashLabel($screen, 'reply-stash'))->toBe(['stash@{0}', 'Discard the restored draft']) ->and(canSend($screen, 'send-reply'))->toBeTrue() - // It's marked on a row under the box, and the page ends above that too. - ->and(childRefs($screen, 'reply-stash-row'))->toBe(['reply-stash']) - ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance + Display::ReplyBarStashLabelHeight); + // It's marked in the row under the field, beside Reply, so the bar is no taller for it. + ->and(array_slice(childRefs($screen, 'reply-actions'), -2))->toBe(['reply-stash', 'send-reply']) + ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance); }); it("forgets a reply's stash once it's sent", function () { From 07e127dcaa3601838d2279e8be8b77f51229a50f Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 00:44:52 +0000 Subject: [PATCH 06/30] Draw the reply bar's fade in the bar on iOS, as Remotes does The page runs on under the bar on iOS, so the fade is the bar's first row there, over the reply's rows, which have the surface. On Android it stays over the foot of the page. Co-Authored-By: Claude Opus 5.5 --- .../views/native/commit-detail.blade.php | 13 ++++++++---- tests/Feature/Screens/CommitDetailTest.php | 20 ++++++++++++------- tests/Feature/Screens/ComposerPhotosTest.php | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 6469c124..46adefdd 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -116,7 +116,7 @@ - @if ($commit) + @if ($commit && ! \App\Devnull\Display::fadesInBar()) @include('native.partials.composer-fade', ['ref' => 'reply-fade']) @endif @@ -125,8 +125,8 @@ {{-- The reply bar, drawn as the Remotes composer is: the field across the top and a row under it with the tools on the left and the round send button on the right (see partials/composer-box), straight on the - surface, with the page fading out above it. native:bottom-bar takes no classes of its own, so the bar is - painted from this column, which also fills the strip under the home indicator. + surface, with the page fading out above it (see partials/composer-fade). native:bottom-bar takes no classes + of its own, so the bar is painted from this column, which also fills the strip under the home indicator. The bar does everything the composer sheet did for a reply, so a reply never needs the sheet, whose presenting takes the keyboard down and back up on both platforms. The photo button adds photos from the @@ -139,7 +139,11 @@ $lead. --}} - + + @if (\App\Devnull\Display::fadesInBar()) + @include('native.partials.composer-fade', ['ref' => 'reply-fade', 'inBar' => true]) + @endif + {{-- The people to mention and the photos on the reply keep a slot each above the field, empty and 0.1pt tall when there's nothing in it, so the field's row never moves. Android rebuilds a row that @@ -181,6 +185,7 @@ @if (\App\Devnull\Data\CommitBody::hasOversizedUrl($reply)) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. @endif + @endif diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 45ef0fd2..3a89d1ca 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -869,16 +869,22 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): fakeThread(); $screen = Native::visit('/log/commits/c2', platform: $platform); - $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); + $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar')['children'][0]; $surface = strtoupper(config('native-ui.theme.light.surface')); - expect($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') - ->and($bar['children'][0]['props']['glass'] ?? null)->toBeNull() - ->and($bar['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) - ->and($bar['children'][0]['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) - ->and(childRefs($screen, 'reply-bar')[0])->toBe('reply-mention-slot') - ->and(childRefs($screen, 'thread-stack'))->toBe(['thread-scroll', 'reply-fade']) + // The bar's rows have the surface. The bar itself has it only on Android: iOS would paint it behind the fade. + expect($bar['ref'] ?? null)->toBe('reply-bar') + ->and($bar['props']['glass'] ?? null)->toBeNull() + ->and($bar['style']['bg_color'] ?? null)->toBe($platform === 'ios' ? null : config('native-ui.theme.light.surface')) + ->and(nodeByRef($screen, 'reply-rows')['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) + ->and(nodeByRef($screen, 'reply-rows')['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) + ->and(childRefs($screen, 'reply-rows')[0])->toBe('reply-mention-slot') ->and(str_ends_with(nodeByRef($screen, 'reply-fade')['props']['gradient_stops'] ?? '', $surface))->toBeTrue(); + + // On iOS the page runs on under the bar, which draws the fade. On Android the page stops at the bar, and the fade + // lies over its foot. + expect(childRefs($screen, 'reply-bar'))->toBe($platform === 'ios' ? ['reply-fade', 'reply-rows'] : ['reply-rows']) + ->and(childRefs($screen, 'thread-stack'))->toBe($platform === 'ios' ? ['thread-scroll'] : ['thread-scroll', 'reply-fade']); })->with(['ios', 'android']); it('ends the page above the reply bar, and further as the draft grows', function () { diff --git a/tests/Feature/Screens/ComposerPhotosTest.php b/tests/Feature/Screens/ComposerPhotosTest.php index 4ea4abd0..9a0fa6e1 100644 --- a/tests/Feature/Screens/ComposerPhotosTest.php +++ b/tests/Feature/Screens/ComposerPhotosTest.php @@ -252,7 +252,7 @@ function replyPage(string $platform = 'ios'): TestableComponent // They show above the field, which keeps its place, and go in the reply's stash with its text. expect($screen->instance()->replyImages)->toHaveCount(2) - ->and(childRefs($screen, 'reply-bar'))->toBe(['reply-mention-slot', 'reply-photos-slot', 'reply-row']) + ->and(childRefs($screen, 'reply-rows'))->toBe(['reply-mention-slot', 'reply-photos-slot', 'reply-row']) ->and(nodeByRef($screen, 'reply-photo-0'))->not->toBeNull() ->and(nodeByRef($screen, 'reply-photo-1'))->not->toBeNull() ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse() From a529a8731f2b39ca382f6b7ee19b81ac5a643ed9 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 02:12:22 +0000 Subject: [PATCH 07/30] Put the reply bar on Liquid Glass on iOS, as Remotes does The commit page's reply bar takes the same glass as the Remotes composer: the page shows through it blurred, the glass fades in at the top and runs on under the home indicator, and the rows tint it with the surface. It needs the same patched mobile-air. Android is unchanged. Co-Authored-By: Claude Opus 5.5 --- .../views/native/commit-detail.blade.php | 11 ++--- tests/Feature/Screens/CommitDetailTest.php | 42 ++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 46adefdd..3667a822 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -124,9 +124,10 @@ @if ($commit) {{-- The reply bar, drawn as the Remotes composer is: the field across the top and a row under it with the - tools on the left and the round send button on the right (see partials/composer-box), straight on the - surface, with the page fading out above it (see partials/composer-fade). native:bottom-bar takes no classes - of its own, so the bar is painted from this column, which also fills the strip under the home indicator. + tools on the left and the round send button on the right (see partials/composer-box), with the page fading + out above it (see partials/composer-fade). On iOS the bar is Liquid Glass, faded in at the top, so the page + shows through it blurred (see Display::composerBarGlass()). On Android it's the surface, painted from this + column. Either fills the strip under the home indicator. The bar does everything the composer sheet did for a reply, so a reply never needs the sheet, whose presenting takes the keyboard down and back up on both platforms. The photo button adds photos from the @@ -138,12 +139,12 @@ A "post as" avatar, for people in a GitHub organization, goes at the start of the row as composer-box's $lead. --}} - + @if (\App\Devnull\Display::fadesInBar()) @include('native.partials.composer-fade', ['ref' => 'reply-fade', 'inBar' => true]) @endif - + {{-- The people to mention and the photos on the reply keep a slot each above the field, empty and 0.1pt tall when there's nothing in it, so the field's row never moves. Android rebuilds a row that diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 3a89d1ca..8b692e51 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -865,26 +865,40 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(pressFeedbackInScroller($screen))->toBe([]); }); -it('puts the reply bar on the surface with no glass or line, and fades the page out above it, on both platforms', function (string $platform) { +it('puts the reply bar on glass on iOS and the surface on Android, with no line, and fades the page out above it', function (string $platform) { fakeThread(); $screen = Native::visit('/log/commits/c2', platform: $platform); - $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar')['children'][0]; - $surface = strtoupper(config('native-ui.theme.light.surface')); + $bottomBar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); + $bar = $bottomBar['children'][0]; + $surface = substr(strtoupper(config('native-ui.theme.light.surface')), 1); + $darkSurface = substr(strtoupper(config('native-ui.theme.dark.surface')), 1); - // The bar's rows have the surface. The bar itself has it only on Android: iOS would paint it behind the fade. expect($bar['ref'] ?? null)->toBe('reply-bar') ->and($bar['props']['glass'] ?? null)->toBeNull() - ->and($bar['style']['bg_color'] ?? null)->toBe($platform === 'ios' ? null : config('native-ui.theme.light.surface')) - ->and(nodeByRef($screen, 'reply-rows')['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) - ->and(nodeByRef($screen, 'reply-rows')['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) - ->and(childRefs($screen, 'reply-rows')[0])->toBe('reply-mention-slot') - ->and(str_ends_with(nodeByRef($screen, 'reply-fade')['props']['gradient_stops'] ?? '', $surface))->toBeTrue(); - - // On iOS the page runs on under the bar, which draws the fade. On Android the page stops at the bar, and the fade - // lies over its foot. - expect(childRefs($screen, 'reply-bar'))->toBe($platform === 'ios' ? ['reply-fade', 'reply-rows'] : ['reply-rows']) - ->and(childRefs($screen, 'thread-stack'))->toBe($platform === 'ios' ? ['thread-scroll'] : ['thread-scroll', 'reply-fade']); + ->and(childRefs($screen, 'reply-rows')[0])->toBe('reply-mention-slot'); + + if ($platform === 'ios') { + // The page runs on under the bar, which is glass, so it shows through blurred. The bar draws the fade at its + // top, ending at the glass's tint, and its rows carry the tint. The bar itself has no background, which iOS + // would paint behind the fade. + expect($bottomBar['props']['glass'] ?? null)->toBe(1) + ->and($bar['style']['bg_color'] ?? null)->toBeNull() + ->and(nodeByRef($screen, 'reply-rows')['style']['bg_color'] ?? null)->toBe('#66'.$surface) + ->and(nodeByRef($screen, 'reply-rows')['props']['dark_bg_color'] ?? null)->toBe('#66'.$darkSurface) + ->and(nodeByRef($screen, 'reply-fade')['props']['gradient_stops'] ?? null)->toBe('#00'.$surface.',#66'.$surface) + ->and(childRefs($screen, 'reply-bar'))->toBe(['reply-fade', 'reply-rows']) + ->and(childRefs($screen, 'thread-stack'))->toBe(['thread-scroll']); + } else { + // No glass on Android. The page stops at the bar, which is the surface, and the fade lies over its foot. + expect($bottomBar['props']['glass'] ?? null)->toBeNull() + ->and($bar['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) + ->and(nodeByRef($screen, 'reply-rows')['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) + ->and(nodeByRef($screen, 'reply-rows')['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) + ->and(str_ends_with(nodeByRef($screen, 'reply-fade')['props']['gradient_stops'] ?? '', ',#'.$surface))->toBeTrue() + ->and(childRefs($screen, 'reply-bar'))->toBe(['reply-rows']) + ->and(childRefs($screen, 'thread-stack'))->toBe(['thread-scroll', 'reply-fade']); + } })->with(['ios', 'android']); it('ends the page above the reply bar, and further as the draft grows', function () { From cbd3bc480aa5bdeb02987d5421530f4f5195707b Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 03:17:00 +0000 Subject: [PATCH 08/30] Line the reply bar's Post as avatar up with the field's text The avatar led the row at the row's own inset, 12pt left of the text above it, where the photo button's icon used to line up. post-as takes an inset now, padded inside its tap target, and the bar passes pl-3. Co-Authored-By: Claude Opus 5.5 --- resources/views/native/commit-detail.blade.php | 6 +++--- resources/views/native/partials/post-as.blade.php | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index b7bc855b..f2645514 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -137,8 +137,8 @@ the stash, then how long the reply is near the limit. A member of a GitHub organization has the web's Post as at the start of the row, as composer-box's $lead: - the avatar of whoever the reply goes out as, which opens the menu (see PostAs). The send button is then - filled with that one's lane. + the avatar of whoever the reply goes out as, lined up with the field's text, which opens the menu (see + PostAs). The send button is then filled with that one's lane. --}} @php($replyPostingMe = app(\App\Devnull\Account::class)->user()) @php($replyPostsAs = $replyPostingMe !== null && \App\Devnull\PostAs::offered($replyAuthor)) @@ -170,7 +170,7 @@ @include('native.partials.composer-box', [ 'ref' => 'reply', 'field' => $replyPreviewing ? 'native.partials.reply-preview' : 'native.partials.reply-field', - 'lead' => $replyPostsAs ? [['native.partials.post-as', ['ref' => 'reply-post-as', 'me' => $replyPostingMe, 'picked' => $replyAuthor, 'method' => 'postAsInReply', 'size' => 28]]] : [], + 'lead' => $replyPostsAs ? [['native.partials.post-as', ['ref' => 'reply-post-as', 'me' => $replyPostingMe, 'picked' => $replyAuthor, 'method' => 'postAsInReply', 'size' => 28, 'inset' => 'pl-3']]] : [], 'tools' => [ ['ref' => 'reply-add-photos', 'icon' => \App\Icons\Lucide::ImagePlus, 'label' => $photosFull ? 'A reply can have up to 3 photos' : 'Add photos', 'menu' => $photosFull ? null : \App\Devnull\ComposerMenu::photoItems(), 'disabled' => $photosFull], ['ref' => 'reply-preview', 'icon' => \App\Icons\Lucide::Eye, 'label' => $replyPreviewing ? 'Edit' : 'Preview', 'press' => 'toggleReplyPreview', 'active' => $replyPreviewing], diff --git a/resources/views/native/partials/post-as.blade.php b/resources/views/native/partials/post-as.blade.php index 64f9d176..b22f86a8 100644 --- a/resources/views/native/partials/post-as.blade.php +++ b/resources/views/native/partials/post-as.blade.php @@ -2,16 +2,18 @@ Who a composer posts as (see PostAs): the avatar of whoever it is now, round for you and a rounded square for an organization, with a small chevron on its corner, as the web's Post as button draws it. A tap opens the menu of you and your organizations, which calls $method with the handle picked, or '' for you. With $withName, their name and - handle follow the avatar, for the sheet, which has the room. + handle follow the avatar, for the sheet, which has the room. $inset pads it inside its tap target, so a bar can line + the avatar up with its field. $picked is the handle the composer holds. An organization you've left since posts as you, so your avatar shows. --}} @php($size ??= 32) @php($withName ??= false) +@php($inset ??= '') @php($author = \App\Devnull\PostAs::author($picked)) @php($identity = $author ?? $me) - + @include('native.partials.avatar', ['user' => $identity, 'size' => $size]) From eaeffdc1b582bc813b96f82ba34f3fbcafa0a87c Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 05:05:18 +0000 Subject: [PATCH 09/30] Treat an organization's commits as yours when you're a member On the web any member of an organization owns its commits, whoever posted them (Commit::isOwnedBy on the server, useOwnsCommit on the web). The app only counted commits authored by you. Now one Ownership class decides it, from your id and the organizations GET /me last listed, and everything that asked "is this mine" asks it instead. For a member, an organization's commit now offers Delete (in More and in the commit page's nav bar), shows its star count instead of a star, can be quoted while pending, and can't be reported or have its poll voted on. Someone outside the org still gets the star and Report and never Delete. Pin stays person-only, as on the server and the web. No one gets a pastel on an organization's commit, matching the web, which hides it because it would go to whoever posted it. The API only lists who starred an organization's commit to the member who posted it, though the web shows it to every member. The stars sheet now says so on a 404 instead of offering Try again. If devnull refuses a delete because you've left the org, its message shows and the app asks /me again, so the commit stops offering Delete. Rows are cached against your organizations too, so they redraw when that changes. Deleting or posting an organization's commit no longer changes your own profile's kept commit count or list. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Account.php | 8 + app/Devnull/CommitMenu.php | 15 +- app/Devnull/Data/Commit.php | 11 +- app/Devnull/LastVisit.php | 8 +- app/Devnull/Ownership.php | 72 +++++ app/Devnull/ResponseCache.php | 35 ++- app/Devnull/RowInputs.php | 2 + app/NativeComponents/CommitDetail.php | 6 +- .../Concerns/OpensCommitSheet.php | 14 +- .../Concerns/OpensStargazers.php | 18 +- .../Concerns/RefreshesInBackground.php | 15 +- .../Concerns/ShowsCommits.php | 38 ++- .../Concerns/TalksToDevnull.php | 9 + .../Concerns/VotesOnPolls.php | 4 +- app/NativeComponents/Log.php | 12 +- app/NativeComponents/Organization.php | 1 + app/NativeComponents/Profile.php | 1 + app/NativeComponents/Search.php | 1 + app/NativeComponents/Starred.php | 1 + .../native/partials/commit-actions.blade.php | 14 +- .../native/partials/commit-poll.blade.php | 10 +- .../partials/stargazers-sheet.blade.php | 7 +- .../Screens/OrganizationCommitsTest.php | 256 ++++++++++++++++++ tests/Unit/Devnull/TimelineTest.php | 17 +- 24 files changed, 503 insertions(+), 72 deletions(-) create mode 100644 app/Devnull/Ownership.php create mode 100644 tests/Feature/Screens/OrganizationCommitsTest.php diff --git a/app/Devnull/Account.php b/app/Devnull/Account.php index 2163391d..07f3b10a 100644 --- a/app/Devnull/Account.php +++ b/app/Devnull/Account.php @@ -228,6 +228,14 @@ public function organizations(): array return is_array($kept) ? array_values(array_map(User::fromArray(...), array_filter($kept, is_array(...)))) : []; } + /** + * Which commits are yours: your own and your organizations' (see Ownership). + */ + public function ownership(): Ownership + { + return Ownership::of($this->user(), $this->organizations()); + } + /** * Remembers the organizations you can post as. With null, from a devnull too old to say, it keeps what it had. * diff --git a/app/Devnull/CommitMenu.php b/app/Devnull/CommitMenu.php index d566caf9..89a2b1e2 100644 --- a/app/Devnull/CommitMenu.php +++ b/app/Devnull/CommitMenu.php @@ -3,7 +3,6 @@ namespace App\Devnull; use App\Devnull\Data\Commit; -use App\Devnull\Data\User; use App\Icons\Lucide; use Native\Mobile\Edge\Elements\TopBarAction; use Native\Mobile\Edge\Layouts\Builders\NavAction; @@ -13,26 +12,28 @@ * partials/commit-actions): Share link on every commit; Pin to profile or * Unpin from profile on your own published commit, not a reply; then, after a * divider, Report commit on someone else's published commit, or Delete commit - * on your own. Each item names the commit, so a tap never rebuilds anything - * from an attribute (see ShowsCommits). + * on yours. An organization's commit is yours while you're a member, whoever + * posted it (see Ownership), so every member gets Delete, as on the web. Only + * a person has a profile to pin to, so it never gets Pin. Each item names the + * commit, so a tap never rebuilds anything from an attribute (see ShowsCommits). */ final class CommitMenu { /** * @return list */ - public static function items(Commit $commit, ?User $viewer): array + public static function items(Commit $commit, Ownership $ownership): array { - $isOwn = $viewer !== null && $commit->author->id === $viewer->id; + $isOwn = $ownership->owns($commit); $items = []; $items[] = self::item($commit, 'share', 'Share link', Lucide::Link, 'shareCommit'); - if ($isOwn && $commit->isApproved() && $commit->parentId === null) { + if ($ownership->isYourOwn($commit) && $commit->isApproved() && $commit->parentId === null) { $items[] = self::item($commit, 'pin', $commit->isPinned ? 'Unpin from profile' : 'Pin to profile', Lucide::Pin, 'togglePin'); } - if ($viewer !== null && ! $isOwn && $commit->isApproved()) { + if ($ownership->isSignedIn() && ! $isOwn && $commit->isApproved()) { $items[] = NavAction::divider(); $items[] = self::item($commit, 'report', 'Report commit', Lucide::Flag, 'reportCommit'); } elseif ($isOwn) { diff --git a/app/Devnull/Data/Commit.php b/app/Devnull/Data/Commit.php index 941f4ce3..1175a11e 100644 --- a/app/Devnull/Data/Commit.php +++ b/app/Devnull/Data/Commit.php @@ -4,6 +4,7 @@ use App\Devnull\Display; use App\Devnull\Lane; +use App\Devnull\Ownership; use Carbon\CarbonImmutable; use Closure; use Throwable; @@ -327,15 +328,15 @@ public function isApproved(): bool } /** - * Whether $viewer may vote on the commit's poll, as the web decides it: someone else's published commit, whose - * poll is open and hasn't had their vote yet. + * Whether you may vote on the commit's poll, as the web decides it: a published commit that isn't yours or your + * organization's (see Ownership), whose poll is open and hasn't had your vote yet. */ - public function canBeVotedOnBy(?User $viewer): bool + public function canBeVotedOnBy(Ownership $ownership): bool { - return $viewer !== null + return $ownership->isSignedIn() && $this->poll !== null && $this->isApproved() - && $this->author->id !== $viewer->id + && ! $ownership->owns($this) && $this->poll->closesAt !== null && ! $this->poll->hasVoted && ! $this->poll->showsResults() diff --git a/app/Devnull/LastVisit.php b/app/Devnull/LastVisit.php index f88e01b2..4a951c89 100644 --- a/app/Devnull/LastVisit.php +++ b/app/Devnull/LastVisit.php @@ -36,13 +36,13 @@ public function remember(string $userId, string $log, array $commits): void /** * The commit the marker goes above, or null for a first visit, when nothing is - * new, or when the only new commits are your own. + * new, or when the only new commits are yours or your organizations' (see Ownership). * * @param list $commits newest first */ - public static function firstSeenId(array $commits, ?string $seenAt, ?string $userId): ?string + public static function firstSeenId(array $commits, ?string $seenAt, Ownership $ownership): ?string { - if ($seenAt === null || $userId === null) { + if ($seenAt === null || ! $ownership->isSignedIn()) { return null; } @@ -58,7 +58,7 @@ public static function firstSeenId(array $commits, ?string $seenAt, ?string $use } foreach (array_slice($commits, 0, $index) as $newer) { - if ($newer->author->id !== $userId) { + if (! $ownership->owns($newer)) { return $commit->id; } } diff --git a/app/Devnull/Ownership.php b/app/Devnull/Ownership.php new file mode 100644 index 00000000..99f52478 --- /dev/null +++ b/app/Devnull/Ownership.php @@ -0,0 +1,72 @@ + $organizationIds + */ + public function __construct( + public ?string $userId = null, + public array $organizationIds = [], + ) {} + + /** + * @param list $organizations + */ + public static function of(?User $user, array $organizations = []): self + { + $userId = $user === null || $user->id === '' ? null : $user->id; + + if ($userId === null) { + return new self; + } + + return new self($userId, array_values(array_filter( + array_map(fn (User $organization): string => $organization->id, $organizations), + fn (string $id): bool => $id !== '' && $id !== $userId, + ))); + } + + public function isSignedIn(): bool + { + return $this->userId !== null; + } + + /** + * Whether the commit is yours: by you, or by an organization you're in. + */ + public function owns(Commit $commit): bool + { + $author = $commit->author->id; + + return $this->userId !== null && $author !== '' && ($author === $this->userId || in_array($author, $this->organizationIds, true)); + } + + /** + * Whether you made the commit as yourself, not as an organization. + */ + public function isYourOwn(Commit $commit): bool + { + return $this->userId !== null && $commit->author->id === $this->userId; + } +} diff --git a/app/Devnull/ResponseCache.php b/app/Devnull/ResponseCache.php index fadaa8a0..cc37bb14 100644 --- a/app/Devnull/ResponseCache.php +++ b/app/Devnull/ResponseCache.php @@ -396,7 +396,9 @@ public function pastelGiven(array $json): void /** * You committed. A commit goes on top of your logs and your profile; a reply - * goes under its parent and counts there, and on top of your replies. + * goes under its parent and counts there, and on top of your replies. One + * you posted as an organization is the organization's, so it stays off + * your profile and its counts, as devnull keeps it. * * @param array $commit */ @@ -409,14 +411,17 @@ public function commitAdded(array $commit): void } $parentId = is_string($commit['parent_id'] ?? null) ? $commit['parent_id'] : null; + $onYourProfile = ! self::isOrganizations($commit); if ($parentId === null) { // Trending is ranked, so a new commit has no place at the top of it. - foreach (['log/following', 'log/latest', "users/{$me}/commits"] as $path) { + foreach (['log/following', 'log/latest', ...($onYourProfile ? ["users/{$me}/commits"] : [])] as $path) { $this->patch($path, [], fn (array $json): array => self::prepend($json, $commit)); } - $this->patch("users/{$me}", [], fn (array $json): array => self::count($json, 'commits_count', 1)); + if ($onYourProfile) { + $this->patch("users/{$me}", [], fn (array $json): array => self::count($json, 'commits_count', 1)); + } return; } @@ -425,7 +430,10 @@ public function commitAdded(array $commit): void $this->patch("commits/{$parentId}/replies", [], fn (array $json): array => ($json['meta']['next_cursor'] ?? null) === null ? [...$json, 'data' => [...self::without($json['data'] ?? [], $commit['id']), $commit]] : $json); - $this->patch("users/{$me}/commits", ['replies' => '1'], fn (array $json): array => self::prepend($json, $commit)); + if ($onYourProfile) { + $this->patch("users/{$me}/commits", ['replies' => '1'], fn (array $json): array => self::prepend($json, $commit)); + } + $this->patchCommit($parentId, fn (array $parent): array => self::withNewestReply([...$parent, 'replies_count' => (int) ($parent['replies_count'] ?? 0) + 1], $commit)); } @@ -450,11 +458,14 @@ private static function withNewestReply(array $parent, array $reply): array } /** - * You deleted a commit: it leaves every list, its page goes, and its parent counts one reply fewer. + * You deleted a commit: it leaves every list, its page goes, and its parent + * counts one reply fewer. Your profile counts one commit fewer, unless it + * was an organization's you're in (see Ownership). */ public function commitDeleted(string $id): void { - $parentId = $this->findCommit($id)['parent_id'] ?? null; + $found = $this->findCommit($id); + $parentId = $found['parent_id'] ?? null; $this->rememberDeletion($id); @@ -465,11 +476,21 @@ public function commitDeleted(string $id): void if (is_string($parentId) && $parentId !== '') { $this->patchCommit($parentId, fn (array $parent): array => [...$parent, 'replies_count' => max(0, (int) ($parent['replies_count'] ?? 0) - 1)]); - } elseif (($me = $this->username()) !== null) { + } elseif (($me = $this->username()) !== null && ($found === null || ! self::isOrganizations($found))) { $this->patch("users/{$me}", [], fn (array $json): array => self::count($json, 'commits_count', -1)); } } + /** + * Whether a kept commit is an organization's. + * + * @param array $commit + */ + private static function isOrganizations(array $commit): bool + { + return is_array($commit['author'] ?? null) && ($commit['author']['type'] ?? null) === 'organization'; + } + /** * You followed or unfollowed someone: their profile and your following * count change, and every list of people kept with whether you follow them. diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index 0659a309..15d208c1 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -25,9 +25,11 @@ final class RowInputs public static function for(Commit $commit, array $scope): array { $viewer = $scope['viewer'] ?? app(Account::class)->user(); + $ownership = $scope['ownership'] ?? app(Account::class)->ownership(); return [ 'viewer' => $viewer?->id, + 'organizations' => $ownership->organizationIds, 'pasteis' => $scope['pasteis'] ?? app(Account::class)->pasteis(), 'stashed' => $scope['stashed'] ?? [], 'unfolded' => $scope['unfolded'] ?? [], diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 23435b1b..dbc088eb 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -844,9 +844,12 @@ private function loadTombstoneReplies(string $id): void } } + /** + * Whether the commit is yours, or an organization's you're in, which puts Delete in the nav bar (see Ownership). + */ public function isOwn(): bool { - return $this->commit !== null && $this->commit->author->username === $this->me()?->username; + return $this->commit !== null && $this->ownership()->owns($this->commit); } public function render(): View @@ -861,6 +864,7 @@ public function render(): View 'replyRows' => $this->replyRows, 'myColour' => $this->myColour(), 'viewer' => $viewer, + 'ownership' => $this->ownership(), 'stashed' => app(Stash::class)->names($viewer?->id), 'pasteis' => app(Account::class)->pasteis(), 'rows' => $this->commit === null ? [] : Timeline::thread( diff --git a/app/NativeComponents/Concerns/OpensCommitSheet.php b/app/NativeComponents/Concerns/OpensCommitSheet.php index 4bcc9cf4..06df216a 100644 --- a/app/NativeComponents/Concerns/OpensCommitSheet.php +++ b/app/NativeComponents/Concerns/OpensCommitSheet.php @@ -540,18 +540,24 @@ private function openFailedCommit(PendingWrite $write): bool return $this->sheetOpen && $this->sheetStashName() === $write->stashName(); } + /** + * A published commit, or one of yours still waiting for approval, as the web's Quote shows. + */ private function canQuote(Commit $commit): bool { - $viewer = $this->me(); + $ownership = $this->ownership(); - return $viewer !== null && ! $commit->isDeleted() && ! $commit->isStaged() && ($commit->isApproved() || $commit->author->id === $viewer->id); + return $ownership->isSignedIn() && ! $commit->isDeleted() && ! $commit->isStaged() && ($commit->isApproved() || $ownership->owns($commit)); } + /** + * Someone else's published commit: never yours or an organization's you're in, which devnull won't take a report of. + */ private function canReport(Commit $commit): bool { - $viewer = $this->me(); + $ownership = $this->ownership(); - return $viewer !== null && ! $commit->isDeleted() && $commit->isApproved() && $commit->author->id !== $viewer->id; + return $ownership->isSignedIn() && ! $commit->isDeleted() && $commit->isApproved() && ! $ownership->owns($commit); } /** diff --git a/app/NativeComponents/Concerns/OpensStargazers.php b/app/NativeComponents/Concerns/OpensStargazers.php index 84024cf4..5ec6fe7f 100644 --- a/app/NativeComponents/Concerns/OpensStargazers.php +++ b/app/NativeComponents/Concerns/OpensStargazers.php @@ -12,6 +12,11 @@ * opening their profile. As on the web, only you see who starred your * commits, and it asks devnull again each time it opens, so stars given in * the meantime show. + * + * An organization's commit is every member's (see Ownership), so its star + * opens the sheet too. The web lists who starred it to any member, but the + * API only to the member who posted it, and to anyone else it says the list + * isn't there. The sheet says so then, rather than offering Try again. */ trait OpensStargazers { @@ -37,6 +42,11 @@ trait OpensStargazers */ public bool $stargazersFailed = false; + /** + * Whether devnull only shows who starred this organization's commit to the member who posted it. + */ + public bool $stargazersForPoster = false; + /** * The load the sheet is waiting for. An answer to an earlier one, sent * before the sheet closed or opened again, is left alone. @@ -47,7 +57,7 @@ public function openStargazers(string $id): void { $commit = $this->shownCommit($id); - if ($commit === null || $commit->isDeleted() || $commit->starsCount === 0 || $commit->author->id !== $this->me()?->id) { + if ($commit === null || $commit->isDeleted() || $commit->starsCount === 0 || ! $this->ownership()->owns($commit)) { return; } @@ -81,10 +91,11 @@ public function loadStargazers(): void $this->stargazers = [...$this->stargazers, ...$page->items]; $this->stargazersCursor = $page->nextCursor; $this->loadingStargazers = false; - }, again: true, quiet: true, failed: function () use ($load): void { + }, again: true, quiet: true, failed: function (int $status = 0) use ($load): void { if ($load === $this->stargazersLoad) { $this->loadingStargazers = false; - $this->stargazersFailed = true; + $this->stargazersForPoster = $status === 404 && $this->shownCommit((string) $this->stargazersOf)?->author->isOrganization === true; + $this->stargazersFailed = ! $this->stargazersForPoster; } }); } @@ -113,5 +124,6 @@ public function stargazersClosed(): void $this->stargazersCursor = null; $this->loadingStargazers = false; $this->stargazersFailed = false; + $this->stargazersForPoster = false; } } diff --git a/app/NativeComponents/Concerns/RefreshesInBackground.php b/app/NativeComponents/Concerns/RefreshesInBackground.php index a64a3a82..732d4f8a 100644 --- a/app/NativeComponents/Concerns/RefreshesInBackground.php +++ b/app/NativeComponents/Concerns/RefreshesInBackground.php @@ -84,12 +84,13 @@ protected function cached(string $path, array $query = []): ?array * lands. A refresh of the same thing already on its way isn't sent twice, * unless $again says it must be. A $quiet one never says it failed on the * screen. It only tells $failed, for a caller that has something else to - * do then. One $withImages brings the answer's images down before it - * lands, rather than after in a task of their own (see FetchInBackground). + * do then, with devnull's status code, or 0 when it never answered. One + * $withImages brings the answer's images down before it lands, rather + * than after in a task of their own (see FetchInBackground). * * @param array $query * @param Closure(array): void $apply - * @param (Closure(): void)|null $failed + * @param (Closure(int): void)|null $failed */ protected function refresh(string $path, array $query, Closure $apply, bool $again = false, bool $quiet = false, ?Closure $failed = null, bool $withImages = false, bool $retried = false): void { @@ -103,7 +104,7 @@ protected function refresh(string $path, array $query, Closure $apply, bool $aga $request = app(Client::class)->signedGet($path, $query); } catch (KeychainUnavailable $exception) { if ($quiet) { - $failed?->__invoke(); + $failed?->__invoke(0); } else { $this->couldNotRefresh($exception->getMessage()); } @@ -132,7 +133,7 @@ protected function refresh(string $path, array $query, Closure $apply, bool $aga unset($this->refreshing[$key]); if ($quiet) { - $failed?->__invoke(); + $failed?->__invoke(0); } else { $this->couldNotRefresh('fatal: '.$exception->getMessage()); } @@ -219,7 +220,7 @@ protected function forgetRefreshes(): void * @param array{status?: int, json?: mixed, retry_after?: string, from_devnull?: bool} $result * @param array $query * @param Closure(array): void $apply - * @param (Closure(): void)|null $failed + * @param (Closure(int): void)|null $failed */ private function settleRefresh(array $result, string $path, array $query, Closure $apply, bool $quiet, ?Closure $failed = null, bool $withImages = false): void { @@ -247,7 +248,7 @@ private function settleRefresh(array $result, string $path, array $query, Closur } if ($quiet) { - $failed?->__invoke(); + $failed?->__invoke($status); return; } diff --git a/app/NativeComponents/Concerns/ShowsCommits.php b/app/NativeComponents/Concerns/ShowsCommits.php index 05407927..28c9c2d8 100644 --- a/app/NativeComponents/Concerns/ShowsCommits.php +++ b/app/NativeComponents/Concerns/ShowsCommits.php @@ -39,6 +39,9 @@ * * A commit can be tapped where a row nests it too: the commit a row quotes, * and the replies a feed shows under a commit. + * + * A commit is yours when you made it or an organization you're in did, as + * devnull decides it (see Ownership). */ trait ShowsCommits { @@ -210,8 +213,8 @@ public function showTime(string $id): void * star goes to devnull from the outbox (see SyncsOutbox). The commit takes * the count devnull sends back, or the star comes back off it if devnull * says no. Like the web, only someone else's published commit can be - * starred, as devnull turns down a star on your own (whose star opens who - * starred it instead, see OpensStargazers). + * starred, as devnull turns down a star on your own or your organization's + * (whose star opens who starred it instead, see OpensStargazers). */ public function toggleStar(string $id): void { @@ -228,7 +231,8 @@ public function toggleStar(string $id): void /** * Gives the commit a pastel, as the web's pastel button does in pastéis * mode: one per tap, from the ten you get each day, on someone else's - * published commit. Its count goes up and your allowance down at once, + * published commit, never an organization's, which has no pastel at all, + * as on the web. Its count goes up and your allowance down at once, * and the pastel goes from the background, so you can keep tapping. When * devnull turns one down, it comes back, and a toast says why in the web's * words. With none left, the toast says so without asking devnull. @@ -238,7 +242,7 @@ public function givePastel(string $id): void $commit = $this->shownCommit($id); $pasteis = app(Account::class)->pasteis(); - if ($commit === null || $pasteis === null || ! $this->canReactTo($commit)) { + if ($commit === null || $pasteis === null || ! $this->canGivePastel($commit)) { return; } @@ -258,8 +262,9 @@ public function givePastel(string $id): void /** * Pin to profile or Unpin from profile, in your own published commit's - * More menu. Once devnull answers, a toast says so in the web's words, and - * a pin takes the place of the one before (see showPinned()). + * More menu. Not an organization's: devnull pins to its author's profile, + * which only a person has. Once devnull answers, a toast says so in the + * web's words, and a pin takes the place of the one before (see showPinned()). */ public function togglePin(string $id): void { @@ -398,7 +403,8 @@ public function shareCommit(string $id): void } /** - * Delete commit, in your own commit's More menu, asks first, as the web does. + * Delete commit, in the More menu of your own commit or an organization's + * you're in, asks first, as the web does. */ public function confirmDelete(string $id): void { @@ -473,6 +479,11 @@ private function pastelGiven(string $id, array $json): void /** * Deletes your commit on devnull, which takes it out of every list kept on * this phone, then the screen lets it go (see showDeleted()). + * + * An organization's commit is only yours while you're in it. When devnull + * turns its delete down, the screen says why in devnull's words, and asks + * GET /me which organizations you're still in, so the commit stops + * offering Delete if you've left. */ public function deleteCommit(string $id): void { @@ -491,6 +502,8 @@ public function deleteCommit(string $id): void if ($deleted === true) { Toasts::say('rm '.$commit->shortHash.' → /dev/null', short: true); $this->showDeleted($id); + } elseif ($this->error !== null && $commit->author->isOrganization && method_exists($this, 'refreshUnreadNotifications')) { + $this->refreshUnreadNotifications(); } } @@ -533,17 +546,22 @@ private function pastelTurnedDown(string $id, ?ApiException $exception): void private function canReactTo(Commit $commit): bool { - return ! $commit->isDeleted() && $commit->isApproved() && $commit->author->id !== $this->me()?->id; + return ! $commit->isDeleted() && $commit->isApproved() && ! $this->ownership()->owns($commit); + } + + private function canGivePastel(Commit $commit): bool + { + return $this->canReactTo($commit) && ! $commit->author->isOrganization; } private function canPin(Commit $commit): bool { - return ! $commit->isDeleted() && $commit->isApproved() && $commit->parentId === null && $commit->author->id === $this->me()?->id; + return ! $commit->isDeleted() && $commit->isApproved() && $commit->parentId === null && $this->ownership()->isYourOwn($commit); } private function canDelete(Commit $commit): bool { - return ! $commit->isDeleted() && ! $commit->isStaged() && $commit->author->id === $this->me()?->id; + return ! $commit->isDeleted() && ! $commit->isStaged() && $this->ownership()->owns($commit); } /** diff --git a/app/NativeComponents/Concerns/TalksToDevnull.php b/app/NativeComponents/Concerns/TalksToDevnull.php index 246acbde..43d3b6a5 100644 --- a/app/NativeComponents/Concerns/TalksToDevnull.php +++ b/app/NativeComponents/Concerns/TalksToDevnull.php @@ -9,6 +9,7 @@ use App\Devnull\Exceptions\KeychainUnavailable; use App\Devnull\Exceptions\Unauthenticated; use App\Devnull\Lane; +use App\Devnull\Ownership; use Closure; /** @@ -62,6 +63,14 @@ protected function me(): ?User return app(Account::class)->user(); } + /** + * Which commits are yours: your own and your organizations' (see Ownership). + */ + protected function ownership(): Ownership + { + return app(Account::class)->ownership(); + } + /** * The theme token for your lane, which the main buttons and the pager tab * underlines are drawn in. diff --git a/app/NativeComponents/Concerns/VotesOnPolls.php b/app/NativeComponents/Concerns/VotesOnPolls.php index 0d6e38a9..d9c78538 100644 --- a/app/NativeComponents/Concerns/VotesOnPolls.php +++ b/app/NativeComponents/Concerns/VotesOnPolls.php @@ -35,7 +35,7 @@ public function choosePollOption(string $id, string $optionId): void { $commit = $this->shownCommit($id); - if ($commit === null || ! $commit->canBeVotedOnBy($this->me()) || ! in_array($optionId, array_map(fn ($option): string => $option->id, $commit->poll?->options ?? []), true)) { + if ($commit === null || ! $commit->canBeVotedOnBy($this->ownership()) || ! in_array($optionId, array_map(fn ($option): string => $option->id, $commit->poll?->options ?? []), true)) { return; } @@ -47,7 +47,7 @@ public function voteOnPoll(string $id): void $commit = $this->shownCommit($id); $choice = $this->pollChoices[$id] ?? null; - if ($commit === null || $choice === null || in_array($id, $this->voting, true) || ! $commit->canBeVotedOnBy($this->me())) { + if ($commit === null || $choice === null || in_array($id, $this->voting, true) || ! $commit->canBeVotedOnBy($this->ownership())) { return; } diff --git a/app/NativeComponents/Log.php b/app/NativeComponents/Log.php index 050e79e2..b9ffff17 100644 --- a/app/NativeComponents/Log.php +++ b/app/NativeComponents/Log.php @@ -6,9 +6,9 @@ use App\Devnull\Data\Commit; use App\Devnull\Data\Page; use App\Devnull\Data\TimelineRow; -use App\Devnull\Data\User; use App\Devnull\Display; use App\Devnull\LastVisit; +use App\Devnull\Ownership; use App\Devnull\ResponseCache; use App\Devnull\RowCache; use App\Devnull\RowWindow; @@ -1169,6 +1169,7 @@ public function render(): Element private function frame(): View { $viewer = $this->me(); + $ownership = $this->ownership(); foreach (self::Logs as $log) { $this->rowCache($log)->startFrame(); @@ -1184,14 +1185,15 @@ private function frame(): View 'loaded' => $this->loaded, 'lastVisitAt' => $this->lastVisitAt, 'error' => $this->error, - ], $viewer, $this->listKey) - : $this->page($log, $this->previewState($log), $viewer, $this->listKeys[$log] ?? 0), self::Logs); + ], $ownership, $this->listKey) + : $this->page($log, $this->previewState($log), $ownership, $this->listKeys[$log] ?? 0), self::Logs); $showing = $pages[array_search($this->log, self::Logs, true)]; return view('native.log', [ 'myColour' => $this->myColour(), 'viewer' => $viewer, + 'ownership' => $ownership, 'pasteis' => app(Account::class)->pasteis(), 'stashed' => app(Stash::class)->names($viewer?->id), 'newCommitsLabel' => $this->newCommitsLabel(), @@ -1208,7 +1210,7 @@ private function frame(): View * @param array $state * @return array */ - private function page(string $log, array $state, ?User $viewer, int $listKey): array + private function page(string $log, array $state, Ownership $ownership, int $listKey): array { /** @var list $commits */ $commits = $state['commits']; @@ -1216,7 +1218,7 @@ private function page(string $log, array $state, ?User $viewer, int $listKey): a $latestCommits = $state['latestCommits']; // Only the log you're on has who to follow: the others show their first few commits. $showsWhoToFollow = $log === $this->log && $this->showsWhoToFollow(); - $rows = $this->timeline($log, $latestCommits, $commits, $log === self::Ranked ? null : LastVisit::firstSeenId($commits, $state['lastVisitAt'], $viewer?->id), $showsWhoToFollow); + $rows = $this->timeline($log, $latestCommits, $commits, $log === self::Ranked ? null : LastVisit::firstSeenId($commits, $state['lastVisitAt'], $ownership), $showsWhoToFollow); return [ 'log' => $log, diff --git a/app/NativeComponents/Organization.php b/app/NativeComponents/Organization.php index c2f3718c..7a42a8ce 100644 --- a/app/NativeComponents/Organization.php +++ b/app/NativeComponents/Organization.php @@ -254,6 +254,7 @@ public function render(): View 'myColour' => $this->myColour(), 'newCommitsLabel' => $this->newCommitsLabel(), 'viewer' => $this->me(), + 'ownership' => $this->ownership(), 'stashed' => app(Stash::class)->names($this->me()?->id), 'pages' => $pages, 'pageIndex' => array_search($this->tab, self::Tabs, true), diff --git a/app/NativeComponents/Profile.php b/app/NativeComponents/Profile.php index d4c1e690..360f48c6 100644 --- a/app/NativeComponents/Profile.php +++ b/app/NativeComponents/Profile.php @@ -899,6 +899,7 @@ public function render(): View 'canRemote' => $this->canRemote(), 'newCommitsLabel' => $this->newCommitsLabel(), 'viewer' => $this->me(), + 'ownership' => $this->ownership(), 'stashed' => app(Stash::class)->names($this->me()?->id), 'pages' => $pages, 'pageIndex' => array_search($this->tab, self::Tabs, true), diff --git a/app/NativeComponents/Search.php b/app/NativeComponents/Search.php index c82ff53d..d05cd1a9 100644 --- a/app/NativeComponents/Search.php +++ b/app/NativeComponents/Search.php @@ -289,6 +289,7 @@ public function render(): View 'searchesCommits' => $this->searchesCommits($term), 'rowCache' => $this->rowCache, 'viewer' => $viewer, + 'ownership' => $this->ownership(), 'stashed' => app(Stash::class)->names($viewer?->id), 'myColour' => $this->myColour(), 'rows' => Timeline::ranked([], $this->commits), diff --git a/app/NativeComponents/Starred.php b/app/NativeComponents/Starred.php index fb69e42c..98fd4021 100644 --- a/app/NativeComponents/Starred.php +++ b/app/NativeComponents/Starred.php @@ -265,6 +265,7 @@ public function render(): View return view('native.starred', [ 'rowCache' => $this->rowCache, 'viewer' => $viewer, + 'ownership' => $this->ownership(), 'stashed' => app(Stash::class)->names($viewer?->id), 'myColour' => $this->myColour(), 'rows' => Timeline::feed($this->commits), diff --git a/resources/views/native/partials/commit-actions.blade.php b/resources/views/native/partials/commit-actions.blade.php index 5c86cf74..690aa60f 100644 --- a/resources/views/native/partials/commit-actions.blade.php +++ b/resources/views/native/partials/commit-actions.blade.php @@ -10,12 +10,14 @@ place, as on the web; elsewhere it opens the commit with its replies showing. Like the web, someone else's commit that isn't approved gets no star or Quote. devnull doesn't let you star your own commits, so on those the star is the count, which opens who starred it (see OpensStargazers), or a faint star until there are any, as on the web. + An organization's commit is yours while you're a member of it, whoever posted it ($ownership, see Ownership). Quote opens a sheet to write the quote in, over the commit being quoted (see commit-sheet). The pastel is the web's: the pastel de nata and how many the commit was given, always, even 0. On someone else's published commit it gives one more per tap; on your own, or one that isn't published, it's just the count. It - only shows in pastéis mode ($pasteis). + only shows in pastéis mode ($pasteis), and never on an organization's commit, which takes no pastéis, as the web + leaves it off. A commit with a quote or a reply you started and didn't send marks that button, as the web does with stash@{0} beside its label. That doesn't fit the row, so here it's a dot after the icon or label, inside the button's 44pt. @@ -44,15 +46,17 @@ @php($iconSize = $compact ? 14 : 16) @php($labelSize = $compact ? 'text-xs' : 'text-[13px]') @php($viewer ??= app(\App\Devnull\Account::class)->user()) +@php($ownership ??= app(\App\Devnull\Account::class)->ownership()) @php($stashed ??= []) @php($hasQuoteStash = in_array('quote-'.$commit->id, $stashed, true)) @php($hasReplyStash = in_array('reply-'.$commit->id, $stashed, true)) -@php($isOwn = $commit->author->id === $viewer?->id) +@php($isOwn = $ownership->owns($commit)) @php($canQuote = $commit->isApproved() || $isOwn) @php($hasThread = $expandable && $commit->replyPreview !== null) @php($showsReplies = $withReplies && ! $hasThread && $repliesCount > 0) @php($pasteis ??= app(\App\Devnull\Account::class)->pasteis()) -@php($canGivePastel = $pasteis !== null && $viewer !== null && ! $isOwn && $commit->isApproved()) +@php($showsPastel = $pasteis !== null && ! $commit->author->isOrganization) +@php($canGivePastel = $showsPastel && $viewer !== null && ! $isOwn && $commit->isApproved()) @php($pastelLabel = \App\Devnull\Display::count($commit->pasteisCount, 'pastel', 'pastéis')) @php($pastelSize = $compact ? 18 : 20) @php($starLabel = ($commit->starred ? 'Unstar commit' : 'Star commit').($commit->starsCount > 0 ? ', '.\App\Devnull\Display::count($commit->starsCount, 'star', 'stars') : '')) @@ -80,7 +84,7 @@ {{ \App\Devnull\Display::compactCount($commit->pasteisCount) }} - @elseif ($pasteis !== null) + @elseif ($showsPastel) {{ \App\Devnull\Display::compactCount($commit->pasteisCount) }} @@ -122,7 +126,7 @@ - + diff --git a/resources/views/native/partials/commit-poll.blade.php b/resources/views/native/partials/commit-poll.blade.php index 9df5bc5a..ea6028ae 100644 --- a/resources/views/native/partials/commit-poll.blade.php +++ b/resources/views/native/partials/commit-poll.blade.php @@ -4,14 +4,14 @@ its percentage in mono on the right, and "4 votes · 3h left" under them all. Without results, the options are plain boxes over the time left. - On someone else's published commit whose poll is open and has no vote of yours yet, you vote as on the web: tap an - option to pick it, its box in Commit Blue on Blue Wash with its radio filled, then Vote, beside the time left, - since votes are final (see VotesOnPolls). Vote spins while it goes, and the poll then shows its results. $static - is the quote card's copy, which never votes. + On a published commit that isn't yours or your organization's, whose poll is open and has no vote of yours yet, you + vote as on the web: tap an option to pick it, its box in Commit Blue on Blue Wash with its radio filled, then Vote, + beside the time left, since votes are final (see VotesOnPolls). Vote spins while it goes, and the poll then shows + its results. $static is the quote card's copy, which never votes. --}} @php($poll = $commit->poll) @php($static ??= false) -@php($canVote = ! $static && $commit->canBeVotedOnBy($viewer ?? app(\App\Devnull\Account::class)->user())) +@php($canVote = ! $static && $commit->canBeVotedOnBy($ownership ?? app(\App\Devnull\Account::class)->ownership())) @php($choice = $pollChoices[$commit->id] ?? null) @php($isVoting = in_array($commit->id, $voting ?? [], true)) diff --git a/resources/views/native/partials/stargazers-sheet.blade.php b/resources/views/native/partials/stargazers-sheet.blade.php index f20394b8..1d3d9253 100644 --- a/resources/views/native/partials/stargazers-sheet.blade.php +++ b/resources/views/native/partials/stargazers-sheet.blade.php @@ -3,6 +3,9 @@ then each of them, newest first, with their avatar, name and handle. A tap opens them. While a page loads, skeleton rows stand in for up to three of them. When one doesn't load, the web's line says so, with Try again, and while there are more, Show more. Nothing is drawn until the sheet opens. + + On an organization's commit that a different member posted, devnull's API won't list who starred it, though the + web does, so the sheet says that instead ($stargazersForPoster). --}} @if ($stargazersOf !== null) @@ -34,7 +37,9 @@ @endif - @if ($stargazersFailed) + @if ($stargazersForPoster) + Only the member who posted this commit can see who starred it here. + @elseif ($stargazersFailed) fatal: could not load stars Try again diff --git a/tests/Feature/Screens/OrganizationCommitsTest.php b/tests/Feature/Screens/OrganizationCommitsTest.php new file mode 100644 index 00000000..d540573e --- /dev/null +++ b/tests/Feature/Screens/OrganizationCommitsTest.php @@ -0,0 +1,256 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * NativePHP as `GET /me` lists an organization you're in. + * + * @return array + */ +function nativephpMembershipJson(): array +{ + return [ + 'type' => 'organization', + 'id' => 'o-nativephp', + 'role' => 'member', + 'handle' => 'nativephp', + 'name' => 'NativePHP', + 'avatar_url' => 'https://avatars.githubusercontent.com/u/7?v=4', + 'github_url' => 'https://github.com/nativephp', + 'html_url' => 'http://devnull.test/@nativephp', + 'lane' => 5, + ]; +} + +/** + * A commit from NativePHP, posted by whichever member it was: devnull never says who. + * + * @param array $overrides + * @return array + */ +function nativephpCommitJson(array $overrides = []): array +{ + return commitJson(['author' => ['type' => 'organization', 'id' => 'o-nativephp', 'handle' => 'nativephp', 'name' => 'NativePHP', 'lane' => 5], ...$overrides]); +} + +/** + * Makes you a member of NativePHP, as the last `GET /me` said. + */ +function joinNativephp(): void +{ + app(Account::class)->rememberOrganizations(CurrentUser::fromArray(currentUserJson(['organizations' => [nativephpMembershipJson()]]))->organizations); +} + +/** + * The Log showing NativePHP's commit c1, with the API answering $routes besides. + * + * @param array $commit + * @param array $routes + */ +function nativephpCommitOnLog(array $commit = [], array $routes = []): TestableComponent +{ + serveApi([ + 'GET /api/v1/log/following' => [pageJson([nativephpCommitJson(['id' => 'c1', 'body' => 'NativePHP ships', ...$commit])])], + ...$routes, + ]); + + return Native::visit('/log', platform: 'ios'); +} + +it('treats an organization\'s commit as yours when you\'re a member, whoever posted it', function () { + joinNativephp(); + app(Account::class)->rememberPasteis(new Pasteis(Pasteis::Daily, CarbonImmutable::now()->addDay())); + + $screen = nativephpCommitOnLog(['stars_count' => 2]); + + // Delete, as for your own, but no Pin: devnull pins to a person's profile. No Report, as devnull won't take one. + expect(menuItems($screen, 'more-c1'))->toBe([ + ['share-c1', 'Share link', 'custom:link'], + 'divider', + ['delete-c1', 'Delete commit', 'custom:trash-2'], + ]) + // You can't star it, so its star is the count, as on your own. + ->and(rendersRef($screen, 'star-c1'))->toBeFalse() + ->and(nodeByRef($screen, 'star-count-c1')['props']['a11y_label'])->toBe('2 stars, show who starred') + // An organization's commit takes no pastéis from anyone, so the web shows none. + ->and(rendersRef($screen, 'pastel-c1'))->toBeFalse() + ->and(rendersRef($screen, 'pastel-count-c1'))->toBeFalse(); + + $screen->call('toggleStar', 'c1') + ->call('givePastel', 'c1') + ->call('reportCommit', 'c1') + ->call('togglePin', 'c1') + ->assertSet('sheetOpen', false); + + Http::assertNotSent(fn (Request $request): bool => $request->method() !== 'GET'); +}); + +it('lets a member delete an organization\'s commit they didn\'t post', function () { + joinNativephp(); + $deleted = false; + + serveApi(function (Request $request) use (&$deleted) { + return match ($request->method().' '.parse_url($request->url(), PHP_URL_PATH)) { + 'DELETE /api/v1/commits/c1' => tap(Http::response(null, 204), function () use (&$deleted): void { + $deleted = true; + }), + 'GET /api/v1/log/following' => Http::response(pageJson([ + ...($deleted ? [] : [nativephpCommitJson(['id' => 'c1', 'body' => 'Delete me'])]), + commitJson(['id' => 'c2', 'body' => 'Keep me']), + ])), + default => Http::response(currentUserJson(['organizations' => [nativephpMembershipJson()]])), + }; + }); + + Native::visit('/log', platform: 'ios') + ->tap('delete-c1') + ->assertNativeCalled('Dialog.Alert', fn (array $params): bool => $params['title'] === 'Delete this commit?') + ->emitNative(ButtonPressed::class, ['index' => 1, 'label' => 'Delete', 'id' => 'delete-commit']) + ->assertNativeCalled('ToastKit.Show', fn (array $params): bool => str_starts_with($params['message'], 'rm ')) + ->assertDontSee('Delete me') + ->assertSee('Keep me'); + + Http::assertSent(fn (Request $request): bool => $request->method() === 'DELETE' && $request->url() === 'http://devnull.test/api/v1/commits/c1'); +}); + +it('puts Delete in the nav bar of an organization\'s commit page for a member', function () { + joinNativephp(); + fakeApi(['GET /api/v1/commits/c1' => [commitPageJson(nativephpCommitJson(['id' => 'c1']))]]); + + Native::visit('/log/commits/c1', platform: 'ios') + ->assertElement('top_bar_action', fn (array $node): bool => ($node['props']['id'] ?? null) === 'delete'); +}); + +it('offers someone outside the organization a star, the pastel and Report, never Delete', function () { + app(Account::class)->rememberPasteis(new Pasteis(Pasteis::Daily, CarbonImmutable::now()->addDay())); + + $screen = nativephpCommitOnLog(); + + expect(menuItems($screen, 'more-c1'))->toBe([ + ['share-c1', 'Share link', 'custom:link'], + 'divider', + ['report-c1', 'Report commit', 'custom:flag'], + ]) + ->and(rendersRef($screen, 'star-c1'))->toBeTrue() + // Still no pastel: it would go to whoever posted it. + ->and(rendersRef($screen, 'pastel-c1'))->toBeFalse() + ->and(rendersRef($screen, 'pastel-count-c1'))->toBeFalse(); + + $screen->call('confirmDelete', 'c1')->call('deleteCommit', 'c1'); + + Http::assertNotSent(fn (Request $request): bool => $request->method() === 'DELETE'); +}); + +it('lets a member quote an organization\'s commit still waiting for approval, as the web does', function () { + $screen = nativephpCommitOnLog(['status' => 'pending']); + + expect(rendersRef($screen, 'quote-c1'))->toBeFalse(); + + joinNativephp(); + $screen = nativephpCommitOnLog(['status' => 'pending']); + + expect(rendersRef($screen, 'quote-c1'))->toBeTrue(); + + $screen->call('quoteCommit', 'c1')->assertSet('sheetOpen', true); +}); + +it('doesn\'t let a member vote on an organization\'s poll', function () { + $poll = [ + 'id' => 'poll1', + 'closes_at' => now()->addDay()->toIso8601ZuluString(), + 'is_closed' => false, + 'has_voted' => false, + 'total_votes' => null, + 'options' => [ + ['id' => 'o1', 'label' => 'Tabs', 'votes_count' => null, 'voted' => false, 'percentage' => null], + ['id' => 'o2', 'label' => 'Spaces', 'votes_count' => null, 'voted' => false, 'percentage' => null], + ], + ]; + + expect(rendersRef(nativephpCommitOnLog(['poll' => $poll]), 'poll-vote-c1'))->toBeTrue(); + + joinNativephp(); + $screen = nativephpCommitOnLog(['poll' => $poll]); + + expect(rendersRef($screen, 'poll-vote-c1'))->toBeFalse(); + + $screen->call('choosePollOption', 'c1', 'o1')->call('voteOnPoll', 'c1'); + + Http::assertNotSent(fn (Request $request): bool => str_ends_with($request->url(), Client::pollVotesPath('c1'))); +}); + +it('says devnull\'s no when you\'ve left the organization, and stops offering Delete once /me says so', function () { + joinNativephp(); + $left = false; + + serveApi(function (Request $request) use (&$left) { + return match ($request->method().' '.parse_url($request->url(), PHP_URL_PATH)) { + 'DELETE /api/v1/commits/c1' => tap(Http::response(['message' => 'This action is unauthorized.'], 403), function () use (&$left): void { + $left = true; + }), + 'GET /api/v1/log/following' => Http::response(pageJson([nativephpCommitJson(['id' => 'c1', 'body' => 'NativePHP ships'])])), + default => Http::response(currentUserJson(['organizations' => $left ? [] : [nativephpMembershipJson()]])), + }; + }); + + $screen = Native::visit('/log', platform: 'ios'); + $asked = count(sentTo('GET', 'me')); + + $screen->tap('delete-c1') + ->emitNative(ButtonPressed::class, ['index' => 1, 'label' => 'Delete', 'id' => 'delete-commit']) + ->assertSee('This action is unauthorized.') + ->assertSee('NativePHP ships'); + + expect(sentTo('GET', 'me'))->toHaveCount($asked + 1) + ->and(app(Account::class)->organizations())->toBe([]) + ->and(menuItems($screen, 'more-c1'))->toBe([ + ['share-c1', 'Share link', 'custom:link'], + 'divider', + ['report-c1', 'Report commit', 'custom:flag'], + ]); +}); + +it('lists who starred an organization\'s commit, or says only the member who posted it can', function () { + joinNativephp(); + + nativephpCommitOnLog(['stars_count' => 1], ['GET /api/v1/commits/c1/stars' => [pageJson([userJson(['id' => 'u-grace', 'handle' => 'grace', 'name' => 'Grace Hopper'])], path: 'http://devnull.test/api/v1/commits/c1/stars')]]) + ->tap('star-count-c1') + ->assertSee('Grace Hopper') + ->assertDontSee('Only the member who posted this commit can see who starred it here.'); + + // The API answers someone who didn't post it as though the list isn't there, where the web shows it them. + nativephpCommitOnLog(['stars_count' => 1], ['GET /api/v1/commits/c1/stars' => [['message' => 'Not found.'], 404]]) + ->tap('star-count-c1') + ->assertSee('Only the member who posted this commit can see who starred it here.') + ->assertDontSee('fatal: could not load stars') + ->assertDontSee('Try again'); +}); + +it('keeps an organization\'s commits off your profile\'s count, posted or deleted', function () { + keep('users/local_dev', ['data' => userWithCountsJson(commits: 3)]); + keep('users/local_dev/commits', pageJson([commitJson(['id' => 'c0'])])); + keep('log/following', pageJson([nativephpCommitJson(['id' => 'c1']), commitJson(['id' => 'c0'])])); + fakeApi(['DELETE /api/v1/commits/c1' => [null, 204]]); + + app(ResponseCache::class)->commitAdded(nativephpCommitJson(['id' => 'c2'])); + app(Client::class)->deleteCommit('c1'); + + expect(kept('users/local_dev')['data']['commits_count'])->toBe(3) + ->and(array_column(kept('users/local_dev/commits')['data'], 'id'))->toBe(['c0']) + ->and(array_column(kept('log/following')['data'], 'id'))->toBe(['c2', 'c0']); +}); diff --git a/tests/Unit/Devnull/TimelineTest.php b/tests/Unit/Devnull/TimelineTest.php index b21edb2a..c68a082b 100644 --- a/tests/Unit/Devnull/TimelineTest.php +++ b/tests/Unit/Devnull/TimelineTest.php @@ -3,6 +3,7 @@ use App\Devnull\Data\Commit; use App\Devnull\Data\TimelineRow; use App\Devnull\LastVisit; +use App\Devnull\Ownership; use App\Devnull\Timeline; use Carbon\CarbonImmutable; @@ -166,14 +167,18 @@ function describeRows(array $rows): array timelineCommit('c1', 'grace', '2026-10-15T09:00:00Z'), ]; - expect(LastVisit::firstSeenId($commits, '2026-10-15T10:00:00+00:00', 'ada'))->toBe('c2') - ->and(LastVisit::firstSeenId($commits, '2026-10-15T09:30:00+00:00', 'ada'))->toBe('c1') + $ada = new Ownership('ada'); + + expect(LastVisit::firstSeenId($commits, '2026-10-15T10:00:00+00:00', $ada))->toBe('c2') + ->and(LastVisit::firstSeenId($commits, '2026-10-15T09:30:00+00:00', $ada))->toBe('c1') // Nothing new. - ->and(LastVisit::firstSeenId($commits, '2026-10-15T11:00:00+00:00', 'ada'))->toBeNull() + ->and(LastVisit::firstSeenId($commits, '2026-10-15T11:00:00+00:00', $ada))->toBeNull() // Only your own commit is new. - ->and(LastVisit::firstSeenId($commits, '2026-10-15T10:00:00+00:00', 'grace'))->toBeNull() + ->and(LastVisit::firstSeenId($commits, '2026-10-15T10:00:00+00:00', new Ownership('grace')))->toBeNull() + // Only a commit from an organization you're in is new, as the web counts it. + ->and(LastVisit::firstSeenId($commits, '2026-10-15T10:00:00+00:00', new Ownership('linus', ['grace'])))->toBeNull() // Everything is new, so there's nothing to mark. - ->and(LastVisit::firstSeenId($commits, '2026-10-15T08:00:00+00:00', 'ada'))->toBeNull() + ->and(LastVisit::firstSeenId($commits, '2026-10-15T08:00:00+00:00', $ada))->toBeNull() // A first visit. - ->and(LastVisit::firstSeenId($commits, null, 'ada'))->toBeNull(); + ->and(LastVisit::firstSeenId($commits, null, $ada))->toBeNull(); }); From 61856995f9b9672941f77d24ae727fe3cf05af6b Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 16:28:44 +0000 Subject: [PATCH 10/30] Draw one line above related commits, not the commit's hairline as well With its replies shut, the last row on a commit page kept its hairline, which starts at the text column, right on top of the related commits' full-width top border. Together they read as a stray line above "Related commits". The last row now leaves its hairline out when related commits follow it, and keeps it above "No replies yet" or at the end of the page. With the replies open the last reply already ends with no hairline, so either way only the full-width line shows. Co-Authored-By: Claude Opus 5.5 --- .../views/native/commit-detail.blade.php | 11 +++++- tests/Feature/Screens/RelatedCommitsTest.php | 36 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 3667a822..b1c2f5f4 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -30,6 +30,14 @@ @include('native.partials.earlier-commits', ['count' => $earlierCount, 'lane' => $earlierLane]) @endif + {{-- + Related commits start with a full-width line of their own (see partials/related-commits). The last row + above them leaves out its hairline, which runs from the text's edge, so the two don't stack up into a + line and a half. Replies end with no hairline on a commit page, and "No replies yet" keeps the commit's. + --}} + @php($noReplies = $commit && $replyCount === 0 && $repliesLoaded && $series === []) + @php($relatedBelow = $commit && $related !== [] && ! $noReplies) + @foreach ($rows as $row) @php($isFocused = $row->commit->id === $commit?->id) @php($hasThread = $isFocused && $repliesShown && $replies !== []) @@ -43,6 +51,7 @@ 'muted' => ! $isFocused, 'seriesExpanded' => true, 'withTail' => ! $loop->last, + 'hairline' => ! ($loop->last && $relatedBelow), ]) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) @@ -95,7 +104,7 @@ @endif @endforeach - @if ($commit && $replyCount === 0 && $repliesLoaded && $series === []) + @if ($noReplies) No replies yet. diff --git a/tests/Feature/Screens/RelatedCommitsTest.php b/tests/Feature/Screens/RelatedCommitsTest.php index 9e8f15b6..d493ad73 100644 --- a/tests/Feature/Screens/RelatedCommitsTest.php +++ b/tests/Feature/Screens/RelatedCommitsTest.php @@ -244,6 +244,42 @@ function openRelated(TestableComponent $screen): TestableComponent expect(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'] ?? 0.0)->toEqual(0.0); })->with(['ios', 'android']); +it("draws one full-width line above related commits, with the replies shut or open, and no hairline from the commit's text", function (string $platform) { + serveRelatedThread([commitJson(['id' => 'c9', 'body' => 'Closest match'])], [ + 'GET /api/v1/commits/c1' => [commitPageJson(commitJson(['id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 1]))], + 'GET /api/v1/commits/c1/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'A reply'])])], + ]); + + $screen = Native::visit('/log/commits/c1', platform: $platform)->assertSee('Related commits'); + $commitLine = fn (): float => (float) (nodeByRef($screen, 'focused-commit')['children'][0]['props']['border_b'] ?? 0); + $relatedLine = fn (): float => (float) (nodeByRef($screen, 'related-commits')['props']['border_t'] ?? 0); + + // Shut, the commit sits right on the section, whose line is the only one. + expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'related-commits', 'reply-bar-clearance']) + ->and($commitLine())->toBe(0.0) + ->and($relatedLine())->toBe(1.0); + + // Open, the last reply ends with no hairline of its own, so the section's line is still the only one. + $screen->tap('replies-c1')->assertSee('A reply'); + expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) + ->and($commitLine())->toBe(0.0) + ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-end-r1'))->toBeNull() + ->and($relatedLine())->toBe(1.0); +})->with(['ios', 'android']); + +it('keeps the hairline under the commit when nothing comes after it, or "No replies yet" does', function (array $commit, array $related) { + serveRelatedThread($related, [ + 'GET /api/v1/commits/c1' => [commitPageJson(commitJson(['id' => 'c1', 'body' => 'The focused commit', ...$commit]))], + ]); + + $screen = Native::visit('/log/commits/c1'); + + expect((float) (nodeByRef($screen, 'focused-commit')['children'][0]['props']['border_b'] ?? 0))->toBe(1.0); +})->with([ + 'no related commits' => [['replies_count' => 1], []], + 'no replies yet' => [['replies_count' => 0], [commitJson(['id' => 'c9', 'body' => 'Closest match'])]], +]); + it('fades related commits in one after another as they open, and out together as they close', function () { holdRefreshes(); serveRelatedThread([ From 01cb5784a43f43a1aabbdb2021df80b7068f24d4 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 16:30:19 +0000 Subject: [PATCH 11/30] Turn the commit page's replies chevron down while they show, as on the Log The replies button's chevron only turned in feeds, where the replies open in place. A commit page opens its commit's replies in place too, but there the chevron kept pointing right with "Hide replies" beside it. It now turns down there as well, over the same 220ms, and carries the animation while shut so iOS animates the first turn. A reply's button on a commit page still opens its page, so its chevron stays put. Co-Authored-By: Claude Opus 5.5 --- .../native/partials/commit-actions.blade.php | 7 ++++++- tests/Feature/Screens/CommitDetailTest.php | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/resources/views/native/partials/commit-actions.blade.php b/resources/views/native/partials/commit-actions.blade.php index 9f0e361d..a73854dc 100644 --- a/resources/views/native/partials/commit-actions.blade.php +++ b/resources/views/native/partials/commit-actions.blade.php @@ -34,6 +34,10 @@ A commit page opens its replies under its commit in place: it passes what the toggle presses ($repliesToggle), whether they're open ($repliesOpen) and how many there are ($repliesCount). $compact draws the row smaller, for the commits around the one a page is about. + + Wherever the button opens the replies in place, in a feed or on a commit page, its chevron turns down while they + show and back as they close, over the time a feed's thread takes to fade (ThreadRows::Fade). The chevron carries + the animation shut as well as open: iOS only animates a change on a node that already had it. --}} @php($withReply ??= true) @php($withReplies ??= true) @@ -42,6 +46,7 @@ @php($expandable ??= isset($threads)) @php($isOpen = $repliesOpen ?? ($expandable && array_key_exists($commit->id, $threads) && ! in_array($commit->id, $closingThreads ?? [], true))) @php($repliesPress = $repliesToggle ?? ($expandable ? "toggleReplies('{$commit->id}')" : "openReplies('{$commit->id}')")) +@php($opensInPlace = $expandable || isset($repliesToggle)) @php($repliesCount ??= $commit->repliesCount) @php($iconSize = $compact ? 14 : 16) @php($labelSize = $compact ? 'text-xs' : 'text-[13px]') @@ -127,7 +132,7 @@ @if ($showsReplies) - + {{ $isOpen ? 'Hide replies' : \App\Devnull\Display::count($repliesCount, 'reply', 'replies') }} @endif diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index d1e271be..ff73f4ba 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -411,6 +411,26 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): Native::visit('/log/commits/c2')->call('openProfile', 'ada')->assertNavigatedTo('/log/users/ada'); }); +it("turns the replies button's chevron down while the replies show, as the Log does, and back as they close", function (string $platform) { + fakeThread(['replies_count' => 1], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1])]); + + $screen = Native::visit('/log/commits/c2', platform: $platform); + $chevron = fn (string $ref): array => findNode(nodeByRef($screen, $ref), fn (array $node): bool => ($node['type'] ?? null) === 'icon'); + + // Shut, it points right, and already carries the animation, so the turn animates on iOS. + expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 0.0, 'animate-duration' => 220.0]); + + $screen->tap('replies-c2')->assertSee('First reply')->assertSee('Hide replies'); + expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 90.0, 'animate-duration' => 220.0]); + + $screen->tap('replies-c2')->assertDontSee('First reply')->assertSee('1 reply'); + expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 0.0, 'animate-duration' => 220.0]); + + // A reply's button opens its page rather than its replies in place, so its chevron stays put. + $screen->tap('replies-c2'); + expect($chevron('replies-r1')['props'])->not->toHaveKey('rotate'); +})->with(['ios', 'android']); + it('opens with its replies showing from a replies button', function () { fakeThread(['replies_count' => 1], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1])], extra: [ 'GET /api/v1/commits/r1' => [commitPageJson(replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1]))], From c8f904ebbf08d84b08a1fc2ec9891f352cca6698 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 22:53:32 +0000 Subject: [PATCH 12/30] Show avatars in the Post as menu Each account in the menu now shows its avatar, round for you and a rounded square for an organization, as the app draws them elsewhere. The person or building icon stands in while an avatar loads or when there isn't one. Whoever posts now keeps the tick, which iOS and Android draw as their own menus do. Needs NativePHP/mobile-ui feat/menu-item-images, which teaches menu rows the image, image_shape and checked props. Without it the rows show the icons and lose the tick. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/PostAs.php | 39 ++++++++++++++-------------- tests/Feature/Screens/PostAsTest.php | 31 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/app/Devnull/PostAs.php b/app/Devnull/PostAs.php index 03902d77..d57f5fb7 100644 --- a/app/Devnull/PostAs.php +++ b/app/Devnull/PostAs.php @@ -56,19 +56,27 @@ public static function offered(?string $picked): bool } /** - * The menu: you first, then your organizations, the one posting now ticked. $method is called with the handle - * picked, or '' for you. + * The menu: you first, then your organizations, each with their avatar, round for you and a rounded square for + * an organization, as elsewhere in the app, and the one posting now ticked. Until an avatar loads, or if it + * can't, a person or building icon stands in. $method is called with the handle picked, or '' for you. * * @return list */ public static function menu(User $me, ?User $author, string $method): array { - return array_map(fn (User $identity): TopBarAction => NavAction::make('post-as-'.$identity->username) - ->label($identity->name.' (@'.$identity->username.')') - ->icon(...self::icon($identity, $author)) - ->press($method."('".($identity->isOrganization ? $identity->username : '')."')") - ->toElement() - ->ref('post-as-'.$identity->username), [$me, ...self::organizations()]); + return array_map(function (User $identity) use ($author, $method): TopBarAction { + $icon = $identity->isOrganization ? Lucide::Building2 : Lucide::UserRound; + + return NavAction::make('post-as-'.$identity->username) + ->label($identity->name.' (@'.$identity->username.')') + ->icon(ios: $icon->ios(), android: $icon->android()) + ->image(ImageCache::src($identity->avatarUrl)) + ->press($method."('".($identity->isOrganization ? $identity->username : '')."')") + ->toElement() + ->setProp('image_shape', $identity->isOrganization ? 'rounded' : 'circle') + ->setProp('checked', self::posting($identity, $author)) + ->ref('post-as-'.$identity->username); + }, [$me, ...self::organizations()]); } /** @@ -88,19 +96,10 @@ public static function colour(User $me, ?User $author): string } /** - * A tick beside whoever posts now, and what each is beside the rest, as the menu has no room for avatars. - * - * @return array{ios: string, android: string} + * Whether the menu ticks this one: whoever posts now. */ - private static function icon(User $identity, ?User $author): array + private static function posting(User $identity, ?User $author): bool { - $posting = $author === null ? ! $identity->isOrganization : $identity->isOrganization && $identity->username === $author->username; - $icon = match (true) { - $posting => Lucide::Check, - $identity->isOrganization => Lucide::Building2, - default => Lucide::UserRound, - }; - - return ['ios' => $icon->ios(), 'android' => $icon->android()]; + return $author === null ? ! $identity->isOrganization : $identity->isOrganization && $identity->username === $author->username; } } diff --git a/tests/Feature/Screens/PostAsTest.php b/tests/Feature/Screens/PostAsTest.php index 2b195312..21550679 100644 --- a/tests/Feature/Screens/PostAsTest.php +++ b/tests/Feature/Screens/PostAsTest.php @@ -3,6 +3,7 @@ use App\Devnull\Account; use App\Devnull\Data\CurrentUser; use App\Devnull\Data\User; +use App\Icons\Lucide; use App\Models\PendingWrite; use Carbon\CarbonImmutable; use Illuminate\Http\Client\Request; @@ -118,6 +119,36 @@ function commitsSent(): array ->assertMissingElement('pressable', fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-post-as'); }); +it('draws each account in the Post as menu with its avatar, round for you, square for an organization, and ticks who posts now', function () { + memberOf([memberOrganizationJson(), memberOrganizationJson(['id' => 'o2', 'handle' => 'nativephp', 'name' => 'NativePHP', 'role' => 'member', 'avatar_url' => null])]); + + $screen = composeOnLogAs(); + + $rows = fn (): array => array_map(fn (array $item): array => [ + $item['ref'], + $item['props']['image'] ?? null, + $item['props']['image_shape'], + $item['props']['checked'], + $item['props']['icon'], + ], array_values(array_filter(nodeByRef($screen, 'sheet-post-as')['children'], fn (array $child): bool => $child['type'] === 'top_bar_action'))); + + $me = app(Account::class)->user(); + $person = Lucide::UserRound->ios(); + $building = Lucide::Building2->ios(); + + expect($me->avatarUrl)->not->toBeNull() + ->and($rows())->toBe([ + ['post-as-local_dev', $me->avatarUrl, 'circle', true, $person], + ['post-as-dev-null-sh', 'https://avatars.githubusercontent.com/u/9?v=4', 'rounded', false, $building], + // No avatar: the building stands in. + ['post-as-nativephp', null, 'rounded', false, $building], + ]); + + $screen->call('postAsInSheet', 'dev-null-sh'); + + expect(array_column($rows(), 3))->toBe([false, true, false]); +}); + it('starts the composer as you, and lists you and your organizations under Post as', function () { memberOf([memberOrganizationJson(), memberOrganizationJson(['id' => 'o2', 'handle' => 'nativephp', 'name' => 'NativePHP', 'role' => 'member', 'lane' => 5])]); From d5cf93dc149173a3103881a6399fa77c42b10d67 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 01:01:00 +0000 Subject: [PATCH 13/30] Even out the reply bar's spacing and lighten its glass The reply field sat 20pt under the fade and only 8pt above the row of tools. The reply row drops its 8pt top padding and the field row gains 8pt underneath, so the field is 12pt under the fade and 16pt above the tools. The bar is the same height as before. On iOS the bar now asks mobile-air for its glass at 0.8 opacity (glass-opacity on native:bottom-bar, NativePHP/mobile-air#735), so a little more of the page shows through. Android draws no glass and is unchanged. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Display.php | 15 +++++++++++ .../views/native/commit-detail.blade.php | 5 ++-- .../native/partials/composer-box.blade.php | 6 +++-- tests/Feature/Screens/CommitDetailTest.php | 27 +++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index a6aeb0bb..8e736203 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -44,6 +44,12 @@ final class Display */ public const int ComposerGlassTint = 40; + /** + * How opaque the glass under the reply bar gets on iOS once it has faded in, from 0 to 1 (see + * replyBarGlassOpacity()). mobile-air's own default is 1, which over a dark page reads as a heavy slab. + */ + public const float ReplyBarGlassOpacity = 0.8; + /** * About how many characters fit on a line of the box's field, which runs the width of the box. */ @@ -308,6 +314,15 @@ public static function composerBarGlass(): string return self::fadesInBar() ? 'glass' : ''; } + /** + * The reply bar's glass-opacity: how opaque mobile-air's glass behind the bar gets on iOS once it has faded in, + * so a little more of the page shows through. Null on Android, which draws no glass behind a bottom bar. + */ + public static function replyBarGlassOpacity(): ?float + { + return self::fadesInBar() ? self::ReplyBarGlassOpacity : null; + } + /** * The composer bar's own classes. On Android it's the surface. On iOS it has no background at all: mobile-air * paints a bar's background colour behind the whole bar, which would cover the fade at its top, so the bar's diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index bf62a9b4..ce9a027f 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -151,7 +151,7 @@ --}} @php($replyPostingMe = app(\App\Devnull\Account::class)->user()) @php($replyPostsAs = $replyPostingMe !== null && \App\Devnull\PostAs::offered($replyAuthor)) - + @if (\App\Devnull\Display::fadesInBar()) @include('native.partials.composer-fade', ['ref' => 'reply-fade', 'inBar' => true]) @@ -173,12 +173,13 @@ @include('native.partials.composer-photos', ['photos' => $replyImages, 'photoRef' => 'reply-photo']) @endif - + @php($hasDraft = trim($reply) !== '' || $replyImages !== []) @php($photosFull = count($replyImages) >= \App\Devnull\DraftImages::MaxImages) @include('native.partials.composer-box', [ 'ref' => 'reply', 'field' => $replyPreviewing ? 'native.partials.reply-preview' : 'native.partials.reply-field', + 'fieldPadding' => 'pt-1 pb-2', 'lead' => $replyPostsAs ? [['native.partials.post-as', ['ref' => 'reply-post-as', 'me' => $replyPostingMe, 'picked' => $replyAuthor, 'method' => 'postAsInReply', 'size' => 28, 'inset' => 'pl-3']]] : [], 'tools' => [ ['ref' => 'reply-add-photos', 'icon' => \App\Icons\Lucide::ImagePlus, 'label' => $photosFull ? 'A reply can have up to 3 photos' : 'Add photos', 'menu' => $photosFull ? null : \App\Devnull\ComposerMenu::photoItems(), 'disabled' => $photosFull], diff --git a/resources/views/native/partials/composer-box.blade.php b/resources/views/native/partials/composer-box.blade.php index 5cb53133..c036c99c 100644 --- a/resources/views/native/partials/composer-box.blade.php +++ b/resources/views/native/partials/composer-box.blade.php @@ -11,12 +11,14 @@ row, ahead of the tools, and for the end, left of the send button, such as the count of a long draft. $send is send-button's: its ref, label, method, and whether it can send yet. - The field's text lines up with the tools' icons under it. + The field's text lines up with the tools' icons under it. $fieldPadding is the field row's padding above and below + the field (pt-1 by default), for a bar that wants more room between the field and the row under it. --}} @php($lead ??= []) +@php($fieldPadding ??= 'pt-1') @php($trail ??= []) - + @include($field) diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 8b692e51..7e0360c4 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -7,6 +7,7 @@ use App\Models\PendingWrite; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; +use Native\Mobile\Edge\Elements\BottomBar; use Native\Mobile\Events\Alert\ButtonPressed; use Native\Mobile\Testing\Native; @@ -901,6 +902,32 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): } })->with(['ios', 'android']); +it('keeps the reply field closer to the fade than to the row of tools under it', function (string $platform) { + fakeThread(); + + $screen = Native::visit('/log/commits/c2', platform: $platform); + + // [top, right, bottom, left]. The row has no top padding, so the field starts 4pt under the fade, and the field + // row leaves 8pt between the field and the tools. + expect(nodeByRef($screen, 'reply-row')['layout']['padding'])->toEqual([0, 16, 8, 16]) + ->and(nodeByRef($screen, 'reply-field-row')['layout']['padding'])->toEqual([4, 12, 8, 16]); +})->with(['ios', 'android']); + +it('asks mobile-air for a lighter glass under the reply bar on iOS only', function (string $platform, ?float $opacity) { + fakeThread(); + + $screen = Native::visit('/log/commits/c2', platform: $platform); + $bottomBar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); + + expect($bottomBar['props']['glass_opacity'] ?? null)->toBe($opacity); +})->with([ + 'ios' => ['ios', Display::ReplyBarGlassOpacity], + 'android' => ['android', null], +])->skip( + ! method_exists(BottomBar::class, 'glassOpacity'), + 'Needs a mobile-air with glass-opacity on native:bottom-bar (NativePHP/mobile-air#735)', +); + it('ends the page above the reply bar, and further as the draft grows', function () { fakeThread(replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'The last reply'])]); From 2f4d5f4ff9d0d1189e7effdc95197e50d9f6c752 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 01:22:25 +0000 Subject: [PATCH 14/30] Read an author's replies to themselves as one thread, as the web does When someone replies to their own commit, the web treats their earliest reply as the next part of a thread rather than as a reply. The commit page now does the same: the parts follow the commit on its rail, each marked with its place (2/5), ten at a time with "Show more of this thread", and the last part's replies show under it. The next part is left out of each commit's replies, and the earlier parts above a commit get their places too. devnull's API doesn't send the web's continuation_id yet, so the app works the parts out from each commit's replies (SelfThread), fetching them one after another. When the API starts sending it, the app takes its word. On the Log, profiles, search, starred and organizations, a thread opened in place leaves out the author's next part and shows "Show thread", which opens the commit's page. Without continuation_id from the API, that link can only show once the replies have been opened. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Data/Commit.php | 5 + app/Devnull/SelfThread.php | 176 +++++++++++++++++ app/Icons/Lucide.php | 2 + app/NativeComponents/CommitDetail.php | 162 +++++++++++++++- .../Concerns/ExpandsThreads.php | 37 ++++ resources/icons/list-tree.svg | 1 + .../views/native/commit-detail.blade.php | 38 +++- .../partials/commit-row-content.blade.php | 16 +- .../views/native/partials/feed.blade.php | 3 +- .../native/partials/show-thread.blade.php | 8 + .../partials/thread-continues.blade.php | 24 +++ .../native/partials/thread-position.blade.php | 4 + .../native/partials/thread-reply.blade.php | 5 + tests/Feature/Screens/CommitDetailTest.php | 2 +- tests/Feature/Screens/CommitMenuTest.php | 2 +- tests/Feature/Screens/SelfThreadTest.php | 179 ++++++++++++++++++ tests/Pest.php | 20 +- tests/Unit/Devnull/SelfThreadTest.php | 105 ++++++++++ 18 files changed, 775 insertions(+), 14 deletions(-) create mode 100644 app/Devnull/SelfThread.php create mode 100644 resources/icons/list-tree.svg create mode 100644 resources/views/native/partials/show-thread.blade.php create mode 100644 resources/views/native/partials/thread-continues.blade.php create mode 100644 resources/views/native/partials/thread-position.blade.php create mode 100644 tests/Feature/Screens/SelfThreadTest.php create mode 100644 tests/Unit/Devnull/SelfThreadTest.php diff --git a/app/Devnull/Data/Commit.php b/app/Devnull/Data/Commit.php index 1175a11e..28b52bbf 100644 --- a/app/Devnull/Data/Commit.php +++ b/app/Devnull/Data/Commit.php @@ -21,6 +21,9 @@ * * A Nata Nu//ers high score carries its signed run in a fenced block, which * shows as a card ($scoreCard) instead of as code. + * + * $continuationId is the reply that carries on a thread its author writes as + * replies to themselves, when devnull says which (see SelfThread). */ final readonly class Commit { @@ -76,6 +79,7 @@ public function __construct( public ?ReplyPreview $replyPreview = null, public int $pasteisCount = 0, public ?ScoreCard $scoreCard = null, + public ?string $continuationId = null, ) {} /** @@ -143,6 +147,7 @@ public static function fromArray(array $data): self replyPreview: is_array($data['reply_preview'] ?? null) ? ReplyPreview::fromArray($data['reply_preview']) : null, pasteisCount: max(0, (int) ($data['pasteis_count'] ?? 0)), scoreCard: $scoreCard, + continuationId: is_string($data['continuation_id'] ?? null) && $data['continuation_id'] !== '' ? $data['continuation_id'] : null, ); } diff --git a/app/Devnull/SelfThread.php b/app/Devnull/SelfThread.php new file mode 100644 index 00000000..56278e10 --- /dev/null +++ b/app/Devnull/SelfThread.php @@ -0,0 +1,176 @@ + $parts The commits carrying the thread on below the commit, in order, at most the limit. + * @param bool $hasMore Whether another part follows the last of $parts. + * @param bool $hasEnded Whether it's known that no part follows the last of $parts. + * @param string|null $waiting The commit whose replies the walk needs to go on. + */ + public function __construct( + public array $parts = [], + public bool $hasMore = false, + public bool $hasEnded = false, + public ?string $waiting = null, + ) {} + + /** + * The reply among $replies that carries $commit's thread on, if it's one of them. + * + * @param iterable $replies + */ + public static function next(Commit $commit, iterable $replies): ?Commit + { + if ($commit->isDeleted() || $commit->isStaged() || $commit->author->id === '') { + return null; + } + + $earliest = null; + + foreach ($replies as $reply) { + if ($commit->continuationId !== null) { + if ($reply->id === $commit->continuationId) { + return $reply; + } + + continue; + } + + if ($reply->parentId !== $commit->id || $reply->isDeleted() || $reply->isStaged() || $reply->author->id !== $commit->author->id) { + continue; + } + + if ($earliest === null || self::isEarlier($reply, $earliest)) { + $earliest = $reply; + } + } + + return $earliest; + } + + /** + * $replies without the one that carries $commit's thread on, which shows as the next part of it instead. + * + * @param list $replies + * @return list + */ + public static function others(Commit $commit, array $replies): array + { + $next = self::next($commit, $replies); + + return $next === null ? $replies : array_values(array_filter($replies, fn (Commit $reply): bool => $reply->id !== $next->id)); + } + + /** + * Walks down from $commit through the parts that carry its thread on, as far as $limit and the replies that + * have come allow. + * + * @param Closure(Commit): (list|null) $repliesOf A commit's first page of replies, or null until it comes. + */ + public static function below(Commit $commit, Closure $repliesOf, int $limit = self::PerPage): self + { + $parts = []; + $above = $commit; + + while (true) { + $replies = $repliesOf($above); + + if ($replies === null) { + return new self($parts, waiting: $above->id); + } + + $next = self::next($above, $replies); + + if ($next === null || in_array($next, $parts, true) || $next->id === $commit->id) { + return new self($parts, hasEnded: true); + } + + if (count($parts) >= $limit) { + return new self($parts, hasMore: true); + } + + $parts[] = $next; + $above = $next; + } + } + + /** + * How many of the commits just above $commit, of $ancestors (oldest first), are earlier parts of its thread, + * and whose replies are needed to look further up. Only the author's own commits can be; each one is a part + * when its earliest reply from them is the one below it. + * + * @param list $ancestors + * @param Closure(Commit): (list|null) $repliesOf + * @return array{0: int, 1: string|null} + */ + public static function above(array $ancestors, Commit $commit, Closure $repliesOf): array + { + $count = 0; + $below = $commit; + + foreach (array_reverse($ancestors) as $ancestor) { + if ($below->isDeleted() || $ancestor->isDeleted() || $ancestor->author->id !== $below->author->id || $below->parentId !== $ancestor->id) { + break; + } + + $replies = $repliesOf($ancestor); + + if ($replies === null) { + return [$count, $ancestor->id]; + } + + if (self::next($ancestor, $replies)?->id !== $below->id) { + break; + } + + $count++; + $below = $ancestor; + } + + return [$count, null]; + } + + /** + * The place in its thread of the commit at $position, as the web's ThreadPositionBadge writes it: "3/7", with + * a "+" when more of the thread follows than has been read. Null for a commit that isn't part of one. + */ + public static function position(int $position, int $size, bool $isOpenEnded): ?string + { + return $size > 1 && $position >= 1 ? $position.'/'.$size.($isOpenEnded ? '+' : '') : null; + } + + private static function isEarlier(Commit $reply, Commit $than): bool + { + if ($reply->createdAt === null || $than->createdAt === null || $reply->createdAt->equalTo($than->createdAt)) { + return strcmp($reply->id, $than->id) < 0; + } + + return $reply->createdAt->lessThan($than->createdAt); + } +} diff --git a/app/Icons/Lucide.php b/app/Icons/Lucide.php index 3df5fa55..24bcab8f 100644 --- a/app/Icons/Lucide.php +++ b/app/Icons/Lucide.php @@ -36,6 +36,7 @@ enum Lucide case ArrowUp; case Pin; case ListOrdered; + case ListTree; /** lucide-react 1.57 draws Building2 as building-complex, so that is the drawing in building-2.svg. */ case Building2; case MapPin; @@ -177,6 +178,7 @@ public function custom(bool $filled = false): string self::ArrowUp => 'arrow-up', self::ChevronsUp => 'chevrons-up', self::ListOrdered => 'list-ordered', + self::ListTree => 'list-tree', self::Building2 => 'building-2', self::MapPin => 'map-pin', self::CalendarDays => 'calendar-days', diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index dbc088eb..ea255221 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -17,6 +17,7 @@ use App\Devnull\PostAs; use App\Devnull\ResponseCache; use App\Devnull\RowCache; +use App\Devnull\SelfThread; use App\Devnull\Stash; use App\Devnull\Timeline; use App\Devnull\Toasts; @@ -75,6 +76,14 @@ * * A member of a GitHub organization can reply as it, from the avatar at the * start of the bar's row, as the web's reply composer does (see PostAs). + * + * A thread its author wrote as replies to themselves reads in order, as on + * the web (see SelfThread): the parts after the commit follow it on its rail, + * each with its place in the thread, ten at a time with "Show more of this + * thread", and the next part isn't among the commit's replies. The replies of + * the last part show under it. The earlier parts are the ancestors above it, + * and wear their places too. Each step needs the replies of the commit above + * it, which are asked for one after another ($partReplies). */ class CommitDetail extends NativeComponent { @@ -110,6 +119,26 @@ class CommitDetail extends NativeComponent /** @var list */ public array $replies = []; + /** + * The first page of replies of the commits around this one in its author's thread, by id, which say which + * reply carries it on (see SelfThread). + * + * @var array> + */ + public array $partReplies = []; + + /** + * The commits in $partReplies with more replies than their first page. + * + * @var list + */ + public array $partsWithMore = []; + + /** + * How many parts of the author's thread show after the commit. + */ + public int $threadLimit = SelfThread::PerPage; + public ?string $repliesCursor = null; /** @@ -291,6 +320,10 @@ protected function revalidate(): void app(ResponseCache::class)->forget($this->threadPath().'/related'); }); + foreach (array_keys($this->partReplies) as $id) { + $this->refreshPartReplies((string) $id); + } + foreach (array_keys($this->tombstoneReplies) as $id) { $id = (string) $id; @@ -338,6 +371,15 @@ public function toggleReplies(): void $this->repliesShown = ! $this->repliesShown; } + /** + * "Show more of this thread": the next ten parts of the author's thread, as on the web. + */ + public function showMoreThread(): void + { + $this->threadLimit += SelfThread::PerPage; + $this->followThread(); + } + /** * The web's preview toggle, in the reply bar: the reply shows as it will * look in the field's place, at once, and devnull is asked for its body, @@ -451,6 +493,7 @@ public function loadMoreReplies(): void $this->replies = [...array_values(array_filter($this->replies, fn (Commit $reply): bool => ! isset($loaded[$reply->id]))), ...$page->items]; $this->repliesCursor = $page->nextCursor; $this->keepStagedReplies(); + $this->followThread(); } } @@ -564,6 +607,7 @@ protected function showCommitWent(PendingWrite $write, Commit $commit): void $staged = PendingWrite::stagedId($write->client_id); $this->replies = array_map(fn (Commit $reply): Commit => $reply->id === $staged ? $commit : $reply, $this->replies); + $this->followThread(); } /** @@ -694,6 +738,7 @@ protected function updateShownCommits(Closure $update): void $this->ancestors = array_map($update, $this->ancestors); $this->series = array_map($update, $this->series); $this->replies = array_map($update, $this->replies); + $this->partReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->partReplies); $this->related = array_map($update, $this->related); $this->tombstoneReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->tombstoneReplies); } @@ -703,7 +748,7 @@ protected function updateShownCommits(Closure $update): void */ protected function shownCommits(): iterable { - return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...$this->related, ...array_merge([], ...array_values($this->tombstoneReplies))]; + return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...array_merge([], ...array_values($this->partReplies)), ...$this->related, ...array_merge([], ...array_values($this->tombstoneReplies))]; } /** @@ -766,6 +811,7 @@ private function showKept(): void $this->takeRelated($this->cached($this->threadPath().'/related') ?? []); $this->keepStagedReplies(); + $this->followThread(); } /** @@ -786,6 +832,7 @@ private function takeThread(array $json): void $this->commit = $thread->commit; $this->ancestors = $thread->ancestors; $this->series = $thread->series; + $this->followThread(); } /** @@ -798,6 +845,74 @@ private function takeReplies(array $json): void [$this->replies, $this->repliesCursor] = self::withFirstPage($this->replies, $this->repliesCursor, Page::fromArray($json, Commit::fromArray(...))); $this->repliesLoaded = true; $this->keepStagedReplies(); + $this->followThread(); + } + + /** + * Asks for the replies the author's thread needs next, above the commit and below it, each when the one + * before has come (see SelfThread). A page kept from before shows at once and refreshes behind. + */ + private function followThread(): void + { + if ($this->commit === null) { + return; + } + + $waiting = [ + $this->selfThread()->waiting, + SelfThread::above($this->ancestors, $this->commit, $this->repliesOf())[1], + ]; + + foreach (array_unique(array_filter($waiting, fn (?string $id): bool => $id !== null && $id !== $this->id)) as $id) { + $kept = $this->cached('commits/'.rawurlencode($id).'/replies'); + $this->refreshPartReplies($id); + + if ($kept !== null) { + $this->takePartReplies($id, $kept); + } + } + } + + private function refreshPartReplies(string $id): void + { + $this->refresh('commits/'.rawurlencode($id).'/replies', [], fn (array $json) => $this->takePartReplies($id, $json)); + } + + /** + * @param array $json + */ + private function takePartReplies(string $id, array $json): void + { + $page = Page::fromArray($json, Commit::fromArray(...)); + $this->partReplies[$id] = $page->items; + $this->partsWithMore = array_values(array_diff($this->partsWithMore, [$id])); + + if ($page->hasMore()) { + $this->partsWithMore[] = $id; + } + + $this->followThread(); + } + + /** + * The first page of a commit's replies as far as the page has them, or null until they come. The commit's + * own are the ones showing, less any still on their way. + * + * @return Closure(Commit): (list|null) + */ + private function repliesOf(): Closure + { + return fn (Commit $commit): ?array => $commit->id === $this->id + ? ($this->repliesLoaded ? array_values(array_filter($this->replies, fn (Commit $reply): bool => ! $reply->isStaged())) : null) + : ($this->partReplies[$commit->id] ?? null); + } + + /** + * The parts of the author's thread after the commit, as far as they've been read. + */ + private function selfThread(): SelfThread + { + return $this->commit === null ? new SelfThread : SelfThread::below($this->commit, $this->repliesOf(), $this->threadLimit); } /** @@ -859,6 +974,11 @@ public function render(): View $viewer = $this->me(); $this->replyRows ??= new RowCache; $this->replyRows->startFrame(); + $thread = $this->selfThread(); + $parts = $thread->parts; + $partsAbove = $this->commit === null ? 0 : SelfThread::above($this->ancestors, $this->commit, $this->repliesOf())[0]; + $lastPart = $thread->hasEnded && $parts !== [] ? end($parts) : null; + $replies = $this->commit === null ? $this->replies : SelfThread::others($this->commit, $this->replies); return view('native.commit-detail', [ 'replyRows' => $this->replyRows, @@ -868,13 +988,49 @@ public function render(): View 'stashed' => app(Stash::class)->names($viewer?->id), 'pasteis' => app(Account::class)->pasteis(), 'rows' => $this->commit === null ? [] : Timeline::thread( - [...$above, $this->commit, ...$this->series], + [...$above, $this->commit, ...$this->series, ...$parts], laneAbove: $earlier === [] ? null : end($earlier)->lane(), ), 'relatedRows' => Timeline::thread($this->related), 'earlierCount' => $this->commit === null ? 0 : count($earlier), 'earlierLane' => $earlier === [] ? null : end($earlier)->lane(), - 'replyCount' => max($this->commit->repliesCount ?? 0, count($this->replies)), + 'replyCount' => max($this->commit->repliesCount ?? 0, count($replies)), + 'replies' => $replies, + 'threadParts' => array_map(fn (Commit $part): string => $part->id, $parts), + 'threadMore' => $thread->hasMore, + 'threadPositions' => $this->threadPositions($thread, $partsAbove), + 'lastPart' => $lastPart, + 'lastPartReplies' => $lastPart === null ? [] : array_slice($this->partReplies[$lastPart->id] ?? [], 0, Client::RepliesPerPage), + 'lastPartMore' => $lastPart !== null && (count($this->partReplies[$lastPart->id] ?? []) > Client::RepliesPerPage || in_array($lastPart->id, $this->partsWithMore, true)), ]); } + + /** + * Each commit's place in its author's thread, by id, as the web marks them: the earlier parts above the + * commit, the commit, and the parts after it. None when the commit isn't part of a thread. + * + * A part known to follow the last one read counts, and a thread not read to its end gets the web's "+". + * + * @return array + */ + private function threadPositions(SelfThread $below, int $partsAbove): array + { + if ($this->commit === null) { + return []; + } + + $thread = [...array_slice($this->ancestors, count($this->ancestors) - $partsAbove, $partsAbove), $this->commit, ...$below->parts]; + $size = count($thread) + ($below->hasMore ? 1 : 0); + $positions = []; + + foreach ($thread as $index => $commit) { + $label = SelfThread::position($index + 1, $size, ! $below->hasEnded); + + if ($label !== null) { + $positions[$commit->id] = $label; + } + } + + return $positions; + } } diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 2a5763ce..aed53c3c 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -4,6 +4,7 @@ use App\Devnull\Data\Commit; use App\Devnull\Data\Page; +use App\Devnull\SelfThread; /** * "› N replies" under a commit in a feed opens its replies in place, the way @@ -20,6 +21,11 @@ * and a thread longer than a page opens the commit's page instead. * * A thread opened before opens at once from the cache, and refreshes behind. + * + * The reply that carries on a thread its author wrote as replies to + * themselves isn't one of the replies, as on the web: it's the next part of + * that thread, which the commit's "Show thread" opens (see SelfThread). + * devnull's count of the replies already leaves it out. */ trait ExpandsThreads { @@ -44,6 +50,13 @@ trait ExpandsThreads */ public array $threadsWithMore = []; + /** + * Commits whose replies, opened, showed that their author carried them on as a thread, so they show "Show thread". + * + * @var list + */ + public array $threadsContinued = []; + public function toggleReplies(string $id): void { if (array_key_exists($id, $this->threads)) { @@ -122,6 +135,8 @@ private function takeThread(string $id, array $json): void */ private function openThread(string $id, Page $page): void { + $page = $this->withoutContinuation($id, $page); + // A thread whose last reply went closes, so its commit gets its hairline back. if ($page->items === []) { $this->closeThread($id); @@ -152,6 +167,28 @@ private function openThread(string $id, Page $page): void $this->threads[$id] = array_reverse($page->items); } + /** + * The page without the reply that carries the commit's thread on, which marks the commit as carried on instead. + * + * @param Page $page + * @return Page + */ + private function withoutContinuation(string $id, Page $page): Page + { + $commit = $this->shownCommit($id); + $next = $commit === null ? null : SelfThread::next($commit, $page->items); + + if ($next === null) { + return $page; + } + + if (! in_array($id, $this->threadsContinued, true)) { + $this->threadsContinued[] = $id; + } + + return new Page(SelfThread::others($commit, $page->items), $page->nextCursor); + } + private function closeThread(string $id): void { unset($this->threads[$id]); diff --git a/resources/icons/list-tree.svg b/resources/icons/list-tree.svg new file mode 100644 index 00000000..27294fa1 --- /dev/null +++ b/resources/icons/list-tree.svg @@ -0,0 +1 @@ + diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index ce9a027f..c3db9ecf 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -25,6 +25,10 @@ has its replies right under it, beside the rail running on, and the later parts follow. Everything around the commit is muted, and still opens its own page. A deleted reply's own replies open in place, one level in, five at a time too, since a deleted commit has no page. + + A thread its author wrote as replies to themselves carries on below the commit, on the same rail, as + the web reads it (see SelfThread): each part wears its place ("2/5"), ten show at a time with "Show + more of this thread" under them, and the replies of the last part hang under it as the commit's do. --}} @if ($earlierCount > 0) @include('native.partials.earlier-commits', ['count' => $earlierCount, 'lane' => $earlierLane]) @@ -35,23 +39,28 @@ above them leaves out its hairline, which runs from the text's edge, so the two don't stack up into a line and a half. Replies end with no hairline on a commit page, and "No replies yet" keeps the commit's. --}} - @php($noReplies = $commit && $replyCount === 0 && $repliesLoaded && $series === []) + @php($noReplies = $commit && $replyCount === 0 && $repliesLoaded && $series === [] && $threadParts === []) @php($relatedBelow = $commit && $related !== [] && ! $noReplies) @foreach ($rows as $row) @php($isFocused = $row->commit->id === $commit?->id) + @php($isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id) @php($hasThread = $isFocused && $repliesShown && $replies !== []) + @php($partThread = $isLastPart && $lastPartReplies !== []) @include('native.partials.commit-row', [ 'commit' => $row->commit, 'previousLane' => $row->previousLane, 'continuesRun' => $row->continuesRun, 'continuesNext' => $isFocused ? ! $loop->last : null, - 'threadBelow' => $hasThread, + 'threadBelow' => $hasThread || $partThread, + 'repliesBelow' => $partThread, 'focused' => $isFocused, 'muted' => ! $isFocused, 'seriesExpanded' => true, - 'withTail' => ! $loop->last, - 'hairline' => ! ($loop->last && $relatedBelow), + 'withTail' => ! $loop->last || $threadMore, + 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), + 'threadPosition' => $threadPositions[$row->commit->id] ?? null, + 'showsThread' => false, ]) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) @@ -102,8 +111,29 @@ @endforeach @endforeach @endif + @if ($partThread) + @foreach ($lastPartReplies as $index => $threadReply) + @php($replyRow = [ + 'reply' => $threadReply, + 'lane' => $lastPart->lane(), + 'previousLane' => $index === 0 ? null : $lastPartReplies[$index - 1]->lane(), + 'hasNext' => ! $loop->last || $lastPartMore, + 'railLane' => null, + 'muted' => true, + 'thread' => $lastPart, + 'more' => $loop->last && $lastPartMore ? "openReplies('{$lastPart->id}')" : null, + 'last' => $loop->last, + ]) + @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) + @php($replyRows->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope)) + @endforeach + @endif @endforeach + @if ($threadMore && $threadParts !== []) + @include('native.partials.thread-continues', ['lane' => $rows[array_key_last($rows)]->commit->lane()]) + @endif + @if ($noReplies) No replies yet. diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 553ac21e..a3af40ec 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -11,6 +11,10 @@ which tapped says when in your timezone, its hash, and its replies behind a toggle in its action row. The commits around it ($muted) step back: smaller and in muted ink, with a smaller avatar and action row. They still open their own pages. + A commit in a thread its author wrote as replies to themselves wears its place in it ($threadPosition, "2/5"), and + one its author carried on that way links to that thread ($showsThread), as the web's "Show thread" does (see + SelfThread). $repliesBelow says its replies show under the row, so its action row leaves out "› N replies". + A commit you just made that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions, until the real one takes its place (see SyncsOutbox). @@ -25,6 +29,9 @@ @php($withTail ??= ! $focused) @php($continuesNext ??= null) @php($threadBelow ??= false) +@php($threadPosition ??= null) +@php($showsThread ??= $commit->continuationId !== null) +@php($repliesBelow ??= false) @php($inFeed = $continuesNext !== null) @php($endsWithDot = $inFeed && ! $continuesRun && ! $continuesNext) @php($laterParts = $seriesExpanded ? 0 : $commit->laterSeriesParts()) @@ -48,6 +55,9 @@ @if ($commit->isSeriesPart()) @include('native.partials.series-position') @endif + @if ($threadPosition !== null) + @include('native.partials.thread-position') + @endif @unless ($commit->isApproved()) @include('native.partials.status-chip', ['status' => $commit->status]) @endunless @@ -75,6 +85,10 @@ @endif + @if ($showsThread && ! $focused) + @include('native.partials.show-thread') + @endif + @if ($focused) {{ $commit->shortHash }} @endif @@ -88,7 +102,7 @@ 'repliesCount' => $replyCount ?? $commit->repliesCount, ]) @else - @include('native.partials.commit-actions', ['compact' => $muted]) + @include('native.partials.commit-actions', ['compact' => $muted, 'withReplies' => ! $repliesBelow]) @endif diff --git a/resources/views/native/partials/feed.blade.php b/resources/views/native/partials/feed.blade.php index c85258e0..17298118 100644 --- a/resources/views/native/partials/feed.blade.php +++ b/resources/views/native/partials/feed.blade.php @@ -3,7 +3,7 @@ partials/who-to-follow) and commits on the rail. Under a commit hangs its thread, inside its row's hairline, as on the web: the newest reply devnull previews, with "Show more" when there are others, or the replies opened in place, with "Show more" to the commit's page when there are more than they show. The commit's rail runs on past them when - its author's run goes on below. + its author's run goes on below. A commit its author carried on in replies to themselves shows "Show thread". Given a $rowCache (see App\Devnull\RowCache), commits and replies that haven't changed since the last frame are drawn from it rather than built again. Given a $rowWindow (see App\Devnull\RowWindow), rows far from the screen @@ -56,6 +56,7 @@ 'continuesRun' => $row->continuesRun, 'continuesNext' => $row->continuesNext, 'threadBelow' => $threadReplies !== [], + 'showsThread' => $feedCommit->continuationId !== null || in_array($feedCommit->id, $threadsContinued ?? [], true), ]; @endphp @if (! $feedDraws) diff --git a/resources/views/native/partials/show-thread.blade.php b/resources/views/native/partials/show-thread.blade.php new file mode 100644 index 00000000..6a3e4aa6 --- /dev/null +++ b/resources/views/native/partials/show-thread.blade.php @@ -0,0 +1,8 @@ +{{-- + "Show thread" under a commit its author carried on in replies to themselves, as the web's ShowThreadLink: it opens + the commit's page, where the thread reads in order (see SelfThread). +--}} + + + Show thread + diff --git a/resources/views/native/partials/thread-continues.blade.php b/resources/views/native/partials/thread-continues.blade.php new file mode 100644 index 00000000..efe83068 --- /dev/null +++ b/resources/views/native/partials/thread-continues.blade.php @@ -0,0 +1,24 @@ +{{-- + "Show more of this thread" under the last part of an author's thread a commit page shows, as the web's: a tap shows + the next ten parts (see SelfThread). It mirrors "↑ N earlier commits" above the commit: the last part's rail comes + down solid to a hollow node in its lane, and a dashed Rail Gray line runs on below it to what's still to come. +--}} +@php($colour = 'bg-theme-'.\App\Devnull\Lane::token($lane)) + + + + + + + Show more of this thread + + + + + + + @include('native.partials.rail-node', ['lane' => $lane, 'filled' => false]) + + @include('native.partials.dashed-line', ['position' => 'top-[31] bottom-0', 'left' => 31.5, 'lane' => \App\Devnull\Lane::Rail]) + + diff --git a/resources/views/native/partials/thread-position.blade.php b/resources/views/native/partials/thread-position.blade.php new file mode 100644 index 00000000..0a9bb7dd --- /dev/null +++ b/resources/views/native/partials/thread-position.blade.php @@ -0,0 +1,4 @@ +{{-- A commit's place in its author's thread, like the web's ThreadPositionBadge: "2/5" in mono on a muted wash. --}} + + {{ $threadPosition }} + diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index 6a1d0a7c..29f95d96 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -16,6 +16,8 @@ A commit page draws its replies $muted, smaller and in muted ink, so the commit they answer stays the main thing. + A reply its author carried on in replies to themselves links to that thread, as on the web (see show-thread). + A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. --}} @php($previousLane ??= null) @@ -83,6 +85,9 @@ @include('native.partials.commit-body', ['size' => $muted ? 'text-sm' : 'text-[15px]']) @include('native.partials.commit-media', ['withEmbeds' => false]) + @if ($reply->continuationId !== null) + @include('native.partials.show-thread') + @endif @unless ($reply->isStaged()) @include('native.partials.commit-actions', ['expandable' => false, 'withQuote' => false, 'compact' => $muted]) @endunless diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 7e0360c4..ad9ef4b2 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -843,7 +843,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): it('stars the focused commit and its replies in place', function () { $grace = userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace']); - fakeThread(['author' => $grace], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'author' => $grace])], extra: [ + fakeThread(['author' => $grace], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2'])], extra: [ 'POST /api/v1/commits/c2/star' => [['data' => commitJson(['id' => 'c2', 'stars_count' => 1, 'starred' => true])]], 'POST /api/v1/commits/r1/star' => [['data' => commitJson(['id' => 'r1', 'starred' => true])]], ]); diff --git a/tests/Feature/Screens/CommitMenuTest.php b/tests/Feature/Screens/CommitMenuTest.php index c07a7170..53ba2936 100644 --- a/tests/Feature/Screens/CommitMenuTest.php +++ b/tests/Feature/Screens/CommitMenuTest.php @@ -130,7 +130,7 @@ $deleted = true; }), 'GET /api/v1/commits/c2' => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'Ada asks', 'replies_count' => $deleted ? 0 : 1, 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))), - 'GET /api/v1/commits/c2/replies' => Http::response(pageJson($deleted ? [] : [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'Soon gone'])])), + 'GET /api/v1/commits/c2/replies' => Http::response(pageJson($deleted ? [] : [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'Soon gone', 'author' => userJson()])])), default => Http::response(['message' => 'No fake.'], 404), }; }); diff --git a/tests/Feature/Screens/SelfThreadTest.php b/tests/Feature/Screens/SelfThreadTest.php new file mode 100644 index 00000000..47a445e5 --- /dev/null +++ b/tests/Feature/Screens/SelfThreadTest.php @@ -0,0 +1,179 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * One of Ada's commits, $minutes ago, replying to $parent. + * + * @param array $overrides + * @return array + */ +function adaJson(string $id, ?string $parent = null, int $minutes = 30, array $overrides = []): array +{ + return commitJson([ + 'id' => $id, + 'parent_id' => $parent, + 'body' => "Ada's {$id}", + 'author' => userJson(['handle' => 'ada', 'name' => 'Ada', 'lane' => 2]), + 'created_at' => now()->subMinutes($minutes)->toIso8601ZuluString(), + ...$overrides, + ]); +} + +/** + * Serves a commit page and the replies of every commit in $replies, by id, and 404s anything else. + * + * @param array $commit + * @param list> $ancestors + * @param array>> $replies + */ +function serveSelfThread(array $commit, array $ancestors, array $replies): void +{ + Http::fake(function (Request $request) use ($commit, $ancestors, $replies) { + $path = (string) parse_url($request->url(), PHP_URL_PATH); + + if ($path === '/api/v1/commits/'.$commit['id']) { + return Http::response(commitPageJson($commit, $ancestors)); + } + + if (preg_match('#^/api/v1/commits/([^/]+)/replies$#', $path, $match) === 1 && array_key_exists($match[1], $replies)) { + return Http::response(pageJson($replies[$match[1]])); + } + + if (str_ends_with($path, '/related')) { + return Http::response(['data' => []]); + } + + return Http::response(['message' => 'No fake.'], 404); + }); +} + +/** + * The refs of the rows down a commit page, top to bottom. + * + * @return list + */ +function selfThreadRows(TestableComponent $screen): array +{ + return array_values(array_filter(childRefs($screen, 'thread-page'), fn (?string $ref): bool => $ref !== 'reply-bar-clearance')); +} + +/** + * The text of a commit's place in its thread. + */ +function threadPositionOf(TestableComponent $screen, string $id): string +{ + $text = findNode(nodeByRef($screen, 'thread-position-'.$id), fn (array $node): bool => ($node['type'] ?? null) === 'text'); + + return $text['props']['text'] ?? ''; +} + +it("reads an author's replies to themselves in order under the commit, as the web's thread", function () { + serveSelfThread(adaJson('c1', overrides: ['replies_count' => 2]), [], [ + 'c1' => [ + replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'Grace answers', 'created_at' => now()->subMinutes(28)->toIso8601ZuluString()]), + adaJson('p2', 'c1', 25), + adaJson('later', 'c1', 5, ['body' => 'Ada again, later']), + ], + 'p2' => [replyJson(['id' => 'x1', 'parent_id' => 'p2', 'body' => 'Under part two']), adaJson('p3', 'p2', 20)], + 'p3' => [replyJson(['id' => 'y1', 'parent_id' => 'p3', 'body' => 'Under the last part'])], + ]); + + $screen = Native::visit('/log/commits/c1') + ->assertSee("Ada's p2") + ->assertSee("Ada's p3") + ->assertSee('Under the last part') + ->assertDontSee('Under part two') + ->assertDontSee('Grace answers') + ->assertDontSee('No replies yet.'); + + expect(selfThreadRows($screen))->toBe(['focused-commit', 'commit-p2', 'commit-p3', 'thread-reply-y1']) + ->and(threadPositionOf($screen, 'c1'))->toBe('1/3') + ->and(threadPositionOf($screen, 'p2'))->toBe('2/3') + ->and(threadPositionOf($screen, 'p3'))->toBe('3/3') + ->and(railNode($screen, 'commit-p2'))->toBe('dot') + // The last part's replies show under it, so its action row doesn't offer them again. + ->and(findNode(nodeByRef($screen, 'commit-p3'), fn (array $node): bool => ($node['ref'] ?? null) === 'replies-p3'))->toBeNull(); + + // The commit's own replies leave out the part that carries it on, and keep its later replies to itself. + $screen->tap('replies-c1')->assertSee('Grace answers')->assertSee('Ada again, later'); + + expect(selfThreadRows($screen))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-later', 'commit-p2', 'commit-p3', 'thread-reply-y1']); +}); + +it('marks the earlier parts above a commit in the middle of its thread', function () { + serveSelfThread(adaJson('p2', 'c1', 20), [adaJson('c1', minutes: 30)], [ + 'c1' => [adaJson('p2', 'c1', 20)], + 'p2' => [], + ]); + + $screen = Native::visit('/log/commits/p2'); + + expect(threadPositionOf($screen, 'c1'))->toBe('1/2') + ->and(threadPositionOf($screen, 'p2'))->toBe('2/2'); +}); + +it("doesn't mark a commit its author replied to some other way first", function () { + serveSelfThread(adaJson('p2', 'c1', 10), [adaJson('c1', minutes: 30)], [ + 'c1' => [adaJson('first', 'c1', 20), adaJson('p2', 'c1', 10)], + 'p2' => [], + ]); + + $screen = Native::visit('/log/commits/p2')->assertSee("Ada's c1"); + + expect(findNode($screen->tree(), fn (array $node): bool => str_starts_with((string) ($node['ref'] ?? ''), 'thread-position-')))->toBeNull(); +}); + +it('shows ten parts at a time, and the rest from Show more of this thread', function () { + $replies = ['c1' => [adaJson('p2', 'c1', 29)]]; + + foreach (range(2, 11) as $part) { + $replies['p'.$part] = [adaJson('p'.($part + 1), 'p'.$part, 29 - $part)]; + } + + $replies['p12'] = []; + serveSelfThread(adaJson('c1', minutes: 30), [], $replies); + + $screen = Native::visit('/log/commits/c1') + ->assertSee("Ada's p11") + ->assertDontSee("Ada's p12"); + + expect(threadPositionOf($screen, 'c1'))->toBe('1/12+'); + + $screen->tap('more-thread')->assertSee("Ada's p12"); + + expect(threadPositionOf($screen, 'c1'))->toBe('1/12') + ->and(threadPositionOf($screen, 'p12'))->toBe('12/12') + ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'more-thread'))->toBeNull(); +}); + +it("leaves the author's next part out of a thread opened on the Log, and links to the thread instead", function () { + Http::fake(fn (Request $request) => match (parse_url($request->url(), PHP_URL_PATH)) { + '/api/v1/log/following' => Http::response(pageJson([adaJson('c1', overrides: ['replies_count' => 1])])), + '/api/v1/commits/c1/replies' => Http::response(pageJson([adaJson('p2', 'c1', 25), replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'Grace answers'])])), + default => Http::response(['message' => 'No fake.'], 404), + }); + + $screen = Native::visit('/log')->assertDontSee('Show thread')->tap('replies-c1') + ->assertSee('Grace answers') + ->assertDontSee("Ada's p2") + ->assertSee('Show thread'); + + expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c1']))->toBe(['r1']); + + $screen->tap('show-thread-c1')->assertNavigatedTo('/log/commits/c1'); +}); + +it('links to the thread when devnull says which reply carries it on', function () { + Http::fake(['devnull.test/api/v1/log/following*' => Http::response(pageJson([adaJson('c1', overrides: ['continuation_id' => 'p2'])]))]); + + Native::visit('/log')->assertSee('Show thread')->tap('show-thread-c1')->assertNavigatedTo('/log/commits/c1'); +}); diff --git a/tests/Pest.php b/tests/Pest.php index d1bf556c..42366d00 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -409,7 +409,8 @@ function userJson(array $overrides = []): array $username = $overrides['handle'] ?? 'local_dev'; return [ - 'id' => '0199e5c4-0000-7000-8000-000000000001', + // Someone else, named by a handle of their own, is someone else to the app too. + 'id' => $username === 'local_dev' ? '0199e5c4-0000-7000-8000-000000000001' : 'user-'.$username, 'handle' => $username, 'name' => 'Local Dev', 'avatar_url' => 'https://avatars.githubusercontent.com/u/1?v=4', @@ -426,6 +427,17 @@ function userJson(array $overrides = []): array ]; } +/** + * Someone replying to a commit, who isn't its author. + * + * @param array $overrides + * @return array + */ +function replierJson(array $overrides = []): array +{ + return userJson(['id' => '0199e5c4-0000-7000-8000-0000000000aa', 'handle' => 'replier', 'name' => 'Re Plier', 'lane' => 5, ...$overrides]); +} + /** * A user with their counts, as `/me`, a profile and a key sync send them. * @@ -525,14 +537,16 @@ function commitPageJson(array $commit, array $ancestors = [], array $series = [] /** * A reply as `GET /commits/{id}/replies` sends it: like any commit, but without - * stars_count or starred, which that list doesn't load. + * stars_count or starred, which that list doesn't load. It comes from someone + * other than the commit's author unless a test says who, since a reply of + * theirs carries their own thread on (see SelfThread). * * @param array $overrides * @return array */ function replyJson(array $overrides = []): array { - return array_diff_key(commitJson($overrides), array_flip(['stars_count', 'starred'])); + return array_diff_key(commitJson(['author' => replierJson(), ...$overrides]), array_flip(['stars_count', 'starred'])); } /** diff --git a/tests/Unit/Devnull/SelfThreadTest.php b/tests/Unit/Devnull/SelfThreadTest.php new file mode 100644 index 00000000..5f9cc7e6 --- /dev/null +++ b/tests/Unit/Devnull/SelfThreadTest.php @@ -0,0 +1,105 @@ + $overrides + */ +function threadCommit(string $id, string $handle = 'ada', ?string $parent = null, int $minutes = 10, array $overrides = []): Commit +{ + return Commit::fromArray(commitJson([ + 'id' => $id, + 'parent_id' => $parent, + 'author' => userJson(['handle' => $handle]), + 'created_at' => now()->subMinutes($minutes)->toIso8601ZuluString(), + ...$overrides, + ])); +} + +/** + * @param array> $replies + * @return Closure(Commit): (list|null) + */ +function repliesFrom(array $replies): Closure +{ + return fn (Commit $commit): ?array => $replies[$commit->id] ?? null; +} + +it("carries a commit on with its author's earliest reply to it", function () { + $commit = threadCommit('c1', minutes: 30); + $replies = [ + threadCommit('r1', 'grace', 'c1', 25), + threadCommit('p3', 'ada', 'c1', 10), + threadCommit('p2', 'ada', 'c1', 20), + ]; + + expect(SelfThread::next($commit, $replies)?->id)->toBe('p2') + ->and(array_map(fn (Commit $reply): string => $reply->id, SelfThread::others($commit, $replies)))->toBe(['r1', 'p3']); +}); + +it('never carries a commit on with a deleted reply, a quote, or a reply still on its way', function () { + $commit = threadCommit('c1', minutes: 30); + + expect(SelfThread::next($commit, [ + Commit::fromArray(['id' => 'gone', 'parent_id' => 'c1', 'deleted_at' => now()->toIso8601ZuluString()]), + threadCommit('quote', 'ada', null, 20, ['quoted_commit_id' => 'c1']), + threadCommit('staged', 'ada', 'c1', 1, ['status' => Commit::Staged]), + threadCommit('r1', 'grace', 'c1', 15), + ]))->toBeNull(); +}); + +it("takes devnull's word for which reply carries the thread on", function () { + $commit = threadCommit('c1', minutes: 30, overrides: ['continuation_id' => 'p3']); + + expect(SelfThread::next($commit, [threadCommit('p2', 'ada', 'c1', 20), threadCommit('p3', 'ada', 'c1', 10)])?->id)->toBe('p3'); +}); + +it('walks down the parts as far as their replies have come', function () { + $c1 = threadCommit('c1', minutes: 30); + $p2 = threadCommit('p2', 'ada', 'c1', 20); + $p3 = threadCommit('p3', 'ada', 'p2', 10); + + $waiting = SelfThread::below($c1, repliesFrom(['c1' => [$p2]])); + $ended = SelfThread::below($c1, repliesFrom(['c1' => [$p2], 'p2' => [$p3], 'p3' => [threadCommit('r1', 'grace', 'p3', 5)]])); + + expect(array_map(fn (Commit $part): string => $part->id, $waiting->parts))->toBe(['p2']) + ->and($waiting->waiting)->toBe('p2') + ->and($waiting->hasEnded)->toBeFalse() + ->and(array_map(fn (Commit $part): string => $part->id, $ended->parts))->toBe(['p2', 'p3']) + ->and($ended->hasEnded)->toBeTrue() + ->and($ended->waiting)->toBeNull(); +}); + +it('stops at the limit and says another part follows', function () { + $c1 = threadCommit('c1', minutes: 30); + $p2 = threadCommit('p2', 'ada', 'c1', 20); + $p3 = threadCommit('p3', 'ada', 'p2', 10); + + $thread = SelfThread::below($c1, repliesFrom(['c1' => [$p2], 'p2' => [$p3]]), limit: 1); + + expect(array_map(fn (Commit $part): string => $part->id, $thread->parts))->toBe(['p2']) + ->and($thread->hasMore)->toBeTrue() + ->and($thread->hasEnded)->toBeFalse(); +}); + +it('counts the earlier parts above a commit, only while each is the one its author carried on', function () { + $c1 = threadCommit('c1', minutes: 30); + $p2 = threadCommit('p2', 'ada', 'c1', 20); + $p3 = threadCommit('p3', 'ada', 'p2', 10); + $other = threadCommit('o1', 'ada', 'p2', 15); + + expect(SelfThread::above([$c1, $p2], $p3, repliesFrom(['c1' => [$p2], 'p2' => [$p3]])))->toBe([2, null]) + ->and(SelfThread::above([$c1, $p2], $p3, repliesFrom(['p2' => [$p3]])))->toBe([1, 'c1']) + // Ada's earliest reply to p2 is o1, so p3 isn't part of the thread. + ->and(SelfThread::above([$c1, $p2], $p3, repliesFrom(['p2' => [$other, $p3]])))->toBe([0, null]) + ->and(SelfThread::above([threadCommit('g1', 'grace')], threadCommit('p9', 'ada', 'g1'), repliesFrom([])))->toBe([0, null]); +}); + +it("writes a commit's place in its thread as the web does", function () { + expect(SelfThread::position(2, 5, false))->toBe('2/5') + ->and(SelfThread::position(1, 12, true))->toBe('1/12+') + ->and(SelfThread::position(1, 1, false))->toBeNull(); +}); From 4f0ed672b28477313e499f69886907a66cc9a47d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 01:31:16 +0000 Subject: [PATCH 15/30] Use glass/80 for both composer bars and even out the Messages bar The lighter glass is now mobile-air's glass/N suffix rather than a separate attribute, and it's on Display::composerBarGlass(), so the Messages composer gets it too. Messages had the same uneven gaps as the reply bar, so the spacing moves into composer-box for both: no top padding on the row around the box, and 8pt between the field and the row of tools. Both bars keep their height. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Display.php | 22 ++++++------------- .../views/native/commit-detail.blade.php | 3 +-- resources/views/native/conversation.blade.php | 2 +- .../native/partials/composer-box.blade.php | 7 +++--- tests/Feature/Screens/CommitDetailTest.php | 18 +++++++-------- tests/Feature/Screens/RemotesComposerTest.php | 17 ++++++++++++++ tests/Pest.php | 12 ++++++++++ 7 files changed, 49 insertions(+), 32 deletions(-) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index 8e736203..6648e4e7 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -45,10 +45,10 @@ final class Display public const int ComposerGlassTint = 40; /** - * How opaque the glass under the reply bar gets on iOS once it has faded in, from 0 to 1 (see - * replyBarGlassOpacity()). mobile-air's own default is 1, which over a dark page reads as a heavy slab. + * How opaque, in percent, the glass under a composer bar gets on iOS once it has faded in (glass/N, see + * composerBarGlass()). Full glass over a dark screen reads as a heavy slab. */ - public const float ReplyBarGlassOpacity = 0.8; + public const int ComposerGlassOpacity = 80; /** * About how many characters fit on a line of the box's field, which runs the width of the box. @@ -306,21 +306,13 @@ public static function fadesInBar(): bool * The classes for a composer's native:bottom-bar. On iOS that's Liquid Glass: what scrolls under the bar shows * through it, blurred. A patched mobile-air draws the glass behind the whole bar, under the home indicator too, * and fades it in over the bar's top ComposerFadeHeight points, so it has no hard top edge. EDGE's own glass on - * an element can't be faded, and stops short of the home indicator. Android has no glass, so the bar stays the - * surface there. + * an element can't be faded, and stops short of the home indicator. The glass stops at ComposerGlassOpacity + * percent (glass/N), so a little of the screen under the bar shows through. Android has no glass, so the bar + * stays the surface there. */ public static function composerBarGlass(): string { - return self::fadesInBar() ? 'glass' : ''; - } - - /** - * The reply bar's glass-opacity: how opaque mobile-air's glass behind the bar gets on iOS once it has faded in, - * so a little more of the page shows through. Null on Android, which draws no glass behind a bottom bar. - */ - public static function replyBarGlassOpacity(): ?float - { - return self::fadesInBar() ? self::ReplyBarGlassOpacity : null; + return self::fadesInBar() ? 'glass/'.self::ComposerGlassOpacity : ''; } /** diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index ce9a027f..5d26c304 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -151,7 +151,7 @@ --}} @php($replyPostingMe = app(\App\Devnull\Account::class)->user()) @php($replyPostsAs = $replyPostingMe !== null && \App\Devnull\PostAs::offered($replyAuthor)) - + @if (\App\Devnull\Display::fadesInBar()) @include('native.partials.composer-fade', ['ref' => 'reply-fade', 'inBar' => true]) @@ -179,7 +179,6 @@ @include('native.partials.composer-box', [ 'ref' => 'reply', 'field' => $replyPreviewing ? 'native.partials.reply-preview' : 'native.partials.reply-field', - 'fieldPadding' => 'pt-1 pb-2', 'lead' => $replyPostsAs ? [['native.partials.post-as', ['ref' => 'reply-post-as', 'me' => $replyPostingMe, 'picked' => $replyAuthor, 'method' => 'postAsInReply', 'size' => 28, 'inset' => 'pl-3']]] : [], 'tools' => [ ['ref' => 'reply-add-photos', 'icon' => \App\Icons\Lucide::ImagePlus, 'label' => $photosFull ? 'A reply can have up to 3 photos' : 'Add photos', 'menu' => $photosFull ? null : \App\Devnull\ComposerMenu::photoItems(), 'disabled' => $photosFull], diff --git a/resources/views/native/conversation.blade.php b/resources/views/native/conversation.blade.php index e5642545..5191385f 100644 --- a/resources/views/native/conversation.blade.php +++ b/resources/views/native/conversation.blade.php @@ -124,7 +124,7 @@ The box keeps its row, and the row its place among the bar's, so the field inside never moves. A voice note takes the field's place, and the +'s, while it's recorded and waits to be pushed. --}} - + @include('native.partials.composer-box', [ 'ref' => 'message', 'field' => $recorder === null ? 'native.partials.message-field' : 'native.partials.voice-recorder', diff --git a/resources/views/native/partials/composer-box.blade.php b/resources/views/native/partials/composer-box.blade.php index c036c99c..c706afc0 100644 --- a/resources/views/native/partials/composer-box.blade.php +++ b/resources/views/native/partials/composer-box.blade.php @@ -11,14 +11,13 @@ row, ahead of the tools, and for the end, left of the send button, such as the count of a long draft. $send is send-button's: its ref, label, method, and whether it can send yet. - The field's text lines up with the tools' icons under it. $fieldPadding is the field row's padding above and below - the field (pt-1 by default), for a bar that wants more room between the field and the row under it. + The field's text lines up with the tools' icons under it. The field sits a little nearer the fade above it than + the row under it: the row around the box has no top padding, and the field row leaves 8pt under the field. --}} @php($lead ??= []) -@php($fieldPadding ??= 'pt-1') @php($trail ??= []) - + @include($field) diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 7e0360c4..5e7d4c55 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -7,7 +7,6 @@ use App\Models\PendingWrite; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; -use Native\Mobile\Edge\Elements\BottomBar; use Native\Mobile\Events\Alert\ButtonPressed; use Native\Mobile\Testing\Native; @@ -869,6 +868,10 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): it('puts the reply bar on glass on iOS and the surface on Android, with no line, and fades the page out above it', function (string $platform) { fakeThread(); + if ($platform === 'ios') { + skipWithoutGlassOpacity(); + } + $screen = Native::visit('/log/commits/c2', platform: $platform); $bottomBar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); $bar = $bottomBar['children'][0]; @@ -913,20 +916,15 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->and(nodeByRef($screen, 'reply-field-row')['layout']['padding'])->toEqual([4, 12, 8, 16]); })->with(['ios', 'android']); -it('asks mobile-air for a lighter glass under the reply bar on iOS only', function (string $platform, ?float $opacity) { +it('fades the glass under the reply bar to 80% on iOS only', function (string $platform) { + skipWithoutGlassOpacity(); fakeThread(); $screen = Native::visit('/log/commits/c2', platform: $platform); $bottomBar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); - expect($bottomBar['props']['glass_opacity'] ?? null)->toBe($opacity); -})->with([ - 'ios' => ['ios', Display::ReplyBarGlassOpacity], - 'android' => ['android', null], -])->skip( - ! method_exists(BottomBar::class, 'glassOpacity'), - 'Needs a mobile-air with glass-opacity on native:bottom-bar (NativePHP/mobile-air#735)', -); + expect($bottomBar['props']['glass_opacity'] ?? null)->toBe($platform === 'ios' ? Display::ComposerGlassOpacity / 100 : null); +})->with(['ios', 'android']); it('ends the page above the reply bar, and further as the draft grows', function () { fakeThread(replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'The last reply'])]); diff --git a/tests/Feature/Screens/RemotesComposerTest.php b/tests/Feature/Screens/RemotesComposerTest.php index 637ed790..a6c567cb 100644 --- a/tests/Feature/Screens/RemotesComposerTest.php +++ b/tests/Feature/Screens/RemotesComposerTest.php @@ -285,7 +285,22 @@ function threadWithAda(string $platform = 'ios'): TestableComponent ->and(nodeByRef($screen, 'push')['props']['a11y_label'] ?? nodeByRef($screen, 'push')['a11y_label'] ?? null)->toBe('Push'); })->with(['ios', 'android']); +it('keeps the field closer to the fade than to the + and Push under it', function (string $platform) { + serveThreadWithAda([remoteMessageJson(['id' => 1])], ['read_through_id' => 1]); + + $screen = threadWithAda($platform); + + // [top, right, bottom, left]. As on a commit's reply bar: no top padding on the row, so the field starts 4pt + // under the fade, and 8pt between the field and the row under it. + expect(nodeByRef($screen, 'message-row')['layout']['padding'])->toEqual([0, 16, 8, 16]) + ->and(nodeByRef($screen, 'message-field-row')['layout']['padding'])->toEqual([4, 12, 8, 16]); +})->with(['ios', 'android']); + it('puts the bar on glass on iOS and the surface on Android, with no box or line, and fades the thread out above it', function (string $platform) { + if ($platform === 'ios') { + skipWithoutGlassOpacity(); + } + serveThreadWithAda([remoteMessageJson(['id' => 1])], ['read_through_id' => 1]); $screen = threadWithAda($platform); @@ -306,6 +321,7 @@ function threadWithAda(string $platform = 'ios'): TestableComponent // top, ending at the glass's tint, and its rows carry the tint, in either appearance. The bar itself has no // background, which iOS would paint behind the fade. expect($bottomBar['props']['glass'] ?? null)->toBe(1) + ->and($bottomBar['props']['glass_opacity'] ?? null)->toBe(Display::ComposerGlassOpacity / 100) ->and(childRefs($screen, 'composer-bar'))->toBe(['composer-fade', 'composer-rows']) ->and($bar['style']['bg_color'] ?? null)->toBeNull() ->and(nodeByRef($screen, 'composer-rows')['style']['bg_color'] ?? null)->toBe('#66'.$surface) @@ -315,6 +331,7 @@ function threadWithAda(string $platform = 'ios'): TestableComponent } else { // No glass on Android. The thread stops at the bar, so the fade lies over its foot, and the bar is the surface. expect($bottomBar['props']['glass'] ?? null)->toBeNull() + ->and($bottomBar['props']['glass_opacity'] ?? null)->toBeNull() ->and(childRefs($screen, 'composer-bar'))->toBe(['composer-rows']) ->and($bar['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) ->and(nodeByRef($screen, 'composer-rows')['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) diff --git a/tests/Pest.php b/tests/Pest.php index d1bf556c..4fd27341 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -15,6 +15,7 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Native\Mobile\AsyncTask; +use Native\Mobile\Edge\TailwindParser; use Native\Mobile\Events\Async\AsyncTaskFailed; use Native\Mobile\Events\Async\AsyncTaskFinished; use Native\Mobile\Events\Gallery\MediaSelected; @@ -1124,3 +1125,14 @@ function skipWithoutSkia(): void test()->markTestSkipped('needs the Skia plugin installed'); } } + +/** + * Skips the test unless the installed mobile-air reads an opacity suffix on the glass class (glass/80, from + * NativePHP/mobile-air#735). Without it the composer bars' glass/N isn't parsed at all. + */ +function skipWithoutGlassOpacity(): void +{ + if (! array_key_exists('glassOpacity', TailwindParser::parse('glass/80'))) { + test()->markTestSkipped('Needs a mobile-air that reads glass/N (NativePHP/mobile-air#735)'); + } +} From c5180c652338026861e3b61026827b1010e45cd5 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 01:33:24 +0000 Subject: [PATCH 16/30] Move the glass/N test guard out of Pest.php It sat at the end of tests/Pest.php, where the build branch's partial frames helpers also land, so the two clashed on merge. It's a small class in tests/Support now. Co-Authored-By: Claude Opus 5.5 --- tests/Feature/Screens/CommitDetailTest.php | 5 ++-- tests/Feature/Screens/RemotesComposerTest.php | 3 ++- tests/Pest.php | 12 ---------- tests/Support/GlassOpacity.php | 24 +++++++++++++++++++ 4 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 tests/Support/GlassOpacity.php diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 5e7d4c55..591eb7f1 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Http; use Native\Mobile\Events\Alert\ButtonPressed; use Native\Mobile\Testing\Native; +use Tests\Support\GlassOpacity; beforeEach(function () { config(['devnull.url' => 'http://devnull.test']); @@ -869,7 +870,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): fakeThread(); if ($platform === 'ios') { - skipWithoutGlassOpacity(); + GlassOpacity::skipUnlessSupported(); } $screen = Native::visit('/log/commits/c2', platform: $platform); @@ -917,7 +918,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): })->with(['ios', 'android']); it('fades the glass under the reply bar to 80% on iOS only', function (string $platform) { - skipWithoutGlassOpacity(); + GlassOpacity::skipUnlessSupported(); fakeThread(); $screen = Native::visit('/log/commits/c2', platform: $platform); diff --git a/tests/Feature/Screens/RemotesComposerTest.php b/tests/Feature/Screens/RemotesComposerTest.php index a6c567cb..6e3e0079 100644 --- a/tests/Feature/Screens/RemotesComposerTest.php +++ b/tests/Feature/Screens/RemotesComposerTest.php @@ -10,6 +10,7 @@ use Native\Mobile\Facades\System; use Native\Mobile\Testing\Native; use Native\Mobile\Testing\TestableComponent; +use Tests\Support\GlassOpacity; const ComposerViewerId = '0199e5c4-0000-7000-8000-000000000001'; @@ -298,7 +299,7 @@ function threadWithAda(string $platform = 'ios'): TestableComponent it('puts the bar on glass on iOS and the surface on Android, with no box or line, and fades the thread out above it', function (string $platform) { if ($platform === 'ios') { - skipWithoutGlassOpacity(); + GlassOpacity::skipUnlessSupported(); } serveThreadWithAda([remoteMessageJson(['id' => 1])], ['read_through_id' => 1]); diff --git a/tests/Pest.php b/tests/Pest.php index 4fd27341..d1bf556c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -15,7 +15,6 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Native\Mobile\AsyncTask; -use Native\Mobile\Edge\TailwindParser; use Native\Mobile\Events\Async\AsyncTaskFailed; use Native\Mobile\Events\Async\AsyncTaskFinished; use Native\Mobile\Events\Gallery\MediaSelected; @@ -1125,14 +1124,3 @@ function skipWithoutSkia(): void test()->markTestSkipped('needs the Skia plugin installed'); } } - -/** - * Skips the test unless the installed mobile-air reads an opacity suffix on the glass class (glass/80, from - * NativePHP/mobile-air#735). Without it the composer bars' glass/N isn't parsed at all. - */ -function skipWithoutGlassOpacity(): void -{ - if (! array_key_exists('glassOpacity', TailwindParser::parse('glass/80'))) { - test()->markTestSkipped('Needs a mobile-air that reads glass/N (NativePHP/mobile-air#735)'); - } -} diff --git a/tests/Support/GlassOpacity.php b/tests/Support/GlassOpacity.php new file mode 100644 index 00000000..4acf0dac --- /dev/null +++ b/tests/Support/GlassOpacity.php @@ -0,0 +1,24 @@ +markTestSkipped('Needs a mobile-air that reads glass/N (NativePHP/mobile-air#735)'); + } + } +} From f03090c4b6512f0ff509bc0419f83b5ea6a0042d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 02:14:29 +0000 Subject: [PATCH 17/30] Open every level of replies in place on the commit page, as the web does A reply's "N replies" on the commit page used to open that reply's own page. Now it opens its replies under it, and theirs under them, as deep as they go, the way the web's commit page does. Tapping a reply still opens its page. The rows come from #179's ThreadRows, now recursive, and the threads from ExpandsThreads, which replaces the page's separate mechanism for a deleted reply's replies. Indentation stops at the web's depth of three (maxIndentDepth in commit-thread.tsx). Replies at the third step hang on their own elbow off the line of the reply they answer, and deeper ones line up under them with no lines and a "replying to @handle" line. "Show more" is a row of its own on the page too, as on the Log, and says "to @handle" past that depth. The Log keeps opening only the commit's replies in place. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/RowInputs.php | 1 - app/Devnull/ThreadRows.php | 193 +++++++++++++----- app/NativeComponents/CommitDetail.php | 119 ++++------- .../Concerns/ExpandsThreads.php | 8 +- .../views/native/commit-detail.blade.php | 75 ++----- .../native/partials/related-commits.blade.php | 1 + .../native/partials/thread-links.blade.php | 33 +-- .../native/partials/thread-more-row.blade.php | 40 +++- .../native/partials/thread-more.blade.php | 17 -- .../native/partials/thread-reply.blade.php | 62 +++--- .../Feature/Screens/CommitDetailCacheTest.php | 2 +- tests/Feature/Screens/CommitDetailTest.php | 15 +- tests/Feature/Screens/NestedRepliesTest.php | 77 +++++++ tests/Feature/Screens/RowCacheScreensTest.php | 6 +- tests/Unit/Devnull/ThreadRowsTest.php | 86 ++++++++ 15 files changed, 457 insertions(+), 278 deletions(-) delete mode 100644 resources/views/native/partials/thread-more.blade.php create mode 100644 tests/Feature/Screens/NestedRepliesTest.php create mode 100644 tests/Unit/Devnull/ThreadRowsTest.php diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index 33d2f741..323d2265 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -40,7 +40,6 @@ public static function for(Commit $commit, array $scope): array 'continued' => in_array($commit->id, $scope['threadsContinued'] ?? [], true), 'popping' => [$scope['popping']['star-'.$commit->id] ?? null, $scope['popping']['pastel-'.$commit->id] ?? null], 'tombstones' => $scope['tombstones'] ?? false, - 'tombstoneReplies' => array_key_exists($commit->id, $scope['tombstoneReplies'] ?? []), 'shown' => [self::changing($commit), $commit->quotedCommit === null ? null : self::changing($commit->quotedCommit)], 'poll' => [$scope['pollChoices'][$commit->id] ?? null, in_array($commit->id, $scope['voting'] ?? [], true)], ]; diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php index 337766d9..61e7042f 100644 --- a/app/Devnull/ThreadRows.php +++ b/app/Devnull/ThreadRows.php @@ -3,21 +3,35 @@ namespace App\Devnull; use App\Devnull\Data\Commit; +use Closure; /** - * The list rows of a commit's thread opened in a feed (see - * Concerns\ExpandsThreads), in order, each with what its partial draws. + * The rows of a commit's thread opened in place (see + * Concerns\ExpandsThreads), in order, each with what its partial draws: in a + * feed, and on a commit page under the commit and under the last part of its + * author's thread. * * Under the commit come its replies, each followed by its own replies when - * they're open, one step in, and "Show more" after the replies of a thread - * with more. Every row is a list row of its own, and the last one closes the - * commit's row with its hairline. + * they're open, and theirs, as deep as they go, with "Show more" after the + * replies of a thread with more. Every row is a row of its own, and in a feed + * the last one closes the commit's row with its hairline. * * The thread hangs off the rail in dashes, as on the web: the first reply on * an elbow from the commit's rail, each later one on a short link from the * line down from the reply above, which is in that reply's lane. A reply's - * own replies hang the same way off the line down from its avatar, which runs - * on past them ($spine) when another reply of the commit follows. + * own replies hang the same way off the line down from its avatar, one step + * in, and that line runs on past them ($spines) when another reply follows. + * + * The steps in stop at the web's depth (MaxIndentDepth). Replies at that + * depth each hang on an elbow of their own from the line of the reply they + * answer, as the web draws every reply, since their replies line up under + * them and a line down from one avatar to the next would run through those. + * Deeper replies are flattened: in the same column, with no lines, and a + * "↳ replying to @handle" line saying who they answer. + * + * In a feed only the commit's replies open theirs in place ($opensInPlace), + * and a reply's replies open their page. On a commit page every reply opens + * its replies in place. */ final class ThreadRows { @@ -35,67 +49,151 @@ final class ThreadRows */ public const int FirstReplyTop = 3; + /** + * How deep replies step in, as the web's maxIndentDepth: the commit's + * replies are 1, and deeper replies line up under those at this depth. + */ + public const int MaxIndentDepth = 3; + + /** + * How far in each step is, in points. + */ + public const int Step = 32; + /** * @param array> $threads Open threads, by the id of the commit or reply they answer. * @param array $cursors Where each open thread with more carries on. * @param array $shown How many of each open thread's replies show. * @param int|string|null $railLane The commit's rail running on past its thread, when its author's run carries on below. + * @param int $opensInPlace How deep a reply's replies button opens its replies in place rather than its page. + * @param bool $onPage On a commit page: replies muted, deleted ones open theirs in place, and no hairline under them. + * @param string|null $morePress What the commit's own "Show more" presses, when it isn't showMoreReplies. * @return list, reply: Commit|null}> */ - public static function under(Commit $commit, array $threads, array $cursors, array $shown, int|string|null $railLane = null): array - { + public static function under( + Commit $commit, + array $threads, + array $cursors, + array $shown, + int|string|null $railLane = null, + int $opensInPlace = 1, + bool $onPage = false, + ?string $morePress = null, + ): array { $thread = fn (string $id): array => array_slice($threads[$id] ?? [], 0, $shown[$id] ?? null); $hasMore = fn (string $id): bool => isset($cursors[$id]) || count($thread($id)) < count($threads[$id] ?? []); - $replies = $thread($commit->id); - if ($replies === []) { + $rows = []; + self::branch($rows, $commit, 1, [], $thread, $hasMore, [ + 'railLane' => $railLane, + 'opensInPlace' => $opensInPlace, + 'onPage' => $onPage, + 'morePress' => $morePress, + ]); + + if ($rows === []) { return []; } - $rows = []; - $more = $hasMore($commit->id); + $last = array_key_last($rows); + $rows[$last]['data']['last'] = true; + + return $rows; + } + + /** + * How far in replies at $depth start, past the commit's text. + */ + public static function indent(int $depth): int + { + return (min($depth, self::MaxIndentDepth) - 1) * self::Step; + } + + /** + * The x of the line down from the avatars of replies at $depth, or the commit's rail above them all. + */ + private static function lineAt(int $depth): float + { + return $depth === 0 ? 31.5 : 75.5 + self::indent($depth); + } + + /** + * The rows of $parent's replies at $depth, and theirs under each. + * + * @param list> $rows + * @param list $spines Lines from further up running on past these rows. + * @param Closure(string): list $thread + * @param Closure(string): bool $hasMore + * @param array{railLane: int|string|null, opensInPlace: int, onPage: bool, morePress: string|null} $options + */ + private static function branch(array &$rows, Commit $parent, int $depth, array $spines, Closure $thread, Closure $hasMore, array $options): void + { + $replies = $thread($parent->id); + + if ($replies === []) { + return; + } + + $more = $hasMore($parent->id); + $indent = self::indent($depth); + $hangs = $depth === self::MaxIndentDepth; + $flattened = $depth > self::MaxIndentDepth; + $parentLine = self::lineAt($depth - 1); + $onPage = $options['onPage']; foreach ($replies as $index => $reply) { - $nested = $reply->isDeleted() ? [] : $thread($reply->id); - $nestedMore = $nested !== [] && $hasMore($reply->id); + $nested = $reply->isDeleted() && ! $onPage ? [] : $thread($reply->id); $followed = $index < count($replies) - 1 || $more; + $top = ! $onPage && $depth === 1 && $index === 0 ? self::FirstReplyTop : 10; $rows[] = self::reply($reply, [ - 'lane' => $commit->lane(), - 'previousLane' => $index === 0 ? null : $replies[$index - 1]->lane(), - 'hasNext' => $followed || $nested !== [], - 'railLane' => $railLane, - 'thread' => $commit, - 'repliesInPlace' => true, - ...($index === 0 ? ['top' => self::FirstReplyTop] : []), + 'lane' => $parent->lane(), + 'previousLane' => $index === 0 || $hangs ? null : $replies[$index - 1]->lane(), + 'hasNext' => ! $hangs && ! $flattened && ($followed || $nested !== []), + 'links' => ! $flattened, + 'railLane' => $options['railLane'], + 'indent' => $indent, + 'top' => $top, + // At the deepest step the line of the reply answered runs on under the elbow to the next one. + 'spines' => [...$spines, ...($hangs && $followed ? [['left' => $parentLine, 'lane' => $parent->lane(), 'top' => $top + 12]] : [])], + 'replyingTo' => $flattened ? self::replyingTo($reply, $parent) : null, + 'repliesInPlace' => $depth <= $options['opensInPlace'], + 'muted' => $onPage, + 'tombstones' => $onPage, ]); - foreach ($nested as $nestedIndex => $nestedReply) { - $rows[] = self::reply($nestedReply, [ - 'lane' => $reply->lane(), - 'previousLane' => $nestedIndex === 0 ? null : $nested[$nestedIndex - 1]->lane(), - 'hasNext' => $nestedIndex < count($nested) - 1 || $nestedMore, - 'railLane' => $railLane, - 'indent' => 32, - 'spine' => $followed ? $reply->lane() : null, - 'thread' => $reply, - 'repliesInPlace' => false, - ]); - } - - if ($nestedMore) { - $rows[] = self::more($reply->id, $nested[array_key_last($nested)]->lane(), $railLane, 32, $followed ? $reply->lane() : null); - } + // The line that has to run on past this reply's own replies, to the next reply at this depth. + $through = match (true) { + ! $followed || $flattened => [], + $hangs => [['left' => $parentLine, 'lane' => $parent->lane()]], + default => [['left' => self::lineAt($depth), 'lane' => $reply->lane()]], + }; + + self::branch($rows, $reply, $depth + 1, [...$spines, ...$through], $thread, $hasMore, $options); } if ($more) { - $rows[] = self::more($commit->id, $replies[array_key_last($replies)]->lane(), $railLane); + $rows[] = self::more($parent, [ + 'lane' => $replies[array_key_last($replies)]->lane(), + 'parentLane' => $parent->lane(), + 'hangs' => $hangs, + 'links' => ! $flattened, + 'railLane' => $options['railLane'], + 'indent' => $indent, + 'spines' => $spines, + 'to' => $flattened && ! $parent->isDeleted() ? $parent->author->handle() : null, + 'hairline' => ! $onPage, + ...($depth === 1 && $options['morePress'] !== null ? ['press' => $options['morePress']] : []), + ]); } + } - $last = array_key_last($rows); - $rows[$last]['data']['last'] = true; - - return $rows; + /** + * "replying to @handle", or "quoting" when the reply quotes what it answers, as the web marks a flattened reply. + */ + private static function replyingTo(Commit $reply, Commit $parent): string + { + return ($reply->quotedCommitId === $parent->id ? 'quoting ' : 'replying to ').($parent->isDeleted() ? '[deleted]' : $parent->author->handle()); } /** @@ -107,7 +205,7 @@ private static function reply(Commit $reply, array $data): array return [ 'key' => 'thread-reply-'.$reply->id, 'partial' => 'native.partials.thread-reply', - 'data' => ['reply' => $reply, 'indent' => 0, 'spine' => null, 'last' => false, 'fades' => true, ...$data], + 'data' => ['reply' => $reply, 'last' => false, 'fades' => true, ...$data], 'reply' => $reply, ]; } @@ -115,14 +213,15 @@ private static function reply(Commit $reply, array $data): array /** * "Show more" at the foot of a thread, on a line down in the lane of the reply above it. * + * @param array $data * @return array{key: string, partial: string, data: array, reply: null} */ - private static function more(string $threadId, int|string $lane, int|string|null $railLane, int $indent = 0, int|string|null $spine = null): array + private static function more(Commit $parent, array $data): array { return [ - 'key' => 'thread-more-'.$threadId, + 'key' => 'thread-more-'.$parent->id, 'partial' => 'native.partials.thread-more-row', - 'data' => ['threadId' => $threadId, 'lane' => $lane, 'railLane' => $railLane, 'indent' => $indent, 'spine' => $spine, 'last' => false], + 'data' => ['threadId' => $parent->id, 'last' => false, ...$data], 'reply' => null, ]; } diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index b2d1a490..d7dd120f 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -23,6 +23,7 @@ use App\Devnull\Toasts; use App\Icons\Lucide; use App\Models\PendingWrite; +use App\NativeComponents\Concerns\ExpandsThreads; use App\NativeComponents\Concerns\OpensInTab; use App\NativeComponents\Concerns\OpensLiveStream; use App\NativeComponents\Concerns\RedrawsOnAppearanceChange; @@ -46,7 +47,11 @@ * "› N replies", each opened in place. Opened from a "› N replies" button * ($data['replies']), its replies already show. They come ten at a time * (see Client::RepliesPerPage), and "Show more" under the last asks for the - * next ten, as it does under a deleted reply's replies opened in place. + * next ten. + * + * Each reply's own replies open in place under it, and theirs under them, as + * deep as they go, as the web's commit page does (see ExpandsThreads and + * App\Devnull\ThreadRows). Tapping a reply still opens its page. * * It opens on the commit as it was last time, or opened from a row, on what * the row knew of it, then asks devnull for the rest behind it and fills it in. @@ -87,6 +92,10 @@ */ class CommitDetail extends NativeComponent { + use ExpandsThreads { + toggleReplies as private toggleThread; + showMoreReplies as private showMoreThreadReplies; + } use OpensInTab; use OpensLiveStream; use RedrawsOnAppearanceChange; @@ -190,20 +199,6 @@ class CommitDetail extends NativeComponent */ public bool $repliesLoaded = false; - /** - * The replies of deleted replies that were opened in place, by the deleted reply's id. - * - * @var array> - */ - public array $tombstoneReplies = []; - - /** - * Where the next page of each deleted reply's replies starts, by the deleted reply's id, or null when they're all shown. - * - * @var array - */ - public array $tombstoneCursors = []; - public string $reply = ''; /** @@ -313,7 +308,7 @@ public function load(): void protected function revalidate(): void { - $this->refresh($this->threadPath(), [], fn (array $json) => $this->takeThread($json)); + $this->refresh($this->threadPath(), [], fn (array $json) => $this->takeCommitThread($json)); $this->refresh($this->threadPath().'/replies', [], fn (array $json) => $this->takeReplies($json)); $this->refresh($this->threadPath().'/related', [], fn (array $json) => $this->takeRelated($json), quiet: true, failed: function (): void { $this->related = []; @@ -324,19 +319,7 @@ protected function revalidate(): void $this->refreshPartReplies((string) $id); } - foreach (array_keys($this->tombstoneReplies) as $id) { - $id = (string) $id; - - $this->refresh('commits/'.rawurlencode($id).'/replies', [], function (array $json) use ($id): void { - if (array_key_exists($id, $this->tombstoneReplies)) { - [$this->tombstoneReplies[$id], $this->tombstoneCursors[$id]] = self::withFirstPage( - $this->tombstoneReplies[$id], - $this->tombstoneCursors[$id] ?? null, - Page::fromArray($json, Commit::fromArray(...)), - ); - } - }); - } + $this->refreshThreads(); } protected function showsContent(): bool @@ -364,11 +347,32 @@ public function replyTapped(): void } /** - * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. + * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. Under a reply, at any + * depth, it opens that reply's replies in place under it (see ExpandsThreads). + */ + public function toggleReplies(string $id = ''): void + { + if ($id === '' || $id === $this->id) { + $this->repliesShown = ! $this->repliesShown; + + return; + } + + $this->toggleThread($id); + } + + /** + * "Show more" under a reply's replies opened in place. The commit's own go on from loadMoreReplies(). */ - public function toggleReplies(): void + public function showMoreReplies(string $id): void { - $this->repliesShown = ! $this->repliesShown; + if ($id === $this->id) { + $this->loadMoreReplies(); + + return; + } + + $this->showMoreThreadReplies($id); } /** @@ -445,39 +449,6 @@ public function toggleRelated(): void Beat::dispatch(self::RelatedFade)->finished($closed)->failed($closed); } - /** - * A deleted reply has no page of its own, so its replies open in place below it. - */ - public function toggleTombstone(string $id): void - { - if (array_key_exists($id, $this->tombstoneReplies)) { - unset($this->tombstoneReplies[$id], $this->tombstoneCursors[$id]); - - return; - } - - $this->loadTombstoneReplies($id); - } - - /** - * "Show more" under a deleted reply's replies: its next five, in place. - */ - public function loadMoreTombstoneReplies(string $id): void - { - $cursor = $this->tombstoneCursors[$id] ?? null; - - if ($cursor === null) { - return; - } - - $page = $this->attempt(fn ($devnull) => $devnull->replies($id, $cursor)); - - if ($page !== null && array_key_exists($id, $this->tombstoneReplies)) { - $this->tombstoneReplies[$id] = [...$this->tombstoneReplies[$id], ...$page->items]; - $this->tombstoneCursors[$id] = $page->nextCursor; - } - } - public function loadMoreReplies(): void { if ($this->repliesCursor === null) { @@ -740,7 +711,7 @@ protected function updateShownCommits(Closure $update): void $this->replies = array_map($update, $this->replies); $this->partReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->partReplies); $this->related = array_map($update, $this->related); - $this->tombstoneReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->tombstoneReplies); + $this->threads = array_map(fn (array $replies): array => array_map($update, $replies), $this->threads); } /** @@ -748,7 +719,7 @@ protected function updateShownCommits(Closure $update): void */ protected function shownCommits(): iterable { - return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...array_merge([], ...array_values($this->partReplies)), ...$this->related, ...array_merge([], ...array_values($this->tombstoneReplies))]; + return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...array_merge([], ...array_values($this->partReplies)), ...$this->related, ...$this->threadCommits()]; } /** @@ -799,7 +770,7 @@ private function keepStagedReplies(): void private function showKept(): void { if (($thread = $this->cached($this->threadPath())) !== null) { - $this->takeThread($thread); + $this->takeCommitThread($thread); } elseif ($this->commit === null && ($commit = $this->data('commit')) instanceof Commit && $commit->id === $this->id) { $this->commit = $commit; $this->ancestors = $commit->parent === null ? [] : [$commit->parent]; @@ -825,7 +796,7 @@ private function takeRelated(array $json): void /** * @param array $json */ - private function takeThread(array $json): void + private function takeCommitThread(array $json): void { $thread = CommitThread::fromArray($json); @@ -949,16 +920,6 @@ private function threadPath(): string return 'commits/'.rawurlencode($this->id); } - private function loadTombstoneReplies(string $id): void - { - $page = $this->attempt(fn ($devnull) => $devnull->replies($id)); - - if ($page !== null) { - $this->tombstoneReplies[$id] = $page->items; - $this->tombstoneCursors[$id] = $page->nextCursor; - } - } - /** * Whether the commit is yours, or an organization's you're in, which puts Delete in the nav bar (see Ownership). */ diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 3be3d314..8a31f599 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -19,9 +19,11 @@ * asked for once they're all showing. * * A reply opened in place has the same button under its own actions, which - * opens its replies in place too, one step in. A reply that deep opens its - * replies on its page. Every thread is kept by the id of the commit or reply - * it answers, so a reply's replies sit in $threads beside its commit's. + * opens its replies in place too, one step in. In a feed a reply that deep + * opens its replies on its page. On a commit page every reply opens its + * replies in place, as deep as they go (see CommitDetail and + * App\Devnull\ThreadRows). Every thread is kept by the id of the commit or + * reply it answers, so a reply's replies sit in $threads beside its commit's. * * EDGE can't animate a row coming into a list or going out of it, so replies * fade: a page that opens is drawn see-through ($fadedRows) and drawn again diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 278706ea..df6150b2 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -23,8 +23,9 @@ their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything - around the commit is muted, and still opens its own page. A deleted reply's own replies open in place, - one level in, ten at a time too, since a deleted commit has no page. + around the commit is muted, and still opens its own page. Every reply's own replies open in place under + it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up + under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). A thread its author wrote as replies to themselves carries on below the commit, on the same rail, as the web reads it (see SelfThread): each part wears its place ("2/5"), ten show at a time with "Show @@ -61,73 +62,23 @@ 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), 'threadPosition' => $threadPositions[$row->commit->id] ?? null, 'showsThread' => false, + 'expandable' => false, ]) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) @endif - @if ($hasThread) - @php($railLane = $loop->last ? null : $commit->lane()) - @foreach ($replies as $index => $threadReply) - @php($nested = $tombstoneReplies[$threadReply->id] ?? []) - @php($nestedMore = ($tombstoneCursors[$threadReply->id] ?? null) !== null) - @php($hasNext = ! $loop->last || $repliesCursor !== null) - @php($replyRow = [ - 'reply' => $threadReply, - 'lane' => $commit->lane(), - 'previousLane' => $index === 0 ? null : $replies[$index - 1]->lane(), - 'hasNext' => $hasNext, - 'railLane' => $railLane, - 'tombstones' => true, - 'muted' => true, - 'thread' => $commit, - 'more' => $loop->last && $nested === [] && $repliesCursor !== null ? 'loadMoreReplies' : null, - 'last' => $loop->last && $nested === [], - ]) + {{-- The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). --}} + @php($pageThread = match (true) { $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) + @foreach ($pageThread as $threadRow) + @if ($threadRow['reply'] === null) + @include($threadRow['partial'], $threadRow['data']) + @else @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope)) - @foreach ($nested as $nestedIndex => $nestedReply) - @php($nestedRow = [ - 'reply' => $nestedReply, - 'lane' => \App\Devnull\Lane::Rail, - 'previousLane' => $nestedIndex === 0 ? null : $nested[$nestedIndex - 1]->lane(), - 'hasNext' => ! $loop->last || $nestedMore, - 'railLane' => $railLane, - 'indent' => 32, - 'spine' => $hasNext ? $threadReply->lane() : null, - 'muted' => true, - 'thread' => $nestedMore ? $threadReply : $commit, - 'more' => match (true) { - ! $loop->last => null, - $nestedMore => "loadMoreTombstoneReplies('{$threadReply->id}')", - $loop->parent->last && $repliesCursor !== null => 'loadMoreReplies', - default => null, - }, - 'last' => $loop->last && $loop->parent->last, - ]) - @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$nestedReply->id, \App\Devnull\RowInputs::for($nestedReply, $rowScope), 'native.partials.thread-reply', $nestedRow, $rowScope)) - @endforeach - @endforeach - @endif - @if ($partThread) - @foreach ($lastPartReplies as $index => $threadReply) - @php($replyRow = [ - 'reply' => $threadReply, - 'lane' => $lastPart->lane(), - 'previousLane' => $index === 0 ? null : $lastPartReplies[$index - 1]->lane(), - 'hasNext' => ! $loop->last || $lastPartMore, - 'railLane' => null, - 'muted' => true, - 'thread' => $lastPart, - 'more' => $loop->last && $lastPartMore ? "openReplies('{$lastPart->id}')" : null, - 'last' => $loop->last, - ]) - @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope)) - @endforeach - @endif + @php($replyRows->include('reply-'.$threadRow['reply']->id, \App\Devnull\RowInputs::for($threadRow['reply'], $rowScope), $threadRow['partial'], $threadRow['data'], $rowScope)) + @endif + @endforeach @endforeach @if ($threadMore && $threadParts !== []) diff --git a/resources/views/native/partials/related-commits.blade.php b/resources/views/native/partials/related-commits.blade.php index 452eaedf..af215186 100644 --- a/resources/views/native/partials/related-commits.blade.php +++ b/resources/views/native/partials/related-commits.blade.php @@ -28,6 +28,7 @@ 'seriesExpanded' => false, 'threadBelow' => false, 'withTail' => ! $loop->last, + 'expandable' => false, ]) @endforeach diff --git a/resources/views/native/partials/thread-links.blade.php b/resources/views/native/partials/thread-links.blade.php index 8f2c9084..9f547262 100644 --- a/resources/views/native/partials/thread-links.blade.php +++ b/resources/views/native/partials/thread-links.blade.php @@ -1,23 +1,28 @@ {{-- - The lines beside a reply in a feed's thread (see thread-reply), drawn last in its row so they sit on top: the - commit's rail running on past, the elbow or the link from the reply above, and the line on down to the next one. + The lines beside a reply in a thread (see thread-reply and App\Devnull\ThreadRows), drawn last in its row so they + sit on top: the commit's rail running on past, the lines from further up running on past ($spines, each from its + `top` or the row's top), the elbow or the link from the reply above, and the line on down to the next one. A + flattened reply, past the web's depth, has no links of its own ($links). --}} +@php($spines ??= []) +@php($links ??= true) @if ($railLane !== null) @include('native.partials.rail', ['previous' => $railLane]) @endif -@if ($spine !== null) - @include('native.partials.dashed-line', ['position' => 'top-0 bottom-0', 'left' => 75.5, 'lane' => $spine]) -@endif +@foreach ($spines as $spineLine) + @include('native.partials.dashed-line', ['position' => (isset($spineLine['top']) ? 'top-['.$spineLine['top'].']' : 'top-0').' bottom-0', 'left' => $spineLine['left'], 'lane' => $spineLine['lane']]) +@endforeach -@if ($previousLane === null) - @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 75.5 : 31.5, 'to' => 64 + $indent, 'level' => $top + 12]) -@else - @include('native.partials.dashed-line', ['position' => 'top-0 h-['.($top - 4).']', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) -@endif +@if ($links) + @if ($previousLane === null) + @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 43.5 + $indent : 31.5, 'to' => 64 + $indent, 'level' => $top + 12]) + @else + @include('native.partials.dashed-line', ['position' => 'top-0 h-['.($top - 4).']', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) + @endif -@if ($hasNext) - {{-- From 4pt under the avatar down to the next reply, or to the top of Show more's dot: 12pt under it, its padding - and the hairline below. --}} - @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] '.($more !== null ? 'bottom-[34]' : 'bottom-0'), 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) + @if ($hasNext) + {{-- From 4pt under the avatar down to the next row, which carries it on. --}} + @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) + @endif @endif diff --git a/resources/views/native/partials/thread-more-row.blade.php b/resources/views/native/partials/thread-more-row.blade.php index d35dc8f2..4b77ced3 100644 --- a/resources/views/native/partials/thread-more-row.blade.php +++ b/resources/views/native/partials/thread-more-row.blade.php @@ -1,18 +1,28 @@ {{-- - "Show more" at the foot of a thread opened in a feed (see App\Devnull\ThreadRows), as a list row of its own: a muted - rail dot where the next avatar would be, on the dashed line down from the reply above ($lane), and the words. - Tapped, the thread's next page opens under what's showing. $indent puts it one step in, under a reply's own replies. + "Show more" at the foot of a thread opened in place (see App\Devnull\ThreadRows), as a row of its own: a muted rail + dot where the next avatar would be, on the dashed line down from the reply above ($lane), and the words. Tapped, + the thread's next page opens under what's showing, or whatever $press says. $indent puts it as far in as the + replies above it, and $spines carry the lines from further up on past it. + + At the web's deepest step the dot hangs on an elbow from the line of the reply the thread answers ($hangs, in + $parentLane), as those replies do. Past it there are no lines ($links), and it says whose replies these are ($to). It's 44pt tall, as tall as the list's shortest row, so the list never pads it out under its hairline. The dot sits - in its middle, so the line from above stops at the top of the dot, 13pt down. + in its middle, so the line from above stops at the top of the dot, 13pt down. In a feed the $last closes the + commit's row with its hairline; on a commit page ($hairline false) nothing does. --}} @php($indent ??= 0) -@php($spine ??= null) +@php($spines ??= []) @php($railLane ??= null) +@php($hangs ??= false) +@php($links ??= true) +@php($to ??= null) +@php($hairline ??= true) +@php($press ??= "showMoreReplies('{$threadId}')") @php($faded = in_array('more-'.$threadId, $fadedRows ?? [], true)) - + - + @@ -20,14 +30,22 @@ - Show more + @if ($to === null) + Show more + @else + Show more to {{ $to }} + @endif @if ($railLane !== null) @include('native.partials.rail', ['previous' => $railLane]) @endif - @if ($spine !== null) - @include('native.partials.dashed-line', ['position' => 'top-0 bottom-0', 'left' => 75.5, 'lane' => $spine]) + @foreach ($spines as $spineLine) + @include('native.partials.dashed-line', ['position' => (isset($spineLine['top']) ? 'top-['.$spineLine['top'].']' : 'top-0').' bottom-0', 'left' => $spineLine['left'], 'lane' => $spineLine['lane']]) + @endforeach + @if ($links && $hangs) + @include('native.partials.thread-elbow', ['lane' => $parentLane, 'from' => 43.5 + $indent, 'to' => 64 + $indent, 'level' => 22]) + @elseif ($links) + @include('native.partials.dashed-line', ['position' => 'top-0 h-[13]', 'left' => 75.5 + $indent, 'lane' => $lane]) @endif - @include('native.partials.dashed-line', ['position' => 'top-0 h-[13]', 'left' => 75.5 + $indent, 'lane' => $lane]) diff --git a/resources/views/native/partials/thread-more.blade.php b/resources/views/native/partials/thread-more.blade.php deleted file mode 100644 index 6ed4afba..00000000 --- a/resources/views/native/partials/thread-more.blade.php +++ /dev/null @@ -1,17 +0,0 @@ -{{-- - "Show more" at the foot of a thread, as the web's: a muted rail dot where the next avatar would be, and the words. - It sits inside the last reply's row, under the reply, so the rail beside it never breaks: a row of its own is - shorter than the list's shortest, and the list pads it out under its hairline. ---}} - - - - - - - - - - Show more - - diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index ff5bea8c..aba96aec 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -1,18 +1,18 @@ {{-- - A reply in the thread under a commit in a feed, like a reply in the web's thread: a 24pt avatar lined up with the - commit's text, the name and time, the body and its actions. The thread hangs off the rail in dashes of each - author's lane, as upstream's #121 draws it: the first reply on an elbow from the rail ($lane is the commit's), each - later one on a short link from the reply above ($previousLane), and a line on down from its avatar when another - reply, or "Show more", follows ($hasNext). $railLane runs the commit's own rail on past, solid, when its author's - run goes on below the thread. A deleted reply keeps its place with a dashed ring. In a feed the $last closes the - commit's row with its hairline. On a commit page nothing follows the thread, so there's no hairline. + A reply in a thread opened in place (see App\Devnull\ThreadRows), like a reply in the web's thread: a 24pt avatar + lined up with the commit's text, or $indent further in, the name and time, the body and its actions. The thread + hangs off the rail in dashes of each author's lane, as upstream's #121 draws it: the first reply on an elbow from + the line of what it answers ($lane is that one's), each later one on a short link from the reply above + ($previousLane), and a line on down from its avatar when another reply, its own replies, or "Show more", follows + ($hasNext). $spines carry lines from further up on past it, and $railLane runs the commit's own rail on past, + solid, when its author's run goes on below the thread (see thread-links). A deleted reply keeps its place with a + dashed ring. In a feed the $last closes the commit's row with its hairline. On a commit page nothing follows the + thread, so there's no hairline. - On a commit page a deleted reply's own replies open in place ($tombstones), since it has no page of their own, - one level in ($indent 32), hanging off a dashed spine from its ring as the web nests them. $spine carries the - thread's line on past a nested reply when the deleted one has another reply after it. + Past the web's depth a reply is flattened: it lines up under the reply it answers, with no lines of its own + ($links), and says who it answers on a line under its name ($replyingTo), as the web does. - The last reply carries the thread's "Show more" when there's more ($more, what it presses), with the line from its - avatar running down to it. + On a commit page a deleted reply's own replies open in place too ($tombstones), with "N replies" under its ring. $top is the space above the avatar, 10pt, less for the first reply in a feed, which sits under the commit row's bottom padding (see ThreadRows::FirstReplyTop). The lines beside it are placed from the avatar, so they move with it. @@ -24,29 +24,31 @@ A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. - In a feed a reply's replies button opens them under it ($repliesInPlace, see App\Devnull\ThreadRows); deeper in, - or on a commit page, it opens the reply's page. A feed's thread rows fade in as they open and out as they close - ($fades): drawn see-through and nudged up while they're in $fadedRows (see Concerns\ExpandsThreads), and eased - to where they belong. Only what's beside the rail fades, so the commit's rail running past never blinks. + A reply's replies button opens them under it ($repliesInPlace): on a commit page at every depth, in a feed only for + the commit's own replies, and a reply's replies there open its page. Tapping the reply itself opens its page. The + rows fade in as they open and out as they close ($fades): drawn see-through and nudged up while they're in + $fadedRows (see Concerns\ExpandsThreads), and eased to where they belong. Only what's beside the rail fades, so + the commit's rail running past never blinks. --}} @php($previousLane ??= null) @php($muted ??= false) @php($railLane ??= null) @php($indent ??= 0) -@php($spine ??= null) +@php($spines ??= []) +@php($links ??= true) +@php($replyingTo ??= null) @php($tombstones ??= false) -@php($more ??= null) @php($avatarLine = 76 + $indent) @php($repliesInPlace ??= false) @php($fades ??= false) @php($top ??= 10) @php($faded = $fades && in_array($reply->id, $fadedRows ?? [], true)) @if ($reply->isDeleted()) - @php($opened = $tombstones && array_key_exists($reply->id, $tombstoneReplies ?? [])) + @php($opened = $tombstones && array_key_exists($reply->id, $threads ?? []) && ! in_array($reply->id, $closingThreads ?? [], true)) - + @include('native.partials.dashed-ring', ['size' => 24, 'lane' => \App\Devnull\Lane::Rail]) @@ -55,7 +57,7 @@ [deleted] This commit was deleted. @if ($tombstones && $reply->repliesCount > 0) - + {{ $opened ? 'Hide replies' : \App\Devnull\Display::count($reply->repliesCount, 'reply', 'replies') }} @@ -64,18 +66,11 @@ @endif - @if ($more !== null) - @include('native.partials.thread-more', ['commit' => $thread ?? $reply]) - @endif @if ($last && ! $muted) @endif @include('native.partials.thread-links') - @if ($opened && ($tombstoneReplies[$reply->id] ?? []) !== []) - {{-- The spine its own replies hang off, down from its ring. --}} - @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => \App\Devnull\Lane::Rail]) - @endif @else @php($commit = $reply) @@ -83,7 +78,7 @@ - + @include('native.partials.rail-avatar', ['user' => $reply->author, 'lane' => $reply->lane(), 'size' => 24, 'staged' => false]) @@ -96,6 +91,12 @@ @include('native.partials.status-chip', ['status' => $reply->status]) @endunless + @if ($replyingTo !== null) + + + {{ $replyingTo }} + + @endif @include('native.partials.commit-body', ['size' => $muted ? 'text-sm' : 'text-[15px]']) @include('native.partials.commit-media', ['withEmbeds' => false]) @if ($reply->continuationId !== null || in_array($reply->id, $threadsContinued ?? [], true)) @@ -106,9 +107,6 @@ @endunless - @if ($more !== null) - @include('native.partials.thread-more', ['commit' => $thread ?? $reply]) - @endif @if ($last && ! $muted) @endif diff --git a/tests/Feature/Screens/CommitDetailCacheTest.php b/tests/Feature/Screens/CommitDetailCacheTest.php index 145eaedf..1694cf61 100644 --- a/tests/Feature/Screens/CommitDetailCacheTest.php +++ b/tests/Feature/Screens/CommitDetailCacheTest.php @@ -140,7 +140,7 @@ function serveThread(): void 'GET /api/v1/commits/d1/replies' => [pageJson([replyJson(['id' => 'r9', 'parent_id' => 'd1', 'body' => 'Under a deleted reply'])])], ]); - $screen = Native::visit('/log/commits/c1')->tap('replies-c1')->call('toggleTombstone', 'd1')->assertSee('Under a deleted reply'); + $screen = Native::visit('/log/commits/c1')->tap('replies-c1')->call('toggleReplies', 'd1')->assertSee('Under a deleted reply'); $screen->call('load'); diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 4da73df3..c25d0645 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -526,29 +526,28 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $screen->tap('replies-c2')->assertDontSee('First reply')->assertSee('1 reply'); expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 0.0, 'animate-duration' => 220.0]); - // A reply's button opens its page rather than its replies in place, so its chevron stays put. + // A reply's button opens its replies in place too, so its chevron turns the same way. $screen->tap('replies-c2'); - expect($chevron('replies-r1')['props'])->not->toHaveKey('rotate'); + expect($chevron('replies-r1')['props'])->toMatchArray(['rotate' => 0.0, 'animate-duration' => 220.0]); })->with(['ios', 'android']); it('opens with its replies showing from a replies button', function () { fakeThread(['replies_count' => 1], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1])], extra: [ 'GET /api/v1/commits/r1' => [commitPageJson(replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1]))], - 'GET /api/v1/commits/r1/replies' => [pageJson([replyJson(['id' => 'r2', 'parent_id' => 'r1', 'body' => 'Answering the reply'])])], + // Someone other than r1's author, whose reply to themselves would carry r1 on as a thread instead. + 'GET /api/v1/commits/r1/replies' => [pageJson([replyJson(['id' => 'r2', 'parent_id' => 'r1', 'body' => 'Answering the reply', 'author' => userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace'])])])], ]); Native::visit('/log/commits/c2', ['replies' => true]) ->assertSee('First reply') ->assertSee('Hide replies'); - // A reply's replies don't open in place on a commit page, so its button opens its page with them showing. + // A reply's replies open in place under it, as on the web, rather than on its page. Native::visit('/log/commits/c2') ->tap('replies-c2') ->tap('replies-r1') - ->assertNavigatedTo('/log/commits/r1') - ->follow() - ->assertSee('Answering the reply') - ->assertSee('Hide replies'); + ->assertNoNavigation() + ->assertSee('Answering the reply'); }); it('asks for the replies a page at a time, and the next page from Show more', function () { diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php new file mode 100644 index 00000000..9d208b7a --- /dev/null +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -0,0 +1,77 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * A commit page for c2 whose replies chain five deep: r1 answers c2, r2 answers r1, and so on, each from someone + * other than the one they answer, so none of them carries a thread on. + */ +function fakeDeepThread(): void +{ + $handles = ['grace', 'linus', 'alan', 'edsger', 'ken']; + $reply = fn (int $depth): array => replyJson([ + 'id' => "r{$depth}", + 'parent_id' => $depth === 1 ? 'c2' : 'r'.($depth - 1), + 'body' => "Reply at depth {$depth}", + 'replies_count' => $depth < 5 ? 1 : 0, + 'author' => userJson(['handle' => $handles[$depth - 1], 'name' => ucfirst($handles[$depth - 1]), 'lane' => $depth]), + ]); + + Http::fake(function (Request $request) use ($reply) { + $path = parse_url($request->url(), PHP_URL_PATH); + + return match (true) { + $path === '/api/v1/commits/c2' => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'replies_count' => 1]))), + $path === '/api/v1/commits/c2/related' => Http::response(['data' => []]), + $path === '/api/v1/commits/c2/replies' => Http::response(pageJson([$reply(1)])), + (bool) preg_match('#^/api/v1/commits/r(\d)/replies$#', $path, $match) => Http::response(pageJson((int) $match[1] < 5 ? [$reply((int) $match[1] + 1)] : [])), + default => Http::response(['message' => 'No fake.'], 404), + }; + }); +} + +it('opens replies of replies in place on a commit page, as deep as they go, without leaving the page', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true])->assertSee('Reply at depth 1'); + + foreach (range(1, 4) as $depth) { + $screen->tap("replies-r{$depth}")->assertSee('Reply at depth '.($depth + 1)); + } + + $screen->assertNoNavigation()->assertSee('Reply at depth 5'); + + // Hiding a reply's replies takes the ones opened under them away too. + $screen->tap('replies-r2')->assertDontSee('Reply at depth 3'); + finishRefreshes($screen)->assertDontSee('Reply at depth 5'); + + // Tapping a reply itself still opens its page. + $screen->tap('thread-reply-r2')->assertNavigatedTo('/log/commits/r2'); +}); + +it('steps replies in up to the third level, and lines deeper ones up under it saying who they answer', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + foreach (range(1, 4) as $depth) { + $screen->tap("replies-r{$depth}"); + } + + // The left padding of the row the reply's avatar sits in, past the commit's 64pt gutter. + $indent = fn (string $id): float => (float) (findNode(nodeByRef($screen, "thread-reply-{$id}"), fn (array $node): bool => ($node['type'] ?? null) === 'row' && isset($node['layout']['padding']))['layout']['padding'][3] ?? 0); + $elbow = fn (string $id): bool => findNode(nodeByRef($screen, "thread-reply-{$id}"), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow') !== null; + + expect([$indent('r1'), $indent('r2'), $indent('r3'), $indent('r4'), $indent('r5')])->toEqual([0, 32, 64, 64, 64]) + ->and([$elbow('r1'), $elbow('r2'), $elbow('r3'), $elbow('r4'), $elbow('r5')])->toBe([true, true, true, false, false]) + ->and(rendersRef($screen, 'replying-to-r3'))->toBeFalse(); + + $screen->assertSee('replying to @alan')->assertSee('replying to @edsger'); +}); diff --git a/tests/Feature/Screens/RowCacheScreensTest.php b/tests/Feature/Screens/RowCacheScreensTest.php index 902cbd0d..d7c547cd 100644 --- a/tests/Feature/Screens/RowCacheScreensTest.php +++ b/tests/Feature/Screens/RowCacheScreensTest.php @@ -88,10 +88,10 @@ function expectKeptRowsMatchFreshOnes(TestableComponent $screen, string $class, }); $screen = Native::visit('/log/commits/c2')->tap('replies-c2')->assertSee('Second reply'); - // The commits above the replies read what the screen shows of the thread, so they're built every time. The last - // reply of a page changes when the next page comes, since it no longer carries "more". + // The commits above the replies read what the screen shows of the thread, so they're built every time. "Show + // more" is a row of its own, so the last reply of a page stays as it was when the next page comes. expect(rowsBuiltBy(fn () => $screen->call('navTitle')))->toBe(['c2']) - ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['c2', 'r2', 'r3']); + ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['c2', 'r3']); expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); }); diff --git a/tests/Unit/Devnull/ThreadRowsTest.php b/tests/Unit/Devnull/ThreadRowsTest.php new file mode 100644 index 00000000..dfad7144 --- /dev/null +++ b/tests/Unit/Devnull/ThreadRowsTest.php @@ -0,0 +1,86 @@ + $id, 'parent_id' => $parent, 'author' => userJson(['handle' => $handle, 'lane' => strlen($handle)]), ...$overrides])); +} + +/** + * The rows of a chain five replies deep under c1, with a second reply at the deepest step (r3b), each opened. + * + * @return array> + */ +function deepRows(int $opensInPlace = PHP_INT_MAX): array +{ + $commit = Commit::fromArray(commitJson(['id' => 'c1', 'author' => userJson(['handle' => 'ada'])])); + $threads = [ + 'c1' => [nestedReply('r1', 'c1', 'grace')], + 'r1' => [nestedReply('r2', 'r1', 'linus')], + 'r2' => [nestedReply('r3', 'r2', 'alan'), nestedReply('r3b', 'r2', 'barbara')], + 'r3' => [nestedReply('r4', 'r3', 'edsger', ['quoted_commit_id' => 'r3'])], + 'r4' => [nestedReply('r5', 'r4', 'ken')], + ]; + + $rows = ThreadRows::under($commit, $threads, ['r4' => 'next'], [], opensInPlace: $opensInPlace, onPage: true); + + return array_column(array_map(fn (array $row): array => [$row['key'], $row['data']], $rows), 1, 0); +} + +it('steps replies in up to the web\'s depth of three, and lines deeper ones up under the third', function () { + $rows = deepRows(); + + expect(array_keys($rows))->toBe(['thread-reply-r1', 'thread-reply-r2', 'thread-reply-r3', 'thread-reply-r4', 'thread-reply-r5', 'thread-more-r4', 'thread-reply-r3b']) + ->and(array_map(fn (array $row): int => $row['indent'], $rows))->toBe([ + 'thread-reply-r1' => 0, + 'thread-reply-r2' => 32, + 'thread-reply-r3' => 64, + 'thread-reply-r4' => 64, + 'thread-reply-r5' => 64, + 'thread-more-r4' => 64, + 'thread-reply-r3b' => 64, + ]); +}); + +it('says who a flattened reply answers, and draws it no lines of its own', function () { + $rows = deepRows(); + + expect($rows['thread-reply-r3']['replyingTo'])->toBeNull() + ->and($rows['thread-reply-r3']['links'])->toBeTrue() + ->and($rows['thread-reply-r4']['replyingTo'])->toBe('quoting @alan') + ->and($rows['thread-reply-r5']['replyingTo'])->toBe('replying to @edsger') + ->and($rows['thread-reply-r4']['links'])->toBeFalse() + ->and($rows['thread-reply-r4']['hasNext'])->toBeFalse() + ->and($rows['thread-more-r4']['links'])->toBeFalse() + ->and($rows['thread-more-r4']['to'])->toBe('@edsger'); +}); + +it('hangs each reply at the deepest step on its own elbow, with the line of the reply it answers running on past', function () { + $rows = deepRows(); + $lane = $rows['thread-reply-r3b']['lane']; + + // r3 and r3b both answer r2, so both hang on elbows off r2's line, which runs past r3's own replies to r3b. + expect($rows['thread-reply-r3']['previousLane'])->toBeNull() + ->and($rows['thread-reply-r3b']['previousLane'])->toBeNull() + ->and($rows['thread-reply-r3']['hasNext'])->toBeFalse() + ->and($rows['thread-reply-r3']['spines'])->toBe([['left' => 107.5, 'lane' => $lane, 'top' => 22]]) + ->and($rows['thread-reply-r4']['spines'])->toBe([['left' => 107.5, 'lane' => $lane]]) + ->and($rows['thread-more-r4']['spines'])->toBe([['left' => 107.5, 'lane' => $lane]]) + ->and($rows['thread-reply-r3b']['spines'])->toBe([]) + // Above that the replies chain from avatar to avatar as before. + ->and($rows['thread-reply-r2']['hasNext'])->toBeTrue() + ->and($rows['thread-reply-r3b']['last'])->toBeTrue(); +}); + +it('opens replies in place as deep as the caller allows', function () { + $inPlace = fn (array $rows): array => array_map(fn (array $row): bool => $row['repliesInPlace'], array_filter($rows, fn (array $row): bool => isset($row['repliesInPlace']))); + + expect($inPlace(deepRows()))->each->toBeTrue() + ->and($inPlace(deepRows(opensInPlace: 1))) + ->toBe(['thread-reply-r1' => true, 'thread-reply-r2' => false, 'thread-reply-r3' => false, 'thread-reply-r4' => false, 'thread-reply-r5' => false, 'thread-reply-r3b' => false]); +}); From a0032d3abd580323af32e536bd4ff1eb9f5a842d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 02:21:57 +0000 Subject: [PATCH 18/30] Move the commit page to a commit in its tree instead of pushing another Tapping an ancestor, a part of the series or the author's thread, or a reply at any depth used to push a new commit screen. Now the same page moves to it: the commit becomes the one the page is about, with what's above it as its ancestors and its replies showing below, built from what the page already has so nothing goes blank. The commit it was on keeps its replies opened, so going back up shows where you came from. Reply on a commit in the tree retargets the reply bar the same way. Commits outside the tree still push. Back still leaves the screen, as Simon asked. There's no history of the commits the page moved through. The scroll view's rows are its own children now, so auto-scroll-to can bring the commit into view. Both platforms jump on the first request and animate later ones. Deleting a commit the page moved to takes the page back to its parent. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 259 +++++++++++++++++- .../views/native/commit-detail.blade.php | 12 +- tests/Feature/Screens/CommitDetailTest.php | 37 +-- tests/Feature/Screens/NestedRepliesTest.php | 58 +++- tests/Feature/Screens/RelatedCommitsTest.php | 6 +- tests/Feature/Screens/SelfThreadTest.php | 2 +- tests/Feature/Screens/SeriesTest.php | 3 +- 7 files changed, 347 insertions(+), 30 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index d7dd120f..2eb2380f 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -51,7 +51,11 @@ * * Each reply's own replies open in place under it, and theirs under them, as * deep as they go, as the web's commit page does (see ExpandsThreads and - * App\Devnull\ThreadRows). Tapping a reply still opens its page. + * App\Devnull\ThreadRows). + * + * Tapping a commit in the tree, above the commit, below it or among the + * replies at any depth, moves this page to it rather than pushing another + * (see refocus()). Back still leaves the page. * * It opens on the commit as it was last time, or opened from a row, on what * the row knew of it, then asks devnull for the rest behind it and fills it in. @@ -101,6 +105,9 @@ class CommitDetail extends NativeComponent use RedrawsOnAppearanceChange; use RefreshesInBackground; use ShowsCommits { + openCommit as private openCommitPage; + openReplies as private openRepliesPage; + replyTo as private replyOnPage; reopenFailedCommit as private reopenFailedCommitInSheet; editFailedCommit as private editFailedCommitInSheet; mentionFields as private sheetMentionFields; @@ -239,6 +246,17 @@ class CommitDetail extends NativeComponent */ public int $scrollKey = 0; + /** + * Which of the scroll view's rows it brings into view, the commit's, once tapping another commit in the tree + * moved the page to it (see refocus()). Null until then, so the page opens at the top as it always has. + */ + public ?int $scrollTarget = null; + + /** + * The commit the page opened on, before tapping others in its tree moved it (see refocus()). + */ + public string $openedId = ''; + /** * The replies from the last frame, so a render only builds the replies that changed, as the Log does its rows. */ @@ -255,6 +273,7 @@ class CommitDetail extends NativeComponent public function mount(): void { + $this->openedId = $this->id; $this->focusReply = $this->data('reply', false) === true; $this->repliesShown = $this->data('replies', false) === true; $draft = app(Stash::class)->get($this->me()?->id, $this->replyStashName()); @@ -343,9 +362,237 @@ public function showEarlier(): void public function replyTapped(): void { $this->earlierShown = false; + $this->scrollTarget = null; $this->scrollKey++; } + /** + * A commit in the tree this page shows moves the page to it, rather than + * pushing another commit page (see refocus()). Anything else opens its page. + */ + public function openCommit(string $id): void + { + if (! $this->refocus($id)) { + $this->openCommitPage($id); + } + } + + /** + * "Show more" under the last part of a thread, or "› N replies" on a commit in the tree: the page moves to it with + * its replies showing. + */ + public function openReplies(string $id): void + { + if (! $this->refocus($id)) { + $this->openRepliesPage($id); + } + } + + /** + * Reply on a commit in the tree moves the page to it, with the reply bar answering it and its keyboard up. + */ + public function replyTo(string $id): void + { + if ($id === $this->id) { + $this->focusReply = true; + + return; + } + + if ($this->refocus($id)) { + $this->focusReply = true; + + return; + } + + $this->replyOnPage($id); + } + + /** + * Moves the page to a commit already in its tree: an ancestor, a part of + * the author's thread or series, or a reply at any depth. It becomes the + * commit the page is about, with what's above it as its ancestors and its + * replies showing below, all from what the page already has, so nothing + * goes blank, and devnull is asked for the rest behind it. Replies opened + * in place stay open, and the commit the page was on keeps its replies, so + * moving up shows where you came from opened under its parent. + * + * The page stays one screen: Back still leaves it, as Simon asked, rather + * than stepping back through the commits it moved to. The scroll view + * brings the commit into view, with every ancestor showing above it. + * + * False, changing nothing, for a commit that isn't in the tree, or one + * that's staged or deleted, which has no page of its own. + */ + private function refocus(string $id): bool + { + if ($this->commit === null || $id === $this->id) { + return false; + } + + $target = $this->treeCommit($id); + $ancestors = $target === null || $target->isStaged() || $target->isDeleted() ? null : $this->ancestorsInTree($target); + + if ($ancestors === null) { + return false; + } + + $line = [...$this->ancestors, $this->commit]; + $below = array_slice($line, count($ancestors) + 1); + + // What the page was on keeps its replies, opened in place, for when it's back in the tree. + if ($this->repliesShown && $this->repliesLoaded && $this->replies !== []) { + $this->threads[$this->id] = array_values(array_filter($this->replies, fn (Commit $reply): bool => ! $reply->isStaged())); + $this->keepCursor($this->id, $this->repliesCursor); + unset($this->threadShown[$this->id]); + } + + // Moving up, the commits between keep their replies open, so the one the page was on shows under them. + foreach ($below as $between) { + if ($between->id !== $this->id && ! array_key_exists($between->id, $this->threads) && ($kept = $this->cached('commits/'.rawurlencode($between->id).'/replies')) !== null) { + $this->takeThread($between->id, $kept); + } + } + + $this->id = $id; + $this->commit = $target; + $this->ancestors = $ancestors; + $this->series = []; + $this->related = []; + $this->relatedShown = false; + $this->threadLimit = SelfThread::PerPage; + $this->takeOwnReplies($id); + + if (($thread = $this->cached($this->threadPath())) !== null) { + $this->takeCommitThread($thread); + } + + $this->takeRelated($this->cached($this->threadPath().'/related') ?? []); + $this->repliesShown = true; + $this->earlierShown = true; + $this->takeReplyDraft(); + $this->error = null; + + // The commit's row is the one after its ancestors. A request the scroll view already went to does nothing, + // so going back to the top a second time mounts it again, at the top. + $target = count($this->ancestors); + + if ($target === $this->scrollTarget) { + $this->scrollKey++; + } + + $this->scrollTarget = $target; + $this->forgetRefreshes(); + $this->revalidate(); + $this->followThread(); + + return true; + } + + /** + * The commit's own replies, as the page knows them: opened in place, read for its author's thread, or kept from + * before. Until one of those, they show as loading. + */ + private function takeOwnReplies(string $id): void + { + $this->replies = []; + $this->repliesCursor = null; + $this->repliesLoaded = false; + + if (array_key_exists($id, $this->threads)) { + $this->replies = $this->threads[$id]; + $this->repliesCursor = $this->threadCursors[$id] ?? null; + $this->repliesLoaded = true; + unset($this->threads[$id], $this->threadCursors[$id], $this->threadShown[$id]); + $this->pagedThreads = array_values(array_diff($this->pagedThreads, [$id])); + } elseif (($kept = $this->cached($this->threadPath().'/replies')) !== null) { + $this->takeReplies($kept); + + return; + } elseif (array_key_exists($id, $this->partReplies)) { + $this->replies = $this->partReplies[$id]; + $this->repliesLoaded = true; + } + + $this->keepStagedReplies(); + } + + /** + * The reply bar takes up the draft kept for the commit the page is on now. + */ + private function takeReplyDraft(): void + { + $draft = app(Stash::class)->get($this->me()?->id, $this->replyStashName()); + $this->reply = $draft->body; + $this->replyImages = $draft->images; + $this->replyRestored = ! $draft->isEmpty(); + $this->replyAuthor = null; + $this->replyPreviewing = false; + $this->replyPreview = null; + $this->focusReply = false; + } + + /** + * A commit the page draws in its tree, by id: around the commit, in its author's thread, or among the replies. + */ + private function treeCommit(string $id): ?Commit + { + $lastPart = $this->commit === null ? null : $this->selfThread()->parts; + $tree = [ + ...$this->ancestors, + ...$this->series, + ...($lastPart ?? []), + ...$this->replies, + ...$this->threadCommits(), + ...array_merge([], ...array_values($this->partReplies)), + ]; + + foreach ($tree as $commit) { + if ($commit->id === $id) { + return $commit; + } + } + + return null; + } + + /** + * What's above $target in the tree, in order: the page's line of ancestors as far as the one it hangs from, then + * the replies, parts or series between. Null when it doesn't hang from that line. + * + * @return list|null + */ + private function ancestorsInTree(Commit $target): ?array + { + $line = [...$this->ancestors, ...($this->commit === null ? [] : [$this->commit])]; + $lineIds = array_map(fn (Commit $commit): string => $commit->id, $line); + $at = array_search($target->id, $lineIds, true); + + if ($at !== false) { + return array_slice($line, 0, $at); + } + + $between = []; + $parentId = $target->parentId; + + while ($parentId !== null && ! in_array($parentId, $lineIds, true)) { + $parent = $this->treeCommit($parentId); + + if ($parent === null || in_array($parent, $between, true)) { + return null; + } + + array_unshift($between, $parent); + $parentId = $parent->parentId; + } + + if ($parentId === null) { + return null; + } + + return [...array_slice($line, 0, array_search($parentId, $lineIds, true) + 1), ...$between]; + } + /** * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. Under a reply, at any * depth, it opens that reply's replies in place under it (see ExpandsThreads). @@ -694,6 +941,16 @@ protected function commitSheetGone(string $view): void */ protected function showDeleted(string $id): void { + // The page moved here from a commit above it, so it goes back there rather than leaving. + $parent = $this->ancestors === [] ? null : end($this->ancestors); + + if ($id === $this->id && $id !== $this->openedId && $parent !== null && $this->refocus($parent->id)) { + $this->threads = array_map(fn (array $replies): array => array_values(array_filter($replies, fn (Commit $reply): bool => $reply->id !== $id)), $this->threads); + $this->replies = array_values(array_filter($this->replies, fn (Commit $reply): bool => $reply->id !== $id)); + + return; + } + if ($id === $this->id) { $this->back(); diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index df6150b2..fd7b2a75 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -7,8 +7,12 @@ {{-- The stack around the page holds the fade over its foot, just above the reply bar (see partials/composer-fade). --}} - - + {{-- + Each row is a child of the scroll view itself, so it can bring one into view: the commit the page is on, after + tapping another commit in the tree moves the page to it (see CommitDetail::refocus() and $scrollTarget). The + first move jumps and later ones animate, as auto-scroll-to does on both platforms. + --}} + @if (! $commit && $error === null) @@ -23,7 +27,8 @@ their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything - around the commit is muted, and still opens its own page. Every reply's own replies open in place under + around the commit is muted. Tapping any commit in the tree moves the page to it rather than pushing + another (see CommitDetail::refocus()). Every reply's own replies open in place under it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). @@ -103,7 +108,6 @@ @if ($commit) @endif - @if ($commit && ! \App\Devnull\Display::fadesInBar()) diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index c25d0645..cf451876 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -51,19 +51,19 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('Reply to @local_dev'); // The commit comes after the one it replies to, and the row standing in for what that replies to. - expect(childRefs($screen, 'thread-page'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); $screen->tap('earlier-commits') ->assertSee('The root commit') ->assertDontSee('1 earlier commit'); - expect(childRefs($screen, 'thread-page'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); $screen->tap('replies-c2') ->assertSee('First reply') ->assertSee('Hide replies'); - expect(childRefs($screen, 'thread-page'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); $screen->tap('replies-c2') ->assertDontSee('First reply') @@ -84,7 +84,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('The parent commit') ->assertDontSee('The root commit'); - expect(childRefs($screen, 'thread-page'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']) ->and(nodeByRef($screen, 'thread-scroll')['id'])->not->toBe($before); }); @@ -347,7 +347,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $staged = $screen->instance()->replies[1]->id; - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', "thread-reply-{$staged}", 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', "thread-reply-{$staged}", 'reply-bar-clearance']) ->and(PendingWrite::query()->count())->toBe(1); finishRefreshes($screen) @@ -355,7 +355,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('pending') ->assertDontSee('staged'); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r9', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r9', 'reply-bar-clearance']) ->and(PendingWrite::query()->count())->toBe(0) ->and(collect(Http::recorded())->filter(fn (array $sent): bool => $sent[0]->method() === 'POST'))->toHaveCount(1); }); @@ -383,7 +383,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->call('loadMoreReplies') ->assertSet('repliesCursor', null); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'thread-reply-r9', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'thread-reply-r9', 'reply-bar-clearance']); }); it('marks a reply waiting for approval as pending on its row', function () { @@ -504,10 +504,11 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): }); it('opens ancestors, replies and profiles', function () { - fakeThread(replies: [replyJson(['id' => 'r1'])]); + fakeThread(replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2'])]); - Native::visit('/log/commits/c2')->tap('earlier-commits')->tap('commit-c1')->assertNavigatedTo('/log/commits/c1'); - Native::visit('/log/commits/c2')->tap('replies-c2')->tap('thread-reply-r1')->assertNavigatedTo('/log/commits/r1'); + // Commits in the tree move the page to them, and anything else opens its own page. + Native::visit('/log/commits/c2')->tap('earlier-commits')->tap('commit-c1')->assertNoNavigation()->assertSet('id', 'c1'); + Native::visit('/log/commits/c2')->tap('replies-c2')->tap('thread-reply-r1')->assertNoNavigation()->assertSet('id', 'r1'); Native::visit('/log/commits/c2')->call('openProfile', 'ada')->assertNavigatedTo('/log/users/ada'); }); @@ -664,7 +665,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): // One level in, on an elbow off the deleted reply's spine. expect(findNode(nodeByRef($screen, 'thread-reply-r3'), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow'))->not->toBeNull(); - $screen->tap('thread-reply-r3')->assertNavigatedTo('/log/commits/r3'); + $screen->tap('thread-reply-r3')->assertNoNavigation()->assertSet('id', 'r3'); Native::visit('/log/commits/c2') ->tap('replies-c2') @@ -792,7 +793,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(app(Account::class)->user())->toBeNull(); }); -it('reloads when you come back from a reply you deleted', function () { +it('moves back to the parent when you delete a reply the page moved to', function () { $replyDeleted = false; Http::fake(function (Request $request) use (&$replyDeleted) { @@ -809,15 +810,15 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): }; }); - $reply = Native::visit('/log/commits/c2') + // The page moved to the reply, so deleting it moves the page back to its parent, asked for again. + Native::visit('/log/commits/c2') ->tap('replies-c2') ->assertSee('Soon gone') ->tap('thread-reply-r1') - ->follow() + ->assertSet('id', 'r1') ->call('deleteCommit', 'r1') - ->assertWentBack(); - - $reply->goBack() + ->assertNoNavigation() + ->assertSet('id', 'c2') ->assertSee('Parent') ->assertDontSee('Soon gone') ->assertSee('No replies yet.'); @@ -952,7 +953,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $screen = Native::visit('/log/commits/c2', platform: 'ios'); $scroller = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'scroll_view'); - $page = $scroller['children'][0]['children']; + $page = $scroller['children']; // The clearance is the last thing on the page, under the last reply: the fade, the bar and the home indicator. $bar = 24 + Display::ComposerFadeHeight + Display::ComposerBoxBarHeight + 34; diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 9d208b7a..14a41698 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -52,8 +52,8 @@ function fakeDeepThread(): void $screen->tap('replies-r2')->assertDontSee('Reply at depth 3'); finishRefreshes($screen)->assertDontSee('Reply at depth 5'); - // Tapping a reply itself still opens its page. - $screen->tap('thread-reply-r2')->assertNavigatedTo('/log/commits/r2'); + // Tapping a reply itself moves the page to it. + $screen->tap('thread-reply-r2')->assertNoNavigation()->assertSet('id', 'r2'); }); it('steps replies in up to the third level, and lines deeper ones up under it saying who they answer', function () { @@ -75,3 +75,57 @@ function fakeDeepThread(): void $screen->assertSee('replying to @alan')->assertSee('replying to @edsger'); }); + +it('moves the page to a reply in its tree rather than pushing another, keeping what was open', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + foreach (range(1, 3) as $depth) { + $screen->tap("replies-r{$depth}"); + } + + $screen->tap('thread-reply-r3') + ->assertNoNavigation() + ->assertSet('id', 'r3') + ->assertSet('scrollTarget', 3); + + // The reply is the commit the page is on, under the commits above it, with its replies showing at once. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c2', 'commit-r1', 'commit-r2', 'focused-commit', 'thread-reply-r4', 'reply-bar-clearance']) + ->and(nodeByRef($screen, 'thread-scroll')['props']['auto_scroll_to'])->toBe(3); + + // Back up at the top, the reply the page was on is still open under its parents. + $screen->tap('commit-c2') + ->assertNoNavigation() + ->assertSet('id', 'c2') + ->assertSet('scrollTarget', 0) + ->assertSee('Reply at depth 4'); + + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'thread-reply-r3', 'thread-reply-r4', 'reply-bar-clearance']); +}); + +it('answers a reply in the tree from the bar, on the same page', function () { + fakeDeepThread(); + + Native::visit('/log/commits/c2', ['replies' => true]) + ->call('replyTo', 'r1') + ->assertNoNavigation() + ->assertSet('id', 'r1') + ->assertSet('focusReply', true); +}); + +it('still pushes a page for a commit outside the tree', function () { + fakeDeepThread(); + + Native::visit('/log/commits/c2', ['replies' => true]) + ->call('openCommit', 'q9') + ->assertNavigatedTo('/log/commits/q9'); +}); + +it('opens at the top with no scroll asked for until the page moves', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + expect(nodeByRef($screen, 'thread-scroll')['props'] ?? [])->not->toHaveKey('auto_scroll_to'); +}); diff --git a/tests/Feature/Screens/RelatedCommitsTest.php b/tests/Feature/Screens/RelatedCommitsTest.php index d493ad73..b3f9a350 100644 --- a/tests/Feature/Screens/RelatedCommitsTest.php +++ b/tests/Feature/Screens/RelatedCommitsTest.php @@ -85,7 +85,7 @@ function openRelated(TestableComponent $screen): TestableComponent ->assertSee('Next match') ->assertSee('Third match'); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) ->and(childRefs($screen, 'related-commits'))->toBe(['related-commits-toggle', 'related-c9', 'related-c3', 'related-c7']) ->and(childRefs($screen, 'related-c9'))->toBe(['commit-c9']) ->and(railNode($screen, 'commit-c9'))->toBe('avatar') @@ -255,13 +255,13 @@ function openRelated(TestableComponent $screen): TestableComponent $relatedLine = fn (): float => (float) (nodeByRef($screen, 'related-commits')['props']['border_t'] ?? 0); // Shut, the commit sits right on the section, whose line is the only one. - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'related-commits', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'related-commits', 'reply-bar-clearance']) ->and($commitLine())->toBe(0.0) ->and($relatedLine())->toBe(1.0); // Open, the last reply ends with no hairline of its own, so the section's line is still the only one. $screen->tap('replies-c1')->assertSee('A reply'); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) ->and($commitLine())->toBe(0.0) ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-end-r1'))->toBeNull() ->and($relatedLine())->toBe(1.0); diff --git a/tests/Feature/Screens/SelfThreadTest.php b/tests/Feature/Screens/SelfThreadTest.php index 6c3b53fd..b78153cc 100644 --- a/tests/Feature/Screens/SelfThreadTest.php +++ b/tests/Feature/Screens/SelfThreadTest.php @@ -63,7 +63,7 @@ function serveSelfThread(array $commit, array $ancestors, array $replies): void */ function selfThreadRows(TestableComponent $screen): array { - return array_values(array_filter(childRefs($screen, 'thread-page'), fn (?string $ref): bool => $ref !== 'reply-bar-clearance')); + return array_values(array_filter(childRefs($screen, 'thread-scroll'), fn (?string $ref): bool => $ref !== 'reply-bar-clearance')); } /** diff --git a/tests/Feature/Screens/SeriesTest.php b/tests/Feature/Screens/SeriesTest.php index ad0ff31a..cd6027f9 100644 --- a/tests/Feature/Screens/SeriesTest.php +++ b/tests/Feature/Screens/SeriesTest.php @@ -131,7 +131,8 @@ function railRunsOn(TestableComponent $screen, string $ref): bool ->and(railRunsOn($screen, 'focused-commit'))->toBeTrue() ->and(railRunsOn($screen, 'commit-p3'))->toBeFalse(); - $screen->tap('commit-p3')->assertNavigatedTo('/log/commits/p3'); + // A part in the tree moves the page to it rather than pushing another. + $screen->tap('commit-p3')->assertNoNavigation()->assertSet('id', 'p3'); }); it('puts a part\'s replies under it, above the later parts, as on the web', function () { From 10cca475869305352f4e9d6cd7b4c3f5e76619ef Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 03:05:46 +0000 Subject: [PATCH 19/30] Animate the commit page's move to another commit in its tree The scroll view now has animate-layout, so the rows the page keeps slide to their new places and the ones it adds or drops fade, and auto-scroll-animated, so the first move animates too. The focused commit is keyed commit-, as it is among the commits above it, so moving up the tree slides that row rather than redrawing it. Going back to a row the scroll view already went to used to mount the scroll view again, which would make every row new. It now passes a new auto-scroll-token instead. These need NativePHP/mobile-air#736 and NativePHP/mobile-ui#225. Without them the move jumps, as before, and asking for the same row twice in a row doesn't scroll. The test that reads the new props skips until vendor has them (Tests\Support\LayoutAnimation). Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 19 +++++---- .../views/native/commit-detail.blade.php | 10 +++-- .../native/partials/commit-row.blade.php | 2 +- tests/Feature/Screens/NestedRepliesTest.php | 41 +++++++++++++++++++ tests/Support/LayoutAnimation.php | 25 +++++++++++ 5 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 tests/Support/LayoutAnimation.php diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 2eb2380f..5f58d4c4 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -252,6 +252,12 @@ class CommitDetail extends NativeComponent */ public ?int $scrollTarget = null; + /** + * Counts the moves refocus() made. The scroll view takes it as its auto-scroll-token, so asking for the same row + * as last time (going back to the top twice) scrolls again rather than doing nothing. + */ + public int $scrollRequest = 0; + /** * The commit the page opened on, before tapping others in its tree moved it (see refocus()). */ @@ -473,15 +479,10 @@ private function refocus(string $id): bool $this->takeReplyDraft(); $this->error = null; - // The commit's row is the one after its ancestors. A request the scroll view already went to does nothing, - // so going back to the top a second time mounts it again, at the top. - $target = count($this->ancestors); - - if ($target === $this->scrollTarget) { - $this->scrollKey++; - } - - $this->scrollTarget = $target; + // The commit's row is the one after its ancestors. A new token asks again even when that's the row the + // scroll view went to last time. The scroll view keeps its key, so its rows slide to their new places. + $this->scrollTarget = count($this->ancestors); + $this->scrollRequest++; $this->forgetRefreshes(); $this->revalidate(); $this->followThread(); diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index fd7b2a75..3b111325 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -9,10 +9,14 @@ {{-- Each row is a child of the scroll view itself, so it can bring one into view: the commit the page is on, after - tapping another commit in the tree moves the page to it (see CommitDetail::refocus() and $scrollTarget). The - first move jumps and later ones animate, as auto-scroll-to does on both platforms. + tapping another commit in the tree moves the page to it (see CommitDetail::refocus() and $scrollTarget). Every + move animates (auto-scroll-animated), and $scrollRequest as the token makes asking for the same row again scroll + again. With animate-layout the rows the page keeps slide to their new places, and the ones it adds or drops + fade. That needs the scroll view's key, and each row's, to stay the same across the move: the focused commit + is keyed commit-, as the commits above it are. These need NativePHP/mobile-air#736 and + NativePHP/mobile-ui#225; without them the move jumps and a repeat of the same row doesn't scroll. --}} - + @if (! $commit && $error === null) diff --git a/resources/views/native/partials/commit-row.blade.php b/resources/views/native/partials/commit-row.blade.php index 209350f2..528a20d1 100644 --- a/resources/views/native/partials/commit-row.blade.php +++ b/resources/views/native/partials/commit-row.blade.php @@ -13,7 +13,7 @@ @if ($commit->isDeleted()) @include('native.partials.commit-tombstone') @elseif ($focused) - + @include('native.partials.commit-row-content') @else diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 14a41698..d94e12a8 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -3,6 +3,7 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Native\Mobile\Testing\Native; +use Tests\Support\LayoutAnimation; beforeEach(function () { config(['devnull.url' => 'http://devnull.test']); @@ -129,3 +130,43 @@ function fakeDeepThread(): void expect(nodeByRef($screen, 'thread-scroll')['props'] ?? [])->not->toHaveKey('auto_scroll_to'); }); + +it('keeps the commit row and the scroll view the same nodes when the page moves', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $screen->tap('replies-r1'); + $screen->tap('thread-reply-r2'); + $scroller = nodeByRef($screen, 'thread-scroll')['id']; + $ancestor = nodeByRef($screen, 'commit-c2')['id']; + + // The commit the page moves to keeps the node it had above the focus, so its row slides into place. The scroll + // view keeps its node too: a new one would make every row in it new. + $screen->tap('commit-c2')->assertSet('id', 'c2'); + + expect(nodeByRef($screen, 'focused-commit')['id'])->toBe($ancestor) + ->and(nodeByRef($screen, 'thread-scroll')['id'])->toBe($scroller); +}); + +it('animates the move and asks again for a row it went to before', function () { + LayoutAnimation::skipUnlessSupported(); + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $props = fn (): array => nodeByRef($screen, 'thread-scroll')['props']; + + expect($props())->toHaveKey('animate_layout', true) + ->and($props())->toHaveKey('auto_scroll_animated', true) + ->and($props())->toHaveKey('auto_scroll_token', '0'); + + $screen->tap('replies-r1'); + $screen->tap('thread-reply-r1')->assertSet('scrollTarget', 1); + $screen->tap('commit-c2')->assertSet('scrollTarget', 0); + $first = $props()['auto_scroll_token']; + $screen->tap('thread-reply-r1'); + $screen->tap('commit-c2')->assertSet('scrollTarget', 0); + + // The same row as two moves ago, under a new token, so the scroll view goes back to it. + expect($props()['auto_scroll_to'])->toBe(0) + ->and($props()['auto_scroll_token'])->not->toBe($first); +}); diff --git a/tests/Support/LayoutAnimation.php b/tests/Support/LayoutAnimation.php new file mode 100644 index 00000000..155686c8 --- /dev/null +++ b/tests/Support/LayoutAnimation.php @@ -0,0 +1,25 @@ +markTestSkipped('Needs a mobile-air with layout animation (NativePHP/mobile-air#736)'); + } + } +} From 5c5d26b78fa34bdac63cc23eb8578b0f98ba3ba8 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 03:13:16 +0000 Subject: [PATCH 20/30] Move the commit page's short hash to the top right of the commit It sat under the commit's text. Now it ends the row with the name, handle and time, pushed right by a spacer, in the same size and ink. Only the focused commit shows a hash, so no other rows change. Co-Authored-By: Claude Opus 5.5 --- .../native/partials/commit-row-content.blade.php | 11 ++++++----- tests/Feature/Screens/CommitDetailTest.php | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 94482f11..382e6c66 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -11,7 +11,7 @@ row is fixed here, so they meet it on both platforms. On a commit page the commit it's about ($focused) is the main thing: a larger name and body in full ink, its time, - which tapped says when in your timezone, its hash, and its replies behind a toggle in its action row. The commits around it ($muted) step back: + which tapped says when in your timezone, its hash at the top right, and its replies behind a toggle in its action row. The commits around it ($muted) step back: smaller and in muted ink, with a smaller avatar and action row. They still open their own pages. A commit in a thread its author wrote as replies to themselves wears its place in it ($threadPosition, "2/5"), and @@ -75,6 +75,11 @@ @unless ($commit->isApproved()) @include('native.partials.status-chip', ['status' => $commit->status]) @endunless + @if ($focused) + {{-- Its short hash, at the top right of the row, as the web has it at the right of the page's header. --}} + + {{ $commit->shortHash }} + @endif @if ($commit->parent?->isDeleted()) @@ -103,10 +108,6 @@ @include('native.partials.show-thread') @endif - @if ($focused) - {{ $commit->shortHash }} - @endif - @if ($commit->isStaged()) @elseif ($focused) @include('native.partials.commit-actions', [ diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index cf451876..267e1a7d 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -287,7 +287,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->and(findNode($screen->tree(), fn (array $node): bool => str_starts_with((string) ($node['ref'] ?? ''), 'thread-end-')))->toBeNull(); }); -it('shows the short hash under the focused commit, without the full date', function () { +it('shows the short hash at the top right of the focused commit, without the full date', function () { fakeThread(['created_at' => '2026-10-14T20:13:05Z']); $screen = Native::visit('/log/commits/c2') @@ -295,8 +295,13 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertDontSee('+0000'); $hash = nodeByRef($screen, 'focused-hash'); + // The row with the name, the handle and the time, with a spacer pushing the hash to its end. + $nameRow = findNode(nodeByRef($screen, 'focused-commit'), fn (array $node): bool => ($node['type'] ?? null) === 'row' && in_array('focused-time', array_map(fn (array $child): ?string => $child['ref'] ?? null, $node['children'] ?? []), true)); + $children = $nameRow['children'] ?? []; - expect($hash['text'] ?? $hash['props']['text'] ?? null)->toBe('c2'); + expect($hash['text'] ?? $hash['props']['text'] ?? null)->toBe('c2') + ->and($children[array_key_last($children)]['ref'] ?? null)->toBe('focused-hash') + ->and($children[count($children) - 2]['type'] ?? null)->toBe('spacer'); }); it('says when the commit was made, in your timezone, when its time is tapped, as the web does on hover', function (?string $chosen, string $toast) { From 16f38391eaae72e01148ecf7aeeec628d8ad8ed4 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 03:13:16 +0000 Subject: [PATCH 21/30] Open the replies of the commits above the commit in place The commits above the one the page is on keep their "N replies" button, and it now opens their replies in place under them, like the commit's and every reply's, instead of moving the page there. The reply on the line down to the commit is left out of the list and of the count, since it already shows below. Closing an ancestor's replies leaves the replies of the commits on the line open (drawsOnItsOwn in ExpandsThreads). After a move the scroll target counts the rows opened above the commit, and opening or closing them later doesn't scroll. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 64 ++++++++++++-- .../Concerns/ExpandsThreads.php | 15 +++- .../views/native/commit-detail.blade.php | 20 +++-- tests/Feature/Screens/NestedRepliesTest.php | 85 +++++++++++++++++++ 4 files changed, 171 insertions(+), 13 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 5f58d4c4..b35ce09c 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -19,6 +19,7 @@ use App\Devnull\RowCache; use App\Devnull\SelfThread; use App\Devnull\Stash; +use App\Devnull\ThreadRows; use App\Devnull\Timeline; use App\Devnull\Toasts; use App\Icons\Lucide; @@ -51,7 +52,8 @@ * * Each reply's own replies open in place under it, and theirs under them, as * deep as they go, as the web's commit page does (see ExpandsThreads and - * App\Devnull\ThreadRows). + * App\Devnull\ThreadRows). So do the commits above the commit, less the one + * on the line down to it, which already shows (see ancestorThreads()). * * Tapping a commit in the tree, above the commit, below it or among the * replies at any depth, moves this page to it rather than pushing another @@ -479,9 +481,10 @@ private function refocus(string $id): bool $this->takeReplyDraft(); $this->error = null; - // The commit's row is the one after its ancestors. A new token asks again even when that's the row the - // scroll view went to last time. The scroll view keeps its key, so its rows slide to their new places. - $this->scrollTarget = count($this->ancestors); + // The commit's row is the one after its ancestors and the replies opened under them. A new token asks again + // even when that's the row the scroll view went to last time. The scroll view keeps its key, so its rows + // slide to their new places. Opening an ancestor's replies later leaves the target be, so it doesn't scroll. + $this->scrollTarget = count($this->ancestors) + array_sum(array_map(fn (array $thread): int => count($thread['rows']), $this->ancestorThreads($this->ancestors))); $this->scrollRequest++; $this->forgetRefreshes(); $this->revalidate(); @@ -594,9 +597,59 @@ private function ancestorsInTree(Commit $target): ?array return [...array_slice($line, 0, array_search($parentId, $lineIds, true) + 1), ...$between]; } + /** + * The replies of each commit above the commit, as its "› N replies" opens them in place under it, the same as a + * reply's (see ExpandsThreads), and how many that button counts. The commit under it on the page, when that's + * one of its replies, is left out of both: it's already showing, on the line down to the commit. The web leaves + * out only the part of a self-thread that carries it on (see SelfThread), so there the rest of the line would + * show twice. devnull's count already leaves that part out. + * + * @param list $above + * @return array, reply: Commit|null}>}> + */ + private function ancestorThreads(array $above): array + { + if ($this->commit === null) { + return []; + } + + $line = [...$above, $this->commit]; + $threads = []; + + foreach ($above as $index => $ancestor) { + $next = $line[$index + 1]; + $onLine = $next->parentId === $ancestor->id && $ancestor->continuationId !== $next->id; + $replies = array_values(array_filter($this->threads[$ancestor->id] ?? [], fn (Commit $reply): bool => $reply->id !== $next->id)); + + $threads[$ancestor->id] = [ + 'count' => max(0, $ancestor->repliesCount - ($onLine ? 1 : 0)), + 'rows' => $ancestor->isDeleted() || $replies === [] ? [] : ThreadRows::under( + $ancestor, + [...$this->threads, $ancestor->id => $replies], + $this->threadCursors, + $this->threadShown, + $ancestor->lane(), + opensInPlace: PHP_INT_MAX, + onPage: true, + ), + ]; + } + + return $threads; + } + + /** + * The commits on the page's line, above the commit and the commit itself, draw rows of their own, so closing the + * replies they're among leaves their own replies open. + */ + protected function drawsOnItsOwn(string $id): bool + { + return $id === $this->id || in_array($id, array_map(fn (Commit $ancestor): string => $ancestor->id, $this->ancestors), true); + } + /** * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. Under a reply, at any - * depth, it opens that reply's replies in place under it (see ExpandsThreads). + * depth, or a commit above the commit, it opens that one's replies in place under it (see ExpandsThreads). */ public function toggleReplies(string $id = ''): void { @@ -1211,6 +1264,7 @@ public function render(): View laneAbove: $earlier === [] ? null : end($earlier)->lane(), ), 'relatedRows' => Timeline::thread($this->related), + 'ancestorThreads' => $this->ancestorThreads($above), 'earlierCount' => $this->commit === null ? 0 : count($earlier), 'earlierLane' => $earlier === [] ? null : end($earlier)->lane(), 'replyCount' => max($this->commit->repliesCount ?? 0, count($replies)), diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 8a31f599..cbd8830d 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -267,7 +267,9 @@ private function keepCursor(string $id, ?string $cursor): void private function closeThread(string $id): void { foreach ($this->threads[$id] ?? [] as $reply) { - $this->closeThread($reply->id); + if (! $this->drawsOnItsOwn($reply->id)) { + $this->closeThread($reply->id); + } } unset($this->threads[$id], $this->threadCursors[$id], $this->threadShown[$id]); @@ -360,7 +362,7 @@ private function rowsInside(string $id): array $rows = $this->rowsOf($id, $this->shownReplies($id)); foreach ($this->shownReplies($id) as $reply) { - if (array_key_exists($reply->id, $this->threads)) { + if (array_key_exists($reply->id, $this->threads) && ! $this->drawsOnItsOwn($reply->id)) { $rows = [...$rows, ...$this->rowsInside($reply->id)]; } } @@ -368,6 +370,15 @@ private function rowsInside(string $id): array return $rows; } + /** + * Whether the screen draws a reply in a row of its own rather than in the thread it's in, so its own replies + * stay open when that thread closes. A commit page draws the commits on its line that way (see CommitDetail). + */ + protected function drawsOnItsOwn(string $id): bool + { + return false; + } + /** * @return list */ diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 3b111325..9cbd7358 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -31,7 +31,8 @@ their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything - around the commit is muted. Tapping any commit in the tree moves the page to it rather than pushing + around the commit is muted, and the commits above it open their other replies in place under them, as the + commit does. Tapping any commit in the tree moves the page to it rather than pushing another (see CommitDetail::refocus()). Every reply's own replies open in place under it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). @@ -57,12 +58,14 @@ @php($isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id) @php($hasThread = $isFocused && $repliesShown && $replies !== []) @php($partThread = $isLastPart && $lastPartReplies !== []) + @php($aboveThread = $ancestorThreads[$row->commit->id] ?? null) + @php($aboveOpen = ($aboveThread['rows'] ?? []) !== []) @include('native.partials.commit-row', [ 'commit' => $row->commit, 'previousLane' => $row->previousLane, 'continuesRun' => $row->continuesRun, - 'continuesNext' => $isFocused ? ! $loop->last : null, - 'threadBelow' => $hasThread || $partThread, + 'continuesNext' => $isFocused || $aboveOpen ? ! $loop->last : null, + 'threadBelow' => $hasThread || $partThread || $aboveOpen, 'repliesBelow' => $partThread, 'focused' => $isFocused, 'muted' => ! $isFocused, @@ -71,15 +74,20 @@ 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), 'threadPosition' => $threadPositions[$row->commit->id] ?? null, 'showsThread' => false, - 'expandable' => false, + 'expandable' => $aboveThread !== null, + 'repliesCount' => $aboveThread['count'] ?? null, ]) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) @endif - {{-- The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). --}} - @php($pageThread = match (true) { $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) + {{-- + The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). + A commit above the commit opens its replies in place under it too, all but the one on the line down + to the commit, which already shows (see CommitDetail::ancestorThreads()). + --}} + @php($pageThread = match (true) { $aboveThread !== null => $aboveThread['rows'], $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) @foreach ($pageThread as $threadRow) @if ($threadRow['reply'] === null) @include($threadRow['partial'], $threadRow['data']) diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index d94e12a8..75a30403 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -170,3 +170,88 @@ function fakeDeepThread(): void expect($props()['auto_scroll_to'])->toBe(0) ->and($props()['auto_scroll_token'])->not->toBe($first); }); + +/** + * A commit page for c2, which answers c1. c1 has another reply, x1, and x1 has one of its own, x2. c2 has one reply, r1. + */ +function fakeAncestorThread(): void +{ + $person = fn (string $handle, int $lane): array => userJson(['handle' => $handle, 'name' => ucfirst($handle), 'lane' => $lane]); + $c1 = commitJson(['id' => 'c1', 'body' => 'The commit above', 'replies_count' => 2, 'author' => $person('ada', 1)]); + $c2 = commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 1, 'author' => $person('grace', 2)]); + $x1 = replyJson(['id' => 'x1', 'parent_id' => 'c1', 'body' => 'Another reply above', 'replies_count' => 1, 'author' => $person('linus', 4)]); + $x2 = replyJson(['id' => 'x2', 'parent_id' => 'x1', 'body' => 'A reply to the other reply', 'author' => $person('alan', 5)]); + $r1 = replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'A reply below', 'author' => $person('ken', 6)]); + + Http::fake(function (Request $request) use ($c1, $c2, $x1, $x2, $r1) { + $path = parse_url($request->url(), PHP_URL_PATH); + + return match ($path) { + '/api/v1/commits/c2' => Http::response(commitPageJson($c2, [$c1])), + '/api/v1/commits/c1' => Http::response(commitPageJson($c1)), + '/api/v1/commits/r1' => Http::response(commitPageJson($r1, [$c1, $c2])), + '/api/v1/commits/c1/related', '/api/v1/commits/c2/related', '/api/v1/commits/r1/related' => Http::response(['data' => []]), + '/api/v1/commits/c1/replies' => Http::response(pageJson([$c2, $x1])), + '/api/v1/commits/c2/replies' => Http::response(pageJson([$r1])), + '/api/v1/commits/x1/replies' => Http::response(pageJson([$x2])), + '/api/v1/commits/r1/replies', '/api/v1/commits/x2/replies' => Http::response(pageJson([])), + default => Http::response(['message' => 'No fake.'], 404), + }; + }); +} + +it('opens the replies of a commit above the commit in place, leaving out the one on the way down', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + // c1 has two replies, and one of them is the commit the page is on, so its button counts the other. + expect(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply'); + + $screen->tap('replies-c1')->assertNoNavigation()->assertSee('Another reply above'); + + // The other reply opens under c1, and the commit the page is on shows once, as the commit. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); + + // Its replies open in place too, at any depth. + $screen->tap('replies-x1')->assertNoNavigation()->assertSee('A reply to the other reply'); + + $screen->tap('replies-c1'); + finishRefreshes($screen)->assertDontSee('Another reply above')->assertDontSee('A reply to the other reply'); + + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); +}); + +it('counts the replies opened above the commit in the row it scrolls to after a move', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $screen->tap('replies-c1'); + $screen->tap('thread-reply-r1')->assertSet('id', 'r1')->assertSet('scrollTarget', 3); + + // r1 has no replies, so "No replies yet" follows it. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'commit-c2', 'focused-commit', null, 'reply-bar-clearance']) + ->and(rendersRef($screen, 'replies-c2'))->toBeFalse(); + + // Closing the replies of a commit above it later doesn't scroll the page again. + $screen->tap('replies-c1')->assertSet('scrollTarget', 3); +}); + +it('keeps the replies of the commits on the line open when the replies of one above them close', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $screen->tap('replies-r1'); + $screen->tap('replies-r2'); + $screen->tap('thread-reply-r3')->assertSet('id', 'r3'); + + // Each commit above r3 has one reply, the one on the way down, so none of them has a replies button. + expect(rendersRef($screen, 'replies-c2'))->toBeFalse() + ->and(rendersRef($screen, 'replies-r1'))->toBeFalse(); + + // Closing c2's replies, which the page kept open from when it was on c2, leaves r1's and r2's be. + $screen->call('toggleReplies', 'c2'); + finishRefreshes($screen); + + expect($screen->get('threads'))->toHaveKeys(['r1', 'r2']); +}); From d204792fdb664e8097bd3e2de6b79d53486180a5 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 09:17:13 +0000 Subject: [PATCH 22/30] Fold the replies of the commits above the commit on every move The commits above the one the page is on now start with their replies folded behind "N replies", whether the page opened on a reply or moved down to one. Before, moving down kept the replies of the commit the page left open under it, and any opened on a commit above stayed open. Moving up, the commit the page moves to shows its replies with the way back down opened, as before. The scroll target after a move is just the ancestor count again, since nothing is open above the commit then. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 23 ++++++--- .../views/native/commit-detail.blade.php | 2 +- tests/Feature/Screens/NestedRepliesTest.php | 51 +++++++++++++++---- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index b35ce09c..7e9292d5 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -421,9 +421,11 @@ public function replyTo(string $id): void * the author's thread or series, or a reply at any depth. It becomes the * commit the page is about, with what's above it as its ancestors and its * replies showing below, all from what the page already has, so nothing - * goes blank, and devnull is asked for the rest behind it. Replies opened - * in place stay open, and the commit the page was on keeps its replies, so - * moving up shows where you came from opened under its parent. + * goes blank, and devnull is asked for the rest behind it. The commits + * above it start with their replies folded, showing only "› N replies", + * as when the page opens on a reply. Moving up, the commit the page was on + * keeps its replies, and so do the commits between, so the commit you + * move to shows the way back down to where you came from opened under it. * * The page stays one screen: Back still leaves it, as Simon asked, rather * than stepping back through the commits it moved to. The scroll view @@ -448,7 +450,7 @@ private function refocus(string $id): bool $line = [...$this->ancestors, $this->commit]; $below = array_slice($line, count($ancestors) + 1); - // What the page was on keeps its replies, opened in place, for when it's back in the tree. + // What the page was on keeps its replies, opened in place, when it ends up below the commit the page moves to. if ($this->repliesShown && $this->repliesLoaded && $this->replies !== []) { $this->threads[$this->id] = array_values(array_filter($this->replies, fn (Commit $reply): bool => ! $reply->isStaged())); $this->keepCursor($this->id, $this->repliesCursor); @@ -471,6 +473,11 @@ private function refocus(string $id): bool $this->threadLimit = SelfThread::PerPage; $this->takeOwnReplies($id); + // The commits above it fold their replies, the commit the page was on among them when the page moved down. + foreach ($this->ancestors as $ancestor) { + $this->closeThread($ancestor->id); + } + if (($thread = $this->cached($this->threadPath())) !== null) { $this->takeCommitThread($thread); } @@ -481,10 +488,10 @@ private function refocus(string $id): bool $this->takeReplyDraft(); $this->error = null; - // The commit's row is the one after its ancestors and the replies opened under them. A new token asks again - // even when that's the row the scroll view went to last time. The scroll view keeps its key, so its rows - // slide to their new places. Opening an ancestor's replies later leaves the target be, so it doesn't scroll. - $this->scrollTarget = count($this->ancestors) + array_sum(array_map(fn (array $thread): int => count($thread['rows']), $this->ancestorThreads($this->ancestors))); + // The commit's row is the one after its ancestors, whose replies are folded. A new token asks again even when + // that's the row the scroll view went to last time. The scroll view keeps its key, so its rows slide to their + // new places. Opening an ancestor's replies later leaves the target be, so it doesn't scroll. + $this->scrollTarget = count($this->ancestors); $this->scrollRequest++; $this->forgetRefreshes(); $this->revalidate(); diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 9cbd7358..7d28ab78 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -32,7 +32,7 @@ above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything around the commit is muted, and the commits above it open their other replies in place under them, as the - commit does. Tapping any commit in the tree moves the page to it rather than pushing + commit does, from their "N replies", which starts folded, even after the page moves. Tapping any commit in the tree moves the page to it rather than pushing another (see CommitDetail::refocus()). Every reply's own replies open in place under it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 75a30403..1e9e4c79 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -222,19 +222,43 @@ function fakeAncestorThread(): void expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); }); -it('counts the replies opened above the commit in the row it scrolls to after a move', function () { +it('folds the replies of the commits above when the page moves down to a reply', function () { fakeAncestorThread(); $screen = Native::visit('/log/commits/c2', ['replies' => true]); - $screen->tap('replies-c1'); - $screen->tap('thread-reply-r1')->assertSet('id', 'r1')->assertSet('scrollTarget', 3); + $screen->tap('replies-c1')->assertSee('Another reply above'); + $screen->tap('thread-reply-r1')->assertSet('id', 'r1')->assertSet('scrollTarget', 2)->assertDontSee('Another reply above'); - // r1 has no replies, so "No replies yet" follows it. - expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'commit-c2', 'focused-commit', null, 'reply-bar-clearance']) + // c1 is back to its button, still leaving out c2 on the way down. r1 has no replies, so "No replies yet" follows it. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'commit-c2', 'focused-commit', null, 'reply-bar-clearance']) + ->and(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply') ->and(rendersRef($screen, 'replies-c2'))->toBeFalse(); - // Closing the replies of a commit above it later doesn't scroll the page again. - $screen->tap('replies-c1')->assertSet('scrollTarget', 3); + // Opening them again later doesn't scroll the page. + $screen->tap('replies-c1')->assertSee('Another reply above')->assertSet('scrollTarget', 2); +}); + +it('folds the replies of the commit the page was on when it moves down to one of them, and opens them again moving back up', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/c1', ['replies' => true])->assertSee('Another reply above'); + $screen->tap('thread-reply-c2')->assertNoNavigation()->assertSet('id', 'c2')->assertDontSee('Another reply above'); + + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']) + ->and(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply'); + + // Back up on c1, its replies show as the commit's do, with c2's still open under it. + $screen->tap('commit-c1')->assertSet('id', 'c1')->assertSee('Another reply above')->assertSee('A reply below'); +}); + +it('opens on a reply with the replies of the commits above it folded', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/r1')->call('showEarlier')->assertDontSee('Another reply above'); + + expect(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply') + ->and(rendersRef($screen, 'replies-c2'))->toBeFalse() + ->and($screen->get('threads'))->toBe([]); }); it('keeps the replies of the commits on the line open when the replies of one above them close', function () { @@ -245,13 +269,18 @@ function fakeAncestorThread(): void $screen->tap('replies-r2'); $screen->tap('thread-reply-r3')->assertSet('id', 'r3'); - // Each commit above r3 has one reply, the one on the way down, so none of them has a replies button. - expect(rendersRef($screen, 'replies-c2'))->toBeFalse() + // The commits above r3 fold their replies. Each has one, the one on the way down, so none of them has a button. + expect($screen->get('threads'))->toBe([]) + ->and(rendersRef($screen, 'replies-c2'))->toBeFalse() ->and(rendersRef($screen, 'replies-r1'))->toBeFalse(); - // Closing c2's replies, which the page kept open from when it was on c2, leaves r1's and r2's be. + // Opened again, closing c2's replies leaves r1's be, since r1 draws a row of its own. + $screen->call('toggleReplies', 'c2'); + $screen->call('toggleReplies', 'r1'); + expect($screen->get('threads'))->toHaveKeys(['c2', 'r1']); + $screen->call('toggleReplies', 'c2'); finishRefreshes($screen); - expect($screen->get('threads'))->toHaveKeys(['r1', 'r2']); + expect($screen->get('threads'))->toHaveKey('r1')->not->toHaveKey('c2'); }); From 056deb8f608883051342db1e28783eb81b24573d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 09:17:13 +0000 Subject: [PATCH 23/30] Hold the mention suggestions to six rows and scroll the rest With more than six people and organizations to suggest, the rows sit in a scroll view six rows tall inside the suggestions, so the list can't push the field and the bar's buttons down under the keyboard. Six or fewer are drawn as before, as tall as their rows. The slot around the list keeps its place, so the field's row doesn't move among its siblings. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Display.php | 8 ++++++ .../partials/mention-suggestions.blade.php | 17 +++++++++++-- tests/Feature/Screens/CommitMentionsTest.php | 25 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index 3897e633..82f003d9 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -27,6 +27,14 @@ final class Display public const int ReplyBarDescriptionHeight = 100; + /** + * The people to mention above a field (see partials/mention-suggestions): a row's height, and how many rows show + * before the rest scroll inside the list. + */ + public const int MentionRowHeight = 44; + + public const int MentionRowsShown = 6; + /** * A bar holding partials/composer-box with one line of draft, as drawn on an iPhone: the bar's padding, then the * field over the row of tools and the send button. diff --git a/resources/views/native/partials/mention-suggestions.blade.php b/resources/views/native/partials/mention-suggestions.blade.php index 1f0a4e29..5ed8a646 100644 --- a/resources/views/native/partials/mention-suggestions.blade.php +++ b/resources/views/native/partials/mention-suggestions.blade.php @@ -4,15 +4,25 @@ colour. $heading, when there is one, heads them: Members for a bare "@" in an org thread. A tap puts "@handle " in the field in place of what was typed. Above a bar's field on iOS they sit on glass of their own, like the reply strip; $class says otherwise. + + At most six rows show (Display::MentionRowsShown). Past that the rows scroll inside a list that tall, so the list + never pushes the field and the bar's buttons down under the keyboard. Fewer, and it's only as tall as its rows. + Each row is then exactly a row's height (Display::MentionRowHeight), so six fill the list. The rows sit inside the + list's own column, so the slot around it, and the field's row beside that, stay where they are. --}} @if (($mention['field'] ?? null) === $field && ($mentionPeople !== [] || $mentionOrganizations !== [])) @if ($heading ?? null) {{ $heading }} @endif - @foreach ([...array_map(fn ($user) => [$user, true], $mentionPeople), ...array_map(fn ($user) => [$user, false], $mentionOrganizations)] as [$user, $person]) + @php($mentionRows = [...array_map(fn ($user) => [$user, true], $mentionPeople), ...array_map(fn ($user) => [$user, false], $mentionOrganizations)]) + @php($mentionScrolls = count($mentionRows) > \App\Devnull\Display::MentionRowsShown) + @if ($mentionScrolls) + + @endif + @foreach ($mentionRows as [$user, $person]) - + @include('native.partials.avatar', ['user' => $user, 'size' => 28]) {{ $user->name }} @@ -26,5 +36,8 @@ @endforeach + @if ($mentionScrolls) + + @endif @endif diff --git a/tests/Feature/Screens/CommitMentionsTest.php b/tests/Feature/Screens/CommitMentionsTest.php index 4d35f14f..b728402d 100644 --- a/tests/Feature/Screens/CommitMentionsTest.php +++ b/tests/Feature/Screens/CommitMentionsTest.php @@ -95,6 +95,31 @@ function mentionsComposer(bool $quoting = false): TestableComponent ->assertMissingElement('column', fn (array $node): bool => ($node['ref'] ?? null) === 'mention-suggestions'); }); +it('holds the reply bar\'s suggestions to six rows and scrolls the rest inside the list', function () { + $people = array_map(fn (int $n): array => userJson(['id' => "u{$n}", 'handle' => "ada{$n}", 'name' => "Ada {$n}"]), range(1, 7)); + $screen = mentionsCommitPage([['data' => $people, 'organizations' => [['handle' => 'adaptive', 'name' => 'Adaptive', 'avatar_url' => null]]]]) + ->input('reply-input', '@ada', 4); + + // Eight rows, so they sit in a list six rows tall, which scrolls. The slot and the field's row around it stay put. + $list = nodeByRef($screen, 'mention-scroll'); + + expect(childRefs($screen, 'mention-suggestions'))->toBe(['mention-scroll']) + ->and($list['type'])->toBe('scroll_view') + ->and($list['layout']['height'] ?? null)->toEqual(6 * 44) + ->and(childRefs($screen, 'mention-scroll'))->toBe([...array_map(fn (int $n): string => "mention-ada{$n}", range(1, 7)), 'mention-adaptive']) + ->and(childRefs($screen, 'reply-rows'))->toBe(['reply-mention-slot', 'reply-photos-slot', 'reply-row']); + + $screen->tap('mention-ada7')->assertSet('reply', '@ada7 '); +}); + +it('leaves six suggestions or fewer as tall as their rows, with no list to scroll', function () { + $people = array_map(fn (int $n): array => userJson(['id' => "u{$n}", 'handle' => "ada{$n}", 'name' => "Ada {$n}"]), range(1, 6)); + $screen = mentionsCommitPage([['data' => $people]])->input('reply-input', '@ada', 4); + + expect(childRefs($screen, 'mention-suggestions'))->toBe(array_map(fn (int $n): string => "mention-ada{$n}", range(1, 6))) + ->and(rendersRef($screen, 'mention-scroll'))->toBeFalse(); +}); + it('puts the person picked in the reply where the @ was, with the caret after them', function () { $screen = mentionsCommitPage() ->input('reply-input', 'cc @adfor review', 6) From f9832b557bb57d5fe2e1f6c8aa2a3aa3ca22ba13 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 10:59:08 +0000 Subject: [PATCH 24/30] Let a caller that scrolls the mention list itself turn off its inner scroll The composer sheet in #198 sizes its mention list and scrolls it. With more than six rows the partial's own six-row scroll view sat inside that one, so a short phone showed two scroll bars. 'scrolls' => false draws every row as tall as it is with no scroll view inside. It defaults to true, so the reply bar and the conversation bar keep their six-row list. Co-Authored-By: Claude Opus 5.5 --- .../partials/mention-suggestions.blade.php | 6 ++- .../Screens/MentionSuggestionsTest.php | 54 +++++++++++++++++++ .../views/mention-suggestions.blade.php | 4 ++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/Screens/MentionSuggestionsTest.php create mode 100644 tests/Fixtures/views/mention-suggestions.blade.php diff --git a/resources/views/native/partials/mention-suggestions.blade.php b/resources/views/native/partials/mention-suggestions.blade.php index 5ed8a646..93dbf174 100644 --- a/resources/views/native/partials/mention-suggestions.blade.php +++ b/resources/views/native/partials/mention-suggestions.blade.php @@ -8,7 +8,9 @@ At most six rows show (Display::MentionRowsShown). Past that the rows scroll inside a list that tall, so the list never pushes the field and the bar's buttons down under the keyboard. Fewer, and it's only as tall as its rows. Each row is then exactly a row's height (Display::MentionRowHeight), so six fill the list. The rows sit inside the - list's own column, so the slot around it, and the field's row beside that, stay where they are. + list's own column, so the slot around it, and the field's row beside that, stay where they are. A caller that + scrolls the list itself (the composer sheet sizes and scrolls its own) passes 'scrolls' => false, and every row is + drawn as tall as it is, with no scroll view inside. --}} @if (($mention['field'] ?? null) === $field && ($mentionPeople !== [] || $mentionOrganizations !== [])) @@ -16,7 +18,7 @@ {{ $heading }} @endif @php($mentionRows = [...array_map(fn ($user) => [$user, true], $mentionPeople), ...array_map(fn ($user) => [$user, false], $mentionOrganizations)]) - @php($mentionScrolls = count($mentionRows) > \App\Devnull\Display::MentionRowsShown) + @php($mentionScrolls = ($scrolls ?? true) && count($mentionRows) > \App\Devnull\Display::MentionRowsShown) @if ($mentionScrolls) @endif diff --git a/tests/Feature/Screens/MentionSuggestionsTest.php b/tests/Feature/Screens/MentionSuggestionsTest.php new file mode 100644 index 00000000..04a7eb65 --- /dev/null +++ b/tests/Feature/Screens/MentionSuggestionsTest.php @@ -0,0 +1,54 @@ + 'body', 'start' => 0, 'query' => 'ada', 'text' => '@ada']; + + /** @var list */ + public array $mentionPeople = []; + + /** @var list */ + public array $mentionOrganizations = []; + + /** @var array */ + public array $options = []; + + public function mount(int $rows = 8, array $options = []): void + { + $this->mentionPeople = array_map(fn (int $n): User => User::fromArray(userJson(['id' => "u{$n}", 'handle' => "ada{$n}", 'name' => "Ada {$n}"])), range(1, $rows)); + $this->options = $options; + } + + public function pickMention(string $field, string $username): void {} + + public function render(): View + { + return view('fixtures::mention-suggestions', ['options' => $this->options]); + } +} + +beforeEach(fn () => view()->addNamespace('fixtures', base_path('tests/Fixtures/views'))); + +it('scrolls more than six rows inside the list by default', function () { + $screen = Native::test(MentionSuggestionsFixture::class, ['rows' => 8]); + + expect(childRefs($screen, 'mention-suggestions'))->toBe(['mention-scroll']) + ->and(nodeByRef($screen, 'mention-scroll')['type'])->toBe('scroll_view'); +}); + +it('draws every row with no scroll view inside when the caller scrolls the list itself', function () { + $screen = Native::test(MentionSuggestionsFixture::class, ['rows' => 8, 'options' => ['scrolls' => false]]); + + expect(rendersRef($screen, 'mention-scroll'))->toBeFalse() + ->and(childRefs($screen, 'mention-suggestions'))->toBe(array_map(fn (int $n): string => "mention-ada{$n}", range(1, 8))) + ->and(nodeByRef($screen, 'mention-ada8')['children'][0]['layout']['height'] ?? null)->toBeNull(); +}); diff --git a/tests/Fixtures/views/mention-suggestions.blade.php b/tests/Fixtures/views/mention-suggestions.blade.php new file mode 100644 index 00000000..d29b0fbf --- /dev/null +++ b/tests/Fixtures/views/mention-suggestions.blade.php @@ -0,0 +1,4 @@ +{{-- The mention list alone, for MentionSuggestionsTest: the partial with whatever options the test passes. --}} + + @include('native.partials.mention-suggestions', ['field' => 'body', ...$options]) + From 89bff8d99142f2081904b012c69b0634af6144fa Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 10:24:54 +0000 Subject: [PATCH 25/30] Count the replies of the commits above from their own pages devnull sends the ancestors on a commit's page without replies_count, so a commit above only showed its "N replies" if the page had moved through it before. Each ancestor that shows now reads its count from its own page, kept from before at once and asked for behind, once per refresh. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Data/Commit.php | 8 +++ app/NativeComponents/CommitDetail.php | 64 ++++++++++++++++++- .../Feature/Screens/CommitDetailCacheTest.php | 3 +- tests/Feature/Screens/NestedRepliesTest.php | 49 ++++++++++++++ 4 files changed, 122 insertions(+), 2 deletions(-) diff --git a/app/Devnull/Data/Commit.php b/app/Devnull/Data/Commit.php index 28b52bbf..4a2f608d 100644 --- a/app/Devnull/Data/Commit.php +++ b/app/Devnull/Data/Commit.php @@ -169,6 +169,14 @@ public function withMorePasteis(int $change): self return new self(...[...get_object_vars($this), 'pasteisCount' => max(0, $this->pasteisCount + $change)]); } + /** + * This commit with the count of replies its own page gives, for a copy that came without one. + */ + public function withRepliesCount(int $repliesCount): self + { + return new self(...[...get_object_vars($this), 'repliesCount' => max(0, $repliesCount)]); + } + public function withPinned(bool $isPinned): self { return new self(...[...get_object_vars($this), 'isPinned' => $isPinned]); diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 7e9292d5..9dd73f7f 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -279,6 +279,13 @@ class CommitDetail extends NativeComponent */ protected bool $forceFullFrames = true; + /** + * The commits above whose own page was asked for their count since the page last asked devnull again. + * + * @var list + */ + protected array $countedAncestors = []; + public function mount(): void { $this->openedId = $this->id; @@ -335,6 +342,7 @@ public function load(): void protected function revalidate(): void { + $this->countedAncestors = []; $this->refresh($this->threadPath(), [], fn (array $json) => $this->takeCommitThread($json)); $this->refresh($this->threadPath().'/replies', [], fn (array $json) => $this->takeReplies($json)); $this->refresh($this->threadPath().'/related', [], fn (array $json) => $this->takeRelated($json), quiet: true, failed: function (): void { @@ -347,6 +355,7 @@ protected function revalidate(): void } $this->refreshThreads(); + $this->countAncestorReplies(); } protected function showsContent(): bool @@ -360,6 +369,7 @@ protected function showsContent(): bool public function showEarlier(): void { $this->earlierShown = true; + $this->countAncestorReplies(); } /** @@ -1121,9 +1131,61 @@ private function takeCommitThread(array $json): void $this->commit = $thread->commit; $this->ancestors = $thread->ancestors; $this->series = $thread->series; + $this->countAncestorReplies(); $this->followThread(); } + /** + * The commits above the commit that show: its parent, or every one once "↑ N earlier commits" opened them. + * + * @return list + */ + private function shownAncestors(): array + { + return $this->earlierShown ? $this->ancestors : array_slice($this->ancestors, -1); + } + + /** + * devnull sends the commits above the commit without their counts, so on their own a commit above never shows + * its "› N replies". Each one showing takes its count from its own page instead: kept from before at once, and + * asked for behind. That also keeps its page, so tapping it moves there with nothing blank. + */ + private function countAncestorReplies(): void + { + foreach ($this->shownAncestors() as $ancestor) { + if ($ancestor->isStaged() || $ancestor->isDeleted()) { + continue; + } + + $id = $ancestor->id; + $path = 'commits/'.rawurlencode($id); + + if (($kept = $this->cached($path)) !== null) { + $this->takeAncestorCount($id, $kept); + } + + // The commit's page landing draws its ancestors again, and they were asked for once already. + if (! in_array($id, $this->countedAncestors, true)) { + $this->countedAncestors[] = $id; + $this->refresh($path, [], fn (array $json) => $this->takeAncestorCount($id, $json), quiet: true); + } + } + } + + /** + * @param array $json + */ + private function takeAncestorCount(string $id, array $json): void + { + $page = CommitThread::fromArray($json)->commit; + + if ($page->id !== $id) { + return; + } + + $this->ancestors = array_map(fn (Commit $ancestor): Commit => $ancestor->id === $id ? $ancestor->withRepliesCount($page->repliesCount) : $ancestor, $this->ancestors); + } + /** * A fresh first page of replies. Pages loaded after it stay, past what it holds. * @@ -1249,7 +1311,7 @@ public function isOwn(): bool public function render(): View { $earlier = $this->earlierShown ? [] : array_slice($this->ancestors, 0, -1); - $above = $this->earlierShown ? $this->ancestors : array_slice($this->ancestors, -1); + $above = $this->shownAncestors(); $viewer = $this->me(); $this->replyRows ??= new RowCache; $this->replyRows->startFrame(); diff --git a/tests/Feature/Screens/CommitDetailCacheTest.php b/tests/Feature/Screens/CommitDetailCacheTest.php index 1694cf61..afc3e075 100644 --- a/tests/Feature/Screens/CommitDetailCacheTest.php +++ b/tests/Feature/Screens/CommitDetailCacheTest.php @@ -48,7 +48,8 @@ function serveThread(): void finishRefreshes($screen)->assertSee('A compiler'); - expect(count(Http::recorded()))->toBe(3); + // The commit, its replies, what's related, and c0's own page for how many replies it has. + expect(count(Http::recorded()))->toBe(4); }); it('opens from a row on what the row knew, then fills in the replies and what it replies to', function () { diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 1e9e4c79..2c9024d9 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -284,3 +284,52 @@ function fakeAncestorThread(): void expect($screen->get('threads'))->toHaveKey('r1')->not->toHaveKey('c2'); }); + +/** + * c3 answers c2, which answers c1, shaped like devnull's API: the ancestors on c3's page come without their counts, + * since CommitAncestorsQuery doesn't load them. Only a commit's own page says how many replies it has. c2 has two + * besides c3, and c1 has one besides c2. Neither page was opened before. + */ +function fakeUncountedAncestors(): void +{ + $person = fn (string $handle, int $lane): array => userJson(['handle' => $handle, 'name' => ucfirst($handle), 'lane' => $lane]); + $uncounted = fn (array $commit): array => array_diff_key($commit, array_flip(['replies_count', 'stars_count'])); + $c1 = commitJson(['id' => 'c1', 'body' => 'The first commit', 'replies_count' => 2, 'author' => $person('ada', 1)]); + $c2 = commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The commit above', 'replies_count' => 3, 'author' => $person('grace', 2)]); + $c3 = commitJson(['id' => 'c3', 'parent_id' => 'c2', 'body' => 'The focused commit', 'author' => $person('ken', 3)]); + $y1 = replyJson(['id' => 'y1', 'parent_id' => 'c1', 'body' => 'Another reply to the first', 'author' => $person('linus', 4)]); + $x1 = replyJson(['id' => 'x1', 'parent_id' => 'c2', 'body' => 'Another reply above', 'author' => $person('alan', 5)]); + $x2 = replyJson(['id' => 'x2', 'parent_id' => 'c2', 'body' => 'One more reply above', 'author' => $person('edsger', 6)]); + + Http::fake(function (Request $request) use ($uncounted, $c1, $c2, $c3, $x1, $x2, $y1) { + return match (parse_url($request->url(), PHP_URL_PATH)) { + '/api/v1/commits/c3' => Http::response(commitPageJson($c3, [$uncounted($c1), $uncounted($c2)])), + '/api/v1/commits/c2' => Http::response(commitPageJson($c2, [$uncounted($c1)])), + '/api/v1/commits/c1' => Http::response(commitPageJson($c1)), + '/api/v1/commits/c1/related', '/api/v1/commits/c2/related', '/api/v1/commits/c3/related' => Http::response(['data' => []]), + '/api/v1/commits/c1/replies' => Http::response(pageJson([$c2, $y1])), + '/api/v1/commits/c2/replies' => Http::response(pageJson([$c3, $x1, $x2])), + '/api/v1/commits/c3/replies', '/api/v1/commits/x1/replies', '/api/v1/commits/x2/replies', '/api/v1/commits/y1/replies' => Http::response(pageJson([])), + default => Http::response(['message' => 'No fake.'], 404), + }; + }); +} + +it('shows the folded replies of a commit above that was never opened, from that commit\'s own page', function () { + fakeUncountedAncestors(); + + $screen = finishRefreshes(Native::visit('/log/commits/c3')); + + // c2's page says it has three replies, and c3 is one of them, on the way down. + expect(nodeByRef($screen, 'replies-c2')['props']['a11y_label'] ?? null)->toBe('2 replies') + ->and($screen->get('threads'))->toBe([]); + + $screen->tap('replies-c2')->assertNoNavigation()->assertSee('Another reply above')->assertSee('One more reply above'); + + // The earlier commits get theirs once they show. + expect(rendersRef($screen, 'replies-c1'))->toBeFalse(); + + finishRefreshes($screen->call('showEarlier')); + + expect(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply'); +}); From f3e4adb086d81a0e78cac60dc0caf337b2062e7a Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 10:25:30 +0000 Subject: [PATCH 26/30] Keep the asked-for ancestor counts with the ancestors Moves the new property away from $forceFullFrames, which the phone build removes, so the two merge cleanly. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 9dd73f7f..7b2d94e9 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -127,6 +127,13 @@ class CommitDetail extends NativeComponent /** @var list */ public array $ancestors = []; + /** + * The commits above whose own page was asked for their count since the page last asked devnull again. + * + * @var list + */ + protected array $countedAncestors = []; + /** * The parts of its series after the commit, in order. * @@ -279,13 +286,6 @@ class CommitDetail extends NativeComponent */ protected bool $forceFullFrames = true; - /** - * The commits above whose own page was asked for their count since the page last asked devnull again. - * - * @var list - */ - protected array $countedAncestors = []; - public function mount(): void { $this->openedId = $this->id; From 820a1756e1b20ced863bf17fc8c087d6f56acf76 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 12:23:46 +0000 Subject: [PATCH 27/30] Suggest every matching org member in Remotes, scrolling past six Org threads ranked members on the phone and kept the first six, so the list never scrolled. Now every member who matches is listed, and the list scrolls past six rows like the reply bar's. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Concerns/SuggestsMentions.php | 6 +++--- tests/Feature/Screens/ConversationTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/NativeComponents/Concerns/SuggestsMentions.php b/app/NativeComponents/Concerns/SuggestsMentions.php index 9166bcf4..138b82ec 100644 --- a/app/NativeComponents/Concerns/SuggestsMentions.php +++ b/app/NativeComponents/Concerns/SuggestsMentions.php @@ -31,7 +31,6 @@ trait SuggestsMentions */ public const string MentionBeforeCaret = '/(?:^|[^\p{L}\p{N}_.\/@-])@([A-Za-z0-9][A-Za-z0-9-]{0,38}|)$/u'; - public const int MaxMentionSuggestions = 6; /** * The "@handle" the caret is after: the field it's in, where its "@" is, in code points, what follows it, and the @@ -199,7 +198,8 @@ private static function mentionEnd(array $mention, string $text): ?int } /** - * An org's members to suggest for what's typed after the "@", best first. + * An org's members to suggest for what's typed after the "@", best first. All of them: past six the list scrolls + * (see partials/mention-suggestions), as the reply bar's does. * * @param list $members * @return list @@ -236,6 +236,6 @@ private static function rankMembers(array $members, string $query, ?User $viewer usort($ranked, fn (array $a, array $b): int => [$a['tier'], ! $a['followed'], $a['user']->username] <=> [$b['tier'], ! $b['followed'], $b['user']->username]); - return array_column(array_slice($ranked, 0, self::MaxMentionSuggestions), 'user'); + return array_column($ranked, 'user'); } } diff --git a/tests/Feature/Screens/ConversationTest.php b/tests/Feature/Screens/ConversationTest.php index 4a22b9cc..40806fa2 100644 --- a/tests/Feature/Screens/ConversationTest.php +++ b/tests/Feature/Screens/ConversationTest.php @@ -1281,7 +1281,7 @@ function orgWithMembers(array $people): array ->assertMissingElement('column', fn (array $node): bool => ($node['ref'] ?? null) === 'mention-suggestions'); }); -it('filters org members as the web ranks them: exact handle, handle prefix, name prefix, then the rest, followed first, six at most', function () { +it('filters org members as the web ranks them: exact handle, handle prefix, name prefix, then the rest, followed first, all of them in a list that scrolls past six', function () { serveOrgThread(orgWithMembers([ ['grace', 'Grace Hopper'], ['tobias', 'Ada Tobias'], @@ -1295,7 +1295,8 @@ function orgWithMembers(array $people): array $screen = finishRefreshes(Native::visit('/remotes/orgs/org-1'))->input('message-input', '@ADA', 4); - expect(childRefs($screen, 'mention-suggestions'))->toBe(['mention-ada', 'mention-adams', 'mention-adamant', 'mention-tobias', 'mention-bada', 'mention-cada']); + expect(childRefs($screen, 'mention-scroll'))->toBe(['mention-ada', 'mention-adams', 'mention-adamant', 'mention-tobias', 'mention-bada', 'mention-cada', 'mention-dada']) + ->and(nodeByRef($screen, 'mention-scroll')['layout']['height'])->toEqual(Display::MentionRowsShown * Display::MentionRowHeight); }); it('never suggests you, or a member devnull says not to, and suggests nothing in a thread with one person', function () { From b5ecbf738ec6c0ef3b5f107b5be7c80cf086b037 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 12:24:01 +0000 Subject: [PATCH 28/30] Tidy a blank line left by the last commit Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Concerns/SuggestsMentions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/NativeComponents/Concerns/SuggestsMentions.php b/app/NativeComponents/Concerns/SuggestsMentions.php index 138b82ec..4dd2f05e 100644 --- a/app/NativeComponents/Concerns/SuggestsMentions.php +++ b/app/NativeComponents/Concerns/SuggestsMentions.php @@ -31,7 +31,6 @@ trait SuggestsMentions */ public const string MentionBeforeCaret = '/(?:^|[^\p{L}\p{N}_.\/@-])@([A-Za-z0-9][A-Za-z0-9-]{0,38}|)$/u'; - /** * The "@handle" the caret is after: the field it's in, where its "@" is, in code points, what follows it, and the * field's text when the caret was there. Null while there's none. From 3b582bb6e5af45fb7f6d3015dee8be268e442990 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 12:32:33 +0000 Subject: [PATCH 29/30] Scroll to a reply you just sent on a commit page Sending a reply from the bar or the composer sheet now scrolls the page to the staged reply. The scroll view counts its direct children, so the page's rows are now listed by CommitDetail::pageRows() and the view draws exactly that list. The component looks the staged reply up in the same list, so the index can't drift from what's drawn. When devnull's reply replaces the staged one it lands on the same row, so the target and token stay put and the page doesn't move again. The one case where it moves is a reply to your own commit that becomes the next part of your thread; the page follows it there. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 150 ++++++++++++++++-- .../views/native/commit-detail.blade.php | 61 ++----- tests/Feature/Screens/ScrollToReplyTest.php | 129 +++++++++++++++ 3 files changed, 284 insertions(+), 56 deletions(-) create mode 100644 tests/Feature/Screens/ScrollToReplyTest.php diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 7b2d94e9..edcb88fa 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -80,7 +80,8 @@ * * A reply goes at once: the bar empties and the reply shows staged under the * commit while it goes to devnull from the outbox (see SyncsOutbox), then the - * real one takes its place. If devnull turns it down, it leaves, and what you + * real one takes its place. The page scrolls to it as it shows, and stays + * there when the real one comes (see scrollToRow()). If devnull turns it down, it leaves, and what you * wrote is back in the bar, or in the sheet with its photos. Edit, on the * toast of a reply or a quote turned down after you'd left, opens its commit * here with it ($data['edit']). @@ -256,17 +257,24 @@ class CommitDetail extends NativeComponent public int $scrollKey = 0; /** - * Which of the scroll view's rows it brings into view, the commit's, once tapping another commit in the tree - * moved the page to it (see refocus()). Null until then, so the page opens at the top as it always has. + * Which of the scroll view's rows it brings into view: the commit's, once tapping another commit in the tree + * moved the page to it (see refocus()), or the reply you just sent (see scrollToRow()). Null until one of those, + * so the page opens at the top as it always has. */ public ?int $scrollTarget = null; /** - * Counts the moves refocus() made. The scroll view takes it as its auto-scroll-token, so asking for the same row + * Counts the moves refocus() and scrollToRow() made. The scroll view takes it as its auto-scroll-token, so asking for the same row * as last time (going back to the top twice) scrolls again rather than doing nothing. */ public int $scrollRequest = 0; + /** + * The key of the row scrollToRow() brought into view last, so a reply you sent can be followed when devnull's + * takes its place (see showCommitWent()). + */ + private ?string $scrolledToRow = null; + /** * The commit the page opened on, before tapping others in its tree moved it (see refocus()). */ @@ -821,6 +829,7 @@ public function sendReply(): void $this->updatedReply(); $this->repliesShown = true; $this->keepStagedReplies(); + $this->scrollToRow('thread-reply-'.PendingWrite::stagedId($write->client_id)); $this->sendFromOutbox($write); } @@ -886,6 +895,7 @@ protected function showCommitted(Commit $commit): void $this->replyRestored = false; $this->repliesShown = true; $this->keepStagedReplies(); + $this->scrollToRow('thread-reply-'.$commit->id); } /** @@ -897,6 +907,31 @@ protected function showCommitWent(PendingWrite $write, Commit $commit): void $this->replies = array_map(fn (Commit $reply): Commit => $reply->id === $staged ? $commit : $reply, $this->replies); $this->followThread(); + $this->followSentReply('thread-reply-'.$staged, $commit); + } + + /** + * The page scrolled to a reply you sent, staged, and devnull's reply has taken its place. That's the same row, + * so the scroll view is left be. Only when the reply has moved, as the next part of your thread below the + * commit's replies, does the page follow it there. + */ + private function followSentReply(string $stagedKey, Commit $commit): void + { + if ($this->scrolledToRow !== $stagedKey) { + return; + } + + $keys = array_column($this->pageRows($this->viewData()), 'key'); + $at = array_search('thread-reply-'.$commit->id, $keys, true); + $at = $at === false ? array_search('commit-'.$commit->id, $keys, true) : $at; + + if ($at === false || $at === $this->scrollTarget) { + $this->scrolledToRow = null; + + return; + } + + $this->scrollToRow($keys[$at]); } /** @@ -1309,20 +1344,31 @@ public function isOwn(): bool } public function render(): View + { + $this->replyRows ??= new RowCache; + $this->replyRows->startFrame(); + $data = $this->viewData(); + + return view('native.commit-detail', [...$data, 'replyRows' => $this->replyRows, 'pageRows' => $this->pageRows($data)]); + } + + /** + * What the page's view draws from, besides the component's own properties. + * + * @return array + */ + private function viewData(): array { $earlier = $this->earlierShown ? [] : array_slice($this->ancestors, 0, -1); $above = $this->shownAncestors(); $viewer = $this->me(); - $this->replyRows ??= new RowCache; - $this->replyRows->startFrame(); $thread = $this->selfThread(); $parts = $thread->parts; $partsAbove = $this->commit === null ? 0 : SelfThread::above($this->ancestors, $this->commit, $this->repliesOf())[0]; $lastPart = $thread->hasEnded && $parts !== [] ? end($parts) : null; $replies = $this->commit === null ? $this->replies : SelfThread::others($this->commit, $this->replies); - return view('native.commit-detail', [ - 'replyRows' => $this->replyRows, + return [ 'myColour' => $this->myColour(), 'viewer' => $viewer, 'ownership' => $this->ownership(), @@ -1344,7 +1390,93 @@ public function render(): View 'lastPart' => $lastPart, 'lastPartReplies' => $lastPart === null ? [] : array_slice($this->partReplies[$lastPart->id] ?? [], 0, Client::RepliesPerPage), 'lastPartMore' => $lastPart !== null && (count($this->partReplies[$lastPart->id] ?? []) > Client::RepliesPerPage || in_array($lastPart->id, $this->partsWithMore, true)), - ]); + ]; + } + + /** + * The scroll view's rows from the top down to the end of the thread, in the order the view draws them, each one + * child of the scroll view: "↑ N earlier commits", then each commit with what hangs under it, its replies opened + * in place and theirs (see App\Devnull\ThreadRows). The view draws exactly these, so a row's place here is its + * place among the scroll view's children, which auto-scroll-to counts in (see scrollToRow()). What comes after + * the thread, the related commits and the room for the reply bar, the view draws on its own. + * + * @param array $data What viewData() gave. + * @return list, reply: Commit|null}> + */ + private function pageRows(array $data): array + { + $commit = $this->commit; + $rows = $data['rows']; + $replies = $data['replies']; + $lastPart = $data['lastPart']; + $noReplies = $commit !== null && $data['replyCount'] === 0 && $this->repliesLoaded && $this->series === [] && $data['threadParts'] === []; + $relatedBelow = $commit !== null && $this->related !== [] && ! $noReplies; + $pageRows = []; + + if ($data['earlierCount'] > 0) { + $pageRows[] = ['key' => 'earlier-commits', 'partial' => 'native.partials.earlier-commits', 'data' => ['count' => $data['earlierCount'], 'lane' => $data['earlierLane']], 'reply' => null]; + } + + foreach ($rows as $index => $row) { + $last = $index === array_key_last($rows); + $isFocused = $row->commit->id === $commit?->id; + $isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id; + $hasThread = $isFocused && $this->repliesShown && $replies !== []; + $partThread = $isLastPart && $data['lastPartReplies'] !== []; + $aboveThread = $data['ancestorThreads'][$row->commit->id] ?? null; + $aboveOpen = ($aboveThread['rows'] ?? []) !== []; + + $pageRows[] = ['key' => 'commit-'.$row->commit->id, 'partial' => 'native.partials.commit-row', 'reply' => null, 'data' => [ + 'commit' => $row->commit, + 'previousLane' => $row->previousLane, + 'continuesRun' => $row->continuesRun, + 'continuesNext' => $isFocused || $aboveOpen ? ! $last : null, + 'threadBelow' => $hasThread || $partThread || $aboveOpen, + 'repliesBelow' => $partThread, + 'focused' => $isFocused, + 'muted' => ! $isFocused, + 'seriesExpanded' => true, + 'withTail' => ! $last || $data['threadMore'], + 'hairline' => ! ($last && $relatedBelow && ! $data['threadMore']), + 'threadPosition' => $data['threadPositions'][$row->commit->id] ?? null, + 'showsThread' => false, + 'expandable' => $aboveThread !== null, + 'repliesCount' => $aboveThread['count'] ?? null, + ]]; + + if ($isFocused && $this->repliesShown && $replies === [] && ! $this->repliesLoaded && $this->error === null) { + $pageRows[] = ['key' => 'loading-replies', 'partial' => null, 'data' => [], 'reply' => null]; + } + + // The replies, and theirs opened in place under them as deep as they go. A commit above the commit opens + // its replies in place under it too, all but the one on the line down to the commit, which already shows + // (see ancestorThreads()). + array_push($pageRows, ...match (true) { + $aboveThread !== null => $aboveThread['rows'], + $hasThread => ThreadRows::under($commit, [...$this->threads, $commit->id => $replies], array_filter([...$this->threadCursors, $commit->id => $this->repliesCursor]), $this->threadShown, $last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), + $partThread => ThreadRows::under($lastPart, [...$this->threads, $lastPart->id => $data['lastPartReplies']], array_filter([...$this->threadCursors, $lastPart->id => $data['lastPartMore'] ? 'more' : null]), $this->threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), + default => [], + }); + } + + return $pageRows; + } + + /** + * Brings the row keyed $key into view, animated, under a new token so it goes even when that's the row it went to + * last time. Nothing happens for a row the page doesn't draw. + */ + private function scrollToRow(string $key): void + { + $at = array_search($key, array_column($this->pageRows($this->viewData()), 'key'), true); + + if ($at === false) { + return; + } + + $this->scrollTarget = $at; + $this->scrollRequest++; + $this->scrolledToRow = $key; } /** diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 7d28ab78..ff7bf65b 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -41,61 +41,28 @@ the web reads it (see SelfThread): each part wears its place ("2/5"), ten show at a time with "Show more of this thread" under them, and the replies of the last part hang under it as the commit's do. --}} - @if ($earlierCount > 0) - @include('native.partials.earlier-commits', ['count' => $earlierCount, 'lane' => $earlierLane]) - @endif - {{-- - Related commits start with a full-width line of their own (see partials/related-commits). The last row - above them leaves out its hairline, which runs from the text's edge, so the two don't stack up into a - line and a half. Replies end with no hairline on a commit page, and "No replies yet" keeps the commit's. + The rows down to the end of the thread come from CommitDetail::pageRows(), each one child of the scroll + view, in the order it lists them, so the place it gives a row is the row auto-scroll-to brings into + view: the reply you just sent, say (see CommitDetail::scrollToRow()). A row drawn here and not there + would put every row below it one out. Related commits start with a full-width line of their own (see + partials/related-commits), so the last row above them leaves out its hairline, which runs from the + text's edge, and the two don't stack up into a line and a half. Replies end with no hairline on a + commit page, and "No replies yet" keeps the commit's. --}} @php($noReplies = $commit && $replyCount === 0 && $repliesLoaded && $series === [] && $threadParts === []) - @php($relatedBelow = $commit && $related !== [] && ! $noReplies) - @foreach ($rows as $row) - @php($isFocused = $row->commit->id === $commit?->id) - @php($isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id) - @php($hasThread = $isFocused && $repliesShown && $replies !== []) - @php($partThread = $isLastPart && $lastPartReplies !== []) - @php($aboveThread = $ancestorThreads[$row->commit->id] ?? null) - @php($aboveOpen = ($aboveThread['rows'] ?? []) !== []) - @include('native.partials.commit-row', [ - 'commit' => $row->commit, - 'previousLane' => $row->previousLane, - 'continuesRun' => $row->continuesRun, - 'continuesNext' => $isFocused || $aboveOpen ? ! $loop->last : null, - 'threadBelow' => $hasThread || $partThread || $aboveOpen, - 'repliesBelow' => $partThread, - 'focused' => $isFocused, - 'muted' => ! $isFocused, - 'seriesExpanded' => true, - 'withTail' => ! $loop->last || $threadMore, - 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), - 'threadPosition' => $threadPositions[$row->commit->id] ?? null, - 'showsThread' => false, - 'expandable' => $aboveThread !== null, - 'repliesCount' => $aboveThread['count'] ?? null, - ]) - @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) + @foreach ($pageRows as $pageRow) + @if ($pageRow['key'] === 'loading-replies') + @elseif ($pageRow['reply'] === null) + @include($pageRow['partial'], $pageRow['data']) + @else + @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) + @php($replyRows->include('reply-'.$pageRow['reply']->id, \App\Devnull\RowInputs::for($pageRow['reply'], $rowScope), $pageRow['partial'], $pageRow['data'], $rowScope)) @endif - {{-- - The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). - A commit above the commit opens its replies in place under it too, all but the one on the line down - to the commit, which already shows (see CommitDetail::ancestorThreads()). - --}} - @php($pageThread = match (true) { $aboveThread !== null => $aboveThread['rows'], $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) - @foreach ($pageThread as $threadRow) - @if ($threadRow['reply'] === null) - @include($threadRow['partial'], $threadRow['data']) - @else - @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$threadRow['reply']->id, \App\Devnull\RowInputs::for($threadRow['reply'], $rowScope), $threadRow['partial'], $threadRow['data'], $rowScope)) - @endif - @endforeach @endforeach @if ($threadMore && $threadParts !== []) diff --git a/tests/Feature/Screens/ScrollToReplyTest.php b/tests/Feature/Screens/ScrollToReplyTest.php new file mode 100644 index 00000000..be04ecf7 --- /dev/null +++ b/tests/Feature/Screens/ScrollToReplyTest.php @@ -0,0 +1,129 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * A commit page for c2, under c1 and c0, with a first page of ten replies and more after them. r1 has a reply of + * its own, n1. Everything is kept from before, so the page shows it at once and holds its refreshes, the reply + * you post among them, until the test lets them go. + * + * @param array $commit + */ +function fakeLongThread(array $commit = [], array $posted = []): void +{ + holdRefreshes(); + + $grace = userJson(['handle' => 'grace', 'name' => 'Grace']); + $c0 = commitJson(['id' => 'c0', 'body' => 'The root commit', 'author' => userJson(['handle' => 'ada', 'name' => 'Ada'])]); + $c1 = commitJson(['id' => 'c1', 'parent_id' => 'c0', 'body' => 'The parent commit', 'author' => userJson(['handle' => 'linus', 'name' => 'Linus'])]); + $c2 = commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 11, 'author' => $grace, ...$commit]); + $replies = array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}", 'replies_count' => $n === 1 ? 1 : 0]), range(1, 10)); + $repliesPage = pageJson($replies, 'page2', 'http://devnull.test/api/v1/commits/c2/replies'); + $nested = pageJson([replyJson(['id' => 'n1', 'parent_id' => 'r1', 'body' => 'A reply to the first reply', 'author' => userJson(['handle' => 'alan', 'name' => 'Alan'])])]); + + keep('commits/c2', commitPageJson($c2, [$c0, $c1])); + keep('commits/c2/replies', $repliesPage); + keep('commits/r1/replies', $nested); + + fakeApi([ + 'GET /api/v1/commits/c2' => [commitPageJson($c2, [$c0, $c1])], + 'GET /api/v1/commits/c2/replies' => [$repliesPage], + 'GET /api/v1/commits/c2/related' => [['data' => []]], + 'GET /api/v1/commits/r1/replies' => [$nested], + 'POST /api/v1/commits' => [['data' => commitJson(['id' => 'r99', 'parent_id' => 'c2', 'body' => 'My fresh reply', ...$posted])], 201], + ]); +} + +/** + * Where the scroll view is asked to go: the ref of the child at auto-scroll-to, and the request it's under, which + * the scroll view takes as its auto-scroll-token where mobile-ui has it. + * + * @return array{0: string|null, 1: int} + */ +function scrolledTo(TestableComponent $screen): array +{ + $index = nodeByRef($screen, 'thread-scroll')['props']['auto_scroll_to'] ?? -1; + + return [childRefs($screen, 'thread-scroll')[$index] ?? null, $screen->instance()->scrollRequest]; +} + +function stagedReplyId(TestableComponent $screen): string +{ + /** @var CommitDetail $page */ + $page = $screen->instance(); + + return collect($page->replies)->first(fn ($reply): bool => $reply->isStaged())->id; +} + +it('scrolls to a reply sent from the bar, under the commits above and past ten replies', function () { + fakeLongThread(); + + $screen = Native::visit('/log/commits/c2')->assertSet('scrollRequest', 0); + + $screen->input('reply-input', 'My fresh reply')->tap('send-reply')->assertSet('repliesShown', true); + + $staged = stagedReplyId($screen); + $children = childRefs($screen, 'thread-scroll'); + + expect($children)->toBe([ + 'earlier-commits', 'commit-c1', 'focused-commit', + ...array_map(fn (int $n): string => "thread-reply-r{$n}", range(1, 10)), + "thread-reply-{$staged}", null, 'reply-bar-clearance', + ]) + ->and($screen->instance()->scrollTarget)->toBe(array_search("thread-reply-{$staged}", $children, true)) + ->and(scrolledTo($screen))->toBe(["thread-reply-{$staged}", 1]); + + // devnull's reply takes the staged one's place, on the same row, and the page doesn't scroll again. + finishRefreshes($screen)->assertDontSee('staged'); + + expect(scrolledTo($screen))->toBe(['thread-reply-r99', 1]); +}); + +it('scrolls to a reply sent from the sheet, past replies opened in place under the ones before it', function () { + fakeLongThread(); + + $screen = Native::visit('/log/commits/c2') + ->tap('earlier-commits') + ->tap('replies-c2') + ->tap('replies-r1'); + + finishRefreshes($screen) + ->assertSee('A reply to the first reply') + ->assertSet('scrollRequest', 0); + + $screen->call('replyInSheet', 'c2')->input('sheet-body', 'My fresh reply')->tap('sheet-commit'); + + $staged = stagedReplyId($screen); + $children = childRefs($screen, 'thread-scroll'); + + expect(array_slice($children, 0, 5))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'thread-reply-r1', 'thread-reply-n1']) + ->and(scrolledTo($screen))->toBe(["thread-reply-{$staged}", 1]) + ->and($screen->instance()->scrollTarget)->toBe(14); + + finishRefreshes($screen); + + expect(scrolledTo($screen))->toBe(['thread-reply-r99', 1]); +}); + +it('follows a reply to your own commit when devnull has it carry your thread on', function () { + // The commit is yours, and so is the reply, so once devnull has it, it's the next part of your thread, below the + // commit's replies, rather than one of them. + fakeLongThread(commit: ['author' => userJson()]); + + $screen = Native::visit('/log/commits/c2'); + $screen->input('reply-input', 'My fresh reply')->tap('send-reply'); + + expect(scrolledTo($screen))->toBe(['thread-reply-'.stagedReplyId($screen), 1]); + + finishRefreshes($screen); + + // It moved a row down, past "Show more" under the replies, so the page goes after it. + expect(scrolledTo($screen))->toBe(['commit-r99', 2]); +}); From 942a74cc92b6a8dccd12af28ccb3fc5232494cca Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 13:12:48 +0000 Subject: [PATCH 30/30] Draw the hairline under replies that another commit follows A commit row gives its hairline up when its replies open under it, and on a commit page the last reply never drew one. So the replies of a commit above the focused one ran straight into the next commit with no line between them. The same happened under the focused commit when later parts of its series follow. ThreadRows::under() takes a hairline flag now. Ancestor threads always end on the line, and the focused commit's replies do when it isn't the last row. Replies at the foot of the page still end without one. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/ThreadRows.php | 14 ++++++++++---- app/NativeComponents/CommitDetail.php | 7 +++++-- .../views/native/partials/thread-reply.blade.php | 10 ++++++---- tests/Feature/Screens/NestedRepliesTest.php | 11 +++++++++-- tests/Feature/Screens/SeriesTest.php | 9 +++++++-- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php index 61e7042f..6d26c2b5 100644 --- a/app/Devnull/ThreadRows.php +++ b/app/Devnull/ThreadRows.php @@ -14,7 +14,8 @@ * Under the commit come its replies, each followed by its own replies when * they're open, and theirs, as deep as they go, with "Show more" after the * replies of a thread with more. Every row is a row of its own, and in a feed - * the last one closes the commit's row with its hairline. + * the last one closes the commit's row with its hairline. On a commit page it + * does only when another commit's row follows the thread. * * The thread hangs off the rail in dashes, as on the web: the first reply on * an elbow from the commit's rail, each later one on a short link from the @@ -66,8 +67,10 @@ final class ThreadRows * @param array $shown How many of each open thread's replies show. * @param int|string|null $railLane The commit's rail running on past its thread, when its author's run carries on below. * @param int $opensInPlace How deep a reply's replies button opens its replies in place rather than its page. - * @param bool $onPage On a commit page: replies muted, deleted ones open theirs in place, and no hairline under them. + * @param bool $onPage On a commit page: replies muted, deleted ones open theirs in place, and no hairline under them by default. * @param string|null $morePress What the commit's own "Show more" presses, when it isn't showMoreReplies. + * @param bool|null $hairline Whether the last row closes the thread with a hairline: in a feed it does, and on a + * commit page only when another commit's row comes next. * @return list, reply: Commit|null}> */ public static function under( @@ -79,6 +82,7 @@ public static function under( int $opensInPlace = 1, bool $onPage = false, ?string $morePress = null, + ?bool $hairline = null, ): array { $thread = fn (string $id): array => array_slice($threads[$id] ?? [], 0, $shown[$id] ?? null); $hasMore = fn (string $id): bool => isset($cursors[$id]) || count($thread($id)) < count($threads[$id] ?? []); @@ -89,6 +93,7 @@ public static function under( 'opensInPlace' => $opensInPlace, 'onPage' => $onPage, 'morePress' => $morePress, + 'hairline' => $hairline ?? ! $onPage, ]); if ($rows === []) { @@ -124,7 +129,7 @@ private static function lineAt(int $depth): float * @param list $spines Lines from further up running on past these rows. * @param Closure(string): list $thread * @param Closure(string): bool $hasMore - * @param array{railLane: int|string|null, opensInPlace: int, onPage: bool, morePress: string|null} $options + * @param array{railLane: int|string|null, opensInPlace: int, onPage: bool, morePress: string|null, hairline: bool} $options */ private static function branch(array &$rows, Commit $parent, int $depth, array $spines, Closure $thread, Closure $hasMore, array $options): void { @@ -160,6 +165,7 @@ private static function branch(array &$rows, Commit $parent, int $depth, array $ 'repliesInPlace' => $depth <= $options['opensInPlace'], 'muted' => $onPage, 'tombstones' => $onPage, + 'hairline' => $options['hairline'], ]); // The line that has to run on past this reply's own replies, to the next reply at this depth. @@ -182,7 +188,7 @@ private static function branch(array &$rows, Commit $parent, int $depth, array $ 'indent' => $indent, 'spines' => $spines, 'to' => $flattened && ! $parent->isDeleted() ? $parent->author->handle() : null, - 'hairline' => ! $onPage, + 'hairline' => $options['hairline'], ...($depth === 1 && $options['morePress'] !== null ? ['press' => $options['morePress']] : []), ]); } diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index edcb88fa..44239e01 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -656,6 +656,8 @@ private function ancestorThreads(array $above): array $ancestor->lane(), opensInPlace: PHP_INT_MAX, onPage: true, + // The next commit on the line follows them, so they end on the hairline the ancestor's row gave up. + hairline: true, ), ]; } @@ -1450,10 +1452,11 @@ private function pageRows(array $data): array // The replies, and theirs opened in place under them as deep as they go. A commit above the commit opens // its replies in place under it too, all but the one on the line down to the commit, which already shows - // (see ancestorThreads()). + // (see ancestorThreads()). Replies with another commit's row after them end on the hairline the row above + // them gave up; at the foot of the page they end on none. array_push($pageRows, ...match (true) { $aboveThread !== null => $aboveThread['rows'], - $hasThread => ThreadRows::under($commit, [...$this->threads, $commit->id => $replies], array_filter([...$this->threadCursors, $commit->id => $this->repliesCursor]), $this->threadShown, $last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), + $hasThread => ThreadRows::under($commit, [...$this->threads, $commit->id => $replies], array_filter([...$this->threadCursors, $commit->id => $this->repliesCursor]), $this->threadShown, $last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies', hairline: ! $last), $partThread => ThreadRows::under($lastPart, [...$this->threads, $lastPart->id => $data['lastPartReplies']], array_filter([...$this->threadCursors, $lastPart->id => $data['lastPartMore'] ? 'more' : null]), $this->threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [], }); diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index aba96aec..9e225242 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -6,8 +6,9 @@ ($previousLane), and a line on down from its avatar when another reply, its own replies, or "Show more", follows ($hasNext). $spines carry lines from further up on past it, and $railLane runs the commit's own rail on past, solid, when its author's run goes on below the thread (see thread-links). A deleted reply keeps its place with a - dashed ring. In a feed the $last closes the commit's row with its hairline. On a commit page nothing follows the - thread, so there's no hairline. + dashed ring. In a feed the $last closes the commit's row with its hairline. On a commit page it has one only when + another commit's row comes next ($hairline): under the replies of a commit above the commit, say, but not at the + foot of the page. Past the web's depth a reply is flattened: it lines up under the reply it answers, with no lines of its own ($links), and says who it answers on a line under its name ($replyingTo), as the web does. @@ -32,6 +33,7 @@ --}} @php($previousLane ??= null) @php($muted ??= false) +@php($hairline ??= ! $muted) @php($railLane ??= null) @php($indent ??= 0) @php($spines ??= []) @@ -66,7 +68,7 @@ @endif - @if ($last && ! $muted) + @if ($last && $hairline) @endif @@ -107,7 +109,7 @@ @endunless - @if ($last && ! $muted) + @if ($last && $hairline) @endif diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 2c9024d9..57fa618e 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -211,11 +211,18 @@ function fakeAncestorThread(): void $screen->tap('replies-c1')->assertNoNavigation()->assertSee('Another reply above'); // The other reply opens under c1, and the commit the page is on shows once, as the commit. - expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']) + // c1 gives up its hairline to its replies, and the last of them ends on it above the commit. The commit's own + // replies end the page, so they end on none. + ->and(rendersRef($screen, 'thread-end-x1'))->toBeTrue() + ->and(rendersRef($screen, 'thread-end-r1'))->toBeFalse(); - // Its replies open in place too, at any depth. + // Its replies open in place too, at any depth, and the hairline moves down under the last of them. $screen->tap('replies-x1')->assertNoNavigation()->assertSee('A reply to the other reply'); + expect(rendersRef($screen, 'thread-end-x2'))->toBeTrue() + ->and(rendersRef($screen, 'thread-end-x1'))->toBeFalse(); + $screen->tap('replies-c1'); finishRefreshes($screen)->assertDontSee('Another reply above')->assertDontSee('A reply to the other reply'); diff --git a/tests/Feature/Screens/SeriesTest.php b/tests/Feature/Screens/SeriesTest.php index cd6027f9..07829c2b 100644 --- a/tests/Feature/Screens/SeriesTest.php +++ b/tests/Feature/Screens/SeriesTest.php @@ -155,7 +155,10 @@ function railRunsOn(TestableComponent $screen, string $ref): bool ->assertSee('Agreed') ->assertDontSee('2 replies'); - expect(threadRows($screen))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'commit-p2', 'commit-p3']); + expect(threadRows($screen))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'commit-p2', 'commit-p3']) + // The focused part gave up its hairline to its replies, and the later parts follow, so the last reply ends on it. + ->and(rendersRef($screen, 'thread-end-r2'))->toBeTrue() + ->and(rendersRef($screen, 'thread-end-r1'))->toBeFalse(); }); it('keeps replies at the foot of the last part\'s page', function () { @@ -168,7 +171,9 @@ function railRunsOn(TestableComponent $screen, string $ref): bool ->assertSee('The end'); expect(threadRows($screen))->toBe(['commit-p1', 'commit-p2', 'focused-commit', 'thread-reply-r1']) - ->and(railRunsOn($screen, 'focused-commit'))->toBeFalse(); + ->and(railRunsOn($screen, 'focused-commit'))->toBeFalse() + // Nothing follows the replies at the foot of the page, so they end on no hairline. + ->and(rendersRef($screen, 'thread-end-r1'))->toBeFalse(); }); it('keeps a deleted part in its place in the series', function () {