Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 44 additions & 21 deletions app/Devnull/CachedRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
* when none of its ids is already in the frame. Otherwise, and for a row with no
* keyed parent, whose ids would come from the frame's running count, the row
* makes its node afresh.
*
* With EDGE's subtree reuse on, the row goes out as EDGE sends any node: a part
* of it the phone already holds, by id and content hash, is sent as a reuse
* marker and taken from the phone's last tree. So a row that hasn't changed
* costs the frame one marker, and a starred one only the parts the star touched.
*/
final class CachedRow extends Element
{
Expand Down Expand Up @@ -65,45 +70,63 @@ public function toArray(
&& array_intersect_key($this->nodeIds, $emittedIds) === []) {
$emittedIds += $this->nodeIds;

return $this->node;
return self::send($this->node, $lastNodeHashes);
}

$node = $this->row->toArray($registry, $nextId, $parentKeyPath, $indexInParent, $emittedIds, $lastNodeHashes);
// Built against no hashes, the row's node is whole, so it can be kept and sent again in any later frame.
$sentNothing = [];
$node = $this->row->toArray($registry, $nextId, $parentKeyPath, $indexInParent, $emittedIds, $sentNothing);
$ids = [];
self::collectIds($node, $ids);

$this->node = $node;
$this->nodePlace = $place;
$this->nodeRegistry = $registry;
$this->nodeIds = $ids;

if (self::collectFullIds($node, $ids)) {
$this->node = $node;
$this->nodePlace = $place;
$this->nodeRegistry = $registry;
$this->nodeIds = $ids;
} else {
$this->node = null;
return self::send($node, $lastNodeHashes);
}

/**
* A node as this frame sends it: a reuse marker where the phone already holds
* it, by its id and hash, as EDGE's own walk does, and otherwise in full, its
* children each sent the same way, and its hash noted as what the phone holds
* next. With subtree reuse off the hashes start empty every frame, so every
* node goes in full.
*
* @param array<string, mixed> $node
* @param array<int, string> $lastNodeHashes
* @return array<string, mixed>
*/
private static function send(array $node, array &$lastNodeHashes): array
{
if (($lastNodeHashes[$node['id']] ?? null) === $node['_hash']) {
return ['id' => $node['id'], 'type' => $node['type'], 'flags' => 1, '_hash' => $node['_hash']];
}

$lastNodeHashes[$node['id']] = $node['_hash'];

if (isset($node['children'])) {
foreach ($node['children'] as $i => $child) {
$node['children'][$i] = self::send($child, $lastNodeHashes);
}
}

return $node;
}

/**
* Collects a node's ids, and its children's. False when any of them is a
* reuse marker, which only stands for a node the phone got in an earlier frame.
* Collects a node's ids, and its children's.
*
* @param array<string, mixed> $node
* @param array<int, true> $ids
*/
private static function collectFullIds(array $node, array &$ids): bool
private static function collectIds(array $node, array &$ids): void
{
if ((($node['flags'] ?? 0) & 1) !== 0) {
return false;
}

$ids[$node['id']] = true;

foreach ($node['children'] ?? [] as $child) {
if (! self::collectFullIds($child, $ids)) {
return false;
}
self::collectIds($child, $ids);
}

return true;
}
}
13 changes: 9 additions & 4 deletions app/Devnull/RowInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,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 @@ -46,6 +49,8 @@ public static function for(Commit $commit, array $scope): array
'poll' => [$scope['pollChoices'][$commit->id] ?? null, in_array($commit->id, $scope['voting'] ?? [], true)],
'selected' => ($scope['selectedCommit'] ?? null) === $commit->id,
'video' => $commit->linkPreview?->embed === null ? null : VideoDetails::card($commit->linkPreview),
// A poll's Vote button wears your lane colour.
'colour' => $scope['myColour'] ?? null,
];
}

Expand Down
13 changes: 3 additions & 10 deletions app/NativeComponents/CommitDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,12 @@ class CommitDetail extends NativeComponent
public string $openedId = '';

/**
* 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;

/**
* Every frame goes in full, as on the Log (see Log::$forceFullFrames). A
* tap on the reply field mounts the thread's scroll view again under a new
* key, and EDGE's subtree reuse sent its unchanged rows as references to
* nodes the phone dropped with the old one, so the thread went blank as
* you started typing.
*/
protected bool $forceFullFrames = true;

public function data(string $key, mixed $default = null): mixed
{
return $this->embedded ? ($this->conversationData[$key] ?? $default) : parent::data($key, $default);
Expand Down
6 changes: 0 additions & 6 deletions app/NativeComponents/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ class Conversation extends NativeComponent

public const int PinnedLines = 3;

/**
* Every frame goes in full, as on the Log (see Log::$forceFullFrames): messages come in at the bottom and their
* reactions change in place, which EDGE's subtree reuse would otherwise miss.
*/
protected bool $forceFullFrames = true;

/**
* Who the thread is with, from the route: a username, or an org's id.
*/
Expand Down
50 changes: 30 additions & 20 deletions app/NativeComponents/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ class Log extends NativeComponent
use TalksToDevnull;
use WatchesForCalls;

/**
* Every frame goes in full. EDGE's subtree reuse sometimes refers to rows
* the phone never got once a list has grown or reordered, and the phone
* drops them, which drew the log blank under a pull to refresh. EDGE's own
* answer for a screen whose lists change often is to send it in full.
*/
protected bool $forceFullFrames = true;

public const array Logs = ['following', 'latest', 'trending'];

/**
Expand Down Expand Up @@ -251,6 +243,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 @@ -438,26 +438,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: 0 additions & 5 deletions app/NativeComponents/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ class Notifications extends NativeComponent
use WatchesForCalls;
use WritesInBackground;

/**
* Every frame goes in full, as on the Log (see Log::$forceFullFrames).
*/
protected bool $forceFullFrames = true;

/**
* How long a group's notifications take to fade in or out, and its
* chevron to turn, in milliseconds: as long as replies take on the Log.
Expand Down
5 changes: 0 additions & 5 deletions app/NativeComponents/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ class Organization extends NativeComponent
use ShowsCommits;
use TalksToDevnull;

/**
* Every frame goes in full, as on a profile (see Profile::$forceFullFrames).
*/
protected bool $forceFullFrames = true;

public const array Tabs = ['commits', 'mentions'];

/**
Expand Down
7 changes: 0 additions & 7 deletions app/NativeComponents/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ class Profile extends NativeComponent
use TalksToDevnull;
use WatchesForCalls;

/**
* Every frame goes in full, as on the Log (see Log::$forceFullFrames). A tab
* tapped again goes back to the top in a list with a new key and the same
* rows, which EDGE's subtree reuse would otherwise never send.
*/
protected bool $forceFullFrames = true;

public string $username = '';

public const array Tabs = ['commits', 'replies'];
Expand Down
6 changes: 0 additions & 6 deletions app/NativeComponents/Remotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ class Remotes extends NativeComponent

public const string LeaveAlert = 'remotes-leave';

/**
* Every frame goes in full, as on the Log (see Log::$forceFullFrames), since a row moves to the top when it
* has a new message.
*/
protected bool $forceFullFrames = true;

/** @var list<ConversationData> */
public array $conversations = [];

Expand Down
5 changes: 0 additions & 5 deletions app/NativeComponents/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ class Search extends NativeComponent
*/
public const int ShortestCommitTerm = 3;

/**
* Every frame goes in full, as on Starred, since a new term replaces every row.
*/
protected bool $forceFullFrames = true;

public string $query = '';

/**
Expand Down
5 changes: 0 additions & 5 deletions app/NativeComponents/Starred.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ class Starred extends NativeComponent
}
use TalksToDevnull;

/**
* Every frame goes in full, as on the Log (see Log::$forceFullFrames), since rows leave the list from the middle.
*/
protected bool $forceFullFrames = true;

/** @var list<Commit> */
public array $commits = [];

Expand Down
10 changes: 10 additions & 0 deletions resources/views/native/commit-detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
<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" />
</native:row>
@elseif ($pageRow['partial'] === 'native.partials.commit-row')
{{--
The commits are kept like the replies, so typing a reply only builds the reply bar. A row's
data says where its commit sits in the tree: its rail, its place in its author's thread, and
for a commit above, how many replies its button counts. RowInputs has whether those are open.
The commit the page is about also shows its own replies' toggle and count, and its time in your
timezone, which only the page knows.
--}}
@php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))
@php($replyRows->include($pageRow['key'], [...\App\Devnull\RowInputs::for($pageRow['data']['commit'], $rowScope), 'focused' => $pageRow['data']['focused'] ? [$repliesShown, $replyCount, app(\App\Devnull\Timezone::class)->yours()] : null], $pageRow['partial'], $pageRow['data'], $rowScope))
@elseif ($pageRow['reply'] === null)
@include($pageRow['partial'], $pageRow['data'])
@else
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
Loading
Loading