Skip to content
Draft
13 changes: 9 additions & 4 deletions app/Devnull/RowInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ final class RowInputs
*/
public static function for(Commit $commit, array $scope): array
{
$viewer = $scope['viewer'] ?? app(Account::class)->user();
// The screen's own answer, null included: null is a real answer (signed out, pastéis mode off), so it's
// only read from the account when the screen gave none. Reading it again cost a query a row on a phone.
$viewer = array_key_exists('viewer', $scope) ? $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'] ?? [],
'pasteis' => array_key_exists('pasteis', $scope) ? $scope['pasteis'] : app(Account::class)->pasteis(),
// Only this commit's own drafts and unfolding: a draft started anywhere used to build every row again.
'stashed' => [in_array('quote-'.$commit->id, $scope['stashed'] ?? [], true), in_array('reply-'.$commit->id, $scope['stashed'] ?? [], true)],
'unfolded' => in_array($commit->id, $scope['unfolded'] ?? [], true),
'expandable' => isset($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),
Expand All @@ -41,6 +44,8 @@ public static function for(Commit $commit, array $scope): array
'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)],
// A poll's Vote button wears your lane colour.
'colour' => $scope['myColour'] ?? null,
];
}

Expand Down
4 changes: 3 additions & 1 deletion app/NativeComponents/CommitDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ class CommitDetail extends NativeComponent
public int $scrollKey = 0;

/**
* The replies from the last frame, so a render only builds the replies that changed, as the Log does its rows.
* The page's rows from the last frame, so a render only builds the ones that changed, as the Log does its rows:
* the commit, what it replies to and the rest of its series, its replies, and the related commits. Typing a reply
* draws a frame a few times a second, and each used to build every commit above the reply bar again.
*/
private ?RowCache $replyRows = null;

Expand Down
42 changes: 30 additions & 12 deletions app/NativeComponents/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ class Log extends NativeComponent
*/
private array $rowCaches = [];

/**
* The logs beside yours as they were last drawn, by log: what was kept
* for them, hashed, and what they showed (see previewState()).
*
* @var array<string, array{0: string, 1: array<string, mixed>}>
*/
private array $previews = [];

/**
* Which rows of each log are drawn.
*
Expand Down Expand Up @@ -431,26 +439,36 @@ private function openAfresh(): void
* A log you're not on: the first few commits kept for it, as it will
* open, or skeleton rows with nothing kept, or while it's two swipes away.
*
* Every frame draws it, so its commits are only made again when what's
* kept for them changes. Made afresh, they cost the frame as much again
* to lay out and to check against the rows kept for them.
*
* @return array<string, mixed>
*/
private function previewState(string $log): array
{
$beside = abs(array_search($log, self::Logs, true) - array_search($this->log, self::Logs, true)) === 1;
$json = $beside && ! $this->skeletonFrame ? $this->cached('log/'.$log) : null;
$kept = is_array($json['data'] ?? null) ? $json['data'] : [];
$page = $json === null ? null : Page::fromArray(['data' => array_slice($kept, 0, self::PreviewCommits)] + $json, Commit::fromArray(...));
$shown = $json === null ? null : [array_slice($kept, 0, self::PreviewCommits), count($kept) > self::PreviewCommits, array_diff_key($json, ['data' => true])];
$key = hash('xxh3', serialize($shown));

if (($this->previews[$log][0] ?? null) !== $key) {
$page = $json === null ? null : Page::fromArray(['data' => array_slice($kept, 0, self::PreviewCommits)] + $json, Commit::fromArray(...));

$this->previews[$log] = [$key, [
'commits' => $page->items ?? [],
// Rows past the preview are left out, with a skeleton row for them, as for the next page.
'nextCursor' => count($kept) > self::PreviewCommits ? 'preview' : $page?->nextCursor,
'threads' => [],
'latestCommits' => [],
'suggestions' => array_values(array_map(Commit::fromArray(...), array_filter(is_array($json['suggestions'] ?? null) ? $json['suggestions'] : [], is_array(...)))),
'loaded' => $page !== null,
'error' => null,
]];
}

return [
'commits' => $page->items ?? [],
// Rows past the preview are left out, with a skeleton row for them, as for the next page.
'nextCursor' => count($kept) > self::PreviewCommits ? 'preview' : $page?->nextCursor,
'threads' => [],
'latestCommits' => [],
'suggestions' => array_values(array_map(Commit::fromArray(...), array_filter(is_array($json['suggestions'] ?? null) ? $json['suggestions'] : [], is_array(...)))),
'loaded' => $page !== null,
'lastVisitAt' => $this->lastVisitSeenAt($log),
'error' => null,
];
return [...$this->previews[$log][1], 'lastVisitAt' => $this->lastVisitSeenAt($log)];
}

public function isRanked(): bool
Expand Down
5 changes: 4 additions & 1 deletion resources/views/native/commit-detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@foreach ($rows as $row)
@php($isFocused = $row->commit->id === $commit?->id)
@php($hasThread = $isFocused && $repliesShown && $replies !== [])
@include('native.partials.commit-row', [
@php($threadRow = [
'commit' => $row->commit,
'previousLane' => $row->previousLane,
'continuesRun' => $row->continuesRun,
Expand All @@ -53,6 +53,9 @@
'withTail' => ! $loop->last,
'hairline' => ! ($loop->last && $relatedBelow),
])
{{-- Kept like the replies, so typing a reply only builds the reply bar. The commit a page is about also shows its replies' toggle and count, and its time in your timezone. --}}
@php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))
@php($replyRows->include('thread-'.$row->commit->id, [...\App\Devnull\RowInputs::for($row->commit, $rowScope), 'focused' => $isFocused ? [$repliesShown, $replyCount, app(\App\Devnull\Timezone::class)->yours()] : null], 'native.partials.commit-row', $threadRow, $rowScope))
@if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null)
<native:row ref="loading-replies" class="w-full pl-[64] pr-4 py-4 gap-2 items-center" a11y-label="Loading replies">
<native:activity-indicator size="small" />
Expand Down
8 changes: 5 additions & 3 deletions resources/views/native/partials/commit-actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

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 label, inside the button.
The screen passes the names of the drafts it has kept ($stashed, see App\Devnull\Stash).
The screen passes the names of the drafts it has kept ($stashed, see App\Devnull\Stash). It passes you ($viewer)
and your pastéis ($pasteis) too, and null is an answer: a row only asks the account when the screen gave neither,
since asking is a query on a phone, and with pastéis mode off every row asked again.

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
Expand Down Expand Up @@ -52,7 +54,7 @@
@php($repliesCount ??= $commit->repliesCount)
@php($iconSize = $compact ? 14 : 16)
@php($labelSize = $compact ? 'text-xs' : 'text-[13px]')
@php($viewer ??= app(\App\Devnull\Account::class)->user())
@php($viewer = array_key_exists('viewer', get_defined_vars()) ? $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))
Expand All @@ -63,7 +65,7 @@
@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($pasteis = array_key_exists('pasteis', get_defined_vars()) ? $pasteis : app(\App\Devnull\Account::class)->pasteis())
@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'))
Expand Down
26 changes: 20 additions & 6 deletions resources/views/native/partials/feed.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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
Given a $rowCache (see App\Devnull\RowCache), commits, replies and markers 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
go as placeholders with the keys their partials give them, so the phone keeps each one's place and height.
--}}
@php
Expand All @@ -16,11 +16,18 @@
@endphp
@foreach ($rows as $feedIndex => $row)
@if ($row->isDayMarker())
@if ($rowWindow?->place($feedIndex) ?? true)
@php
$markerDraws = $rowWindow?->place($feedIndex) ?? true;
@endphp
@if (! $markerDraws)
@php
$rowWindow->placeholder('day-'.$row->label);
@endphp
@elseif ($rowCache === null)
@include('native.partials.day-marker', ['label' => $row->label, 'lane' => $row->previousLane])
@else
@php
$rowWindow->placeholder('day-'.$row->label);
$rowCache->include('day-'.$row->label, [], 'native.partials.day-marker', ['label' => $row->label, 'lane' => $row->previousLane], []);
@endphp
@endif
@elseif ($row->isWhoToFollow())
Expand All @@ -32,11 +39,18 @@
@endphp
@endif
@elseif ($row->isLastVisitMarker())
@if ($rowWindow?->place($feedIndex) ?? true)
@php
$markerDraws = $rowWindow?->place($feedIndex) ?? true;
@endphp
@if (! $markerDraws)
@php
$rowWindow->placeholder('last-visit');
@endphp
@elseif ($rowCache === null)
@include('native.partials.last-visit-marker', ['lane' => $row->previousLane])
@else
@php
$rowWindow->placeholder('last-visit');
$rowCache->include('last-visit', [], 'native.partials.last-visit-marker', ['lane' => $row->previousLane], []);
@endphp
@endif
@else
Expand Down
12 changes: 9 additions & 3 deletions resources/views/native/partials/log-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class="w-full flex-1 bg-theme-surface"
>
@if (! $page['loaded'] && $page['error'] === null)
@foreach (range(1, 3) as $skeleton)
@include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']])
@php
$page['rowCache']->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']], []);
@endphp
@endforeach
@endif

Expand All @@ -45,9 +47,13 @@ class="w-full flex-1 bg-theme-surface"

@if ($page['lastCommit'])
@if ($page['nextCursor'] !== null)
@include('native.partials.rail-loading', ['pulse' => $page['showing']])
@php
$page['rowCache']->include('loading-more', [], 'native.partials.rail-loading', ['pulse' => $page['showing']], []);
@endphp
@else
@include('native.partials.rail-end', ['lane' => $page['lastCommit']->lane(), 'message' => "That's the root commit. There's nothing before it."])
@php
$page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $page['lastCommit']->lane(), 'message' => "That's the root commit. There's nothing before it."], []);
@endphp
@endif
@endif
</native:list>
Expand Down
16 changes: 12 additions & 4 deletions resources/views/native/partials/organization-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class="w-full flex-1 bg-theme-surface"
])
@elseif (! $page['loaded'])
@foreach (range(1, 3) as $skeleton)
@include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']])
@php
$page['rowCache']->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']], []);
@endphp
@endforeach
@elseif ($page['isEmpty'])
@if ($page['tab'] === 'mentions')
Expand All @@ -36,11 +38,17 @@ class="w-full flex-1 bg-theme-surface"

@if ($page['loaded'] && ! $page['isEmpty'])
@if ($page['nextCursor'] !== null)
@include('native.partials.rail-loading', ['pulse' => $page['showing']])
@php
$page['rowCache']->include('loading-more', [], 'native.partials.rail-loading', ['pulse' => $page['showing']], []);
@endphp
@elseif ($page['tab'] === 'mentions')
@include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's the first mention of {$user->handle()}."])
@php
$page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's the first mention of {$user->handle()}."], []);
@endphp
@else
@include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's {$user->handle()}'s root commit."])
@php
$page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => "That's {$user->handle()}'s root commit."], []);
@endphp
@endif
@endif
@endif
Expand Down
23 changes: 18 additions & 5 deletions resources/views/native/partials/profile-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

The pager draws the header and the tabs at the top of this list, so they scroll with it. As on the Log, each tab has
its own list, a new $page['listKey'] puts it back at the top, and only the tab you're on asks for its next page.
The pinned commit, the skeleton rows and the row at the end are kept in the tab's row cache with its commits, so
a frame only builds what changed.
--}}
<native:column native:key="page-{{ $page['tab'] }}" class="w-full h-full bg-theme-surface">
<native:list
Expand All @@ -16,7 +18,9 @@ class="w-full flex-1 bg-theme-surface"
>
@if (! $page['loaded'] && $page['error'] === null)
@foreach (range(1, 3) as $skeleton)
@include('native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']])
@php
$page['rowCache']->include('loading-'.$skeleton, [], 'native.partials.rail-loading', ['ref' => 'loading-'.$skeleton, 'label' => 'Loading commits', 'pulse' => $page['showing']], []);
@endphp
@endforeach
@endif

Expand All @@ -39,18 +43,27 @@ class="w-full flex-1 bg-theme-surface"
<native:text font="mono" class="text-xs text-theme-ink-muted">Pinned</native:text>
</native:row>
</native:row>
@include('native.partials.commit-row', ['commit' => $page['pinnedCommit'], 'previousLane' => null, 'continuesRun' => false, 'rowKey' => 'pinned-'.$page['pinnedCommit']->id])
@php
$rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]);
$page['rowCache']->include('pinned-'.$page['pinnedCommit']->id, \App\Devnull\RowInputs::for($page['pinnedCommit'], $rowScope), 'native.partials.commit-row', ['commit' => $page['pinnedCommit'], 'previousLane' => null, 'continuesRun' => false, 'rowKey' => 'pinned-'.$page['pinnedCommit']->id], $rowScope);
@endphp
@endif

@include('native.partials.feed', ['rows' => $page['rows'], 'threads' => $page['threads'], 'rowCache' => $page['rowCache']])

@if (! $page['isEmpty'] || $page['pinnedCommit'])
@if ($page['nextCursor'] !== null)
@include('native.partials.rail-loading', ['pulse' => $page['showing']])
@php
$page['rowCache']->include('loading-more', [], 'native.partials.rail-loading', ['pulse' => $page['showing']], []);
@endphp
@elseif ($page['tab'] === 'replies')
@include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first reply.' : "That's {$user->handle()}'s first reply."])
@php
$page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first reply.' : "That's {$user->handle()}'s first reply."], []);
@endphp
@else
@include('native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first commit. Everyone starts somewhere.' : "That's {$user->handle()}'s root commit."])
@php
$page['rowCache']->include('root-commit', [], 'native.partials.rail-end', ['lane' => $user->lane(), 'message' => $isMe ? 'That was your first commit. Everyone starts somewhere.' : "That's {$user->handle()}'s root commit."], []);
@endphp
@endif
@endif
</native:list>
Expand Down
Loading
Loading