Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/Devnull/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 8 additions & 6 deletions app/Devnull/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -62,12 +70,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().
Expand Down
39 changes: 39 additions & 0 deletions app/Devnull/Pop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Devnull;

/**
* How a star or a pastel looks at each step of the pop it gives when tapped,
* after the web's: the star grows to 1.35 tilted 12 degrees and springs back
* (`star-pop`), the pastel grows to 1.25 and settles (its button's
* `animate()`). See Concerns\PopsReactions for the steps.
*/
final class Pop
{
/**
* Drawn as it is, with the animation that the next step uses, so the phone
* has a node to animate from.
*/
public const string Ready = 'ready';

public const string Up = 'up';

public const string Down = 'down';

/**
* The icon's transform at $step, or nulls when it isn't popping.
*
* @return array{scale: float|null, rotate: float|null, duration: int|null, easing: string|null}
*/
public static function transform(?string $step, string $button): array
{
$star = $button === 'star';

return match ($step) {
self::Ready => ['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],
};
}
}
7 changes: 5 additions & 2 deletions app/Devnull/RowInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ 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),
// A reply whose replies, opened in place, showed its author carried it on gets "Show thread".
'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)],
];
Expand Down
228 changes: 228 additions & 0 deletions app/Devnull/ThreadRows.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<?php

namespace App\Devnull;

use App\Devnull\Data\Commit;
use Closure;

/**
* 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, 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, 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
{
/**
* How long a thread's rows take to fade in or out, in milliseconds.
*/
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;

/**
* 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<string, list<Commit>> $threads Open threads, by the id of the commit or reply they answer.
* @param array<string, string> $cursors Where each open thread with more carries on.
* @param array<string, int> $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<array{key: string, partial: string, data: array<string, mixed>, reply: Commit|null}>
*/
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] ?? []);

$rows = [];
self::branch($rows, $commit, 1, [], $thread, $hasMore, [
'railLane' => $railLane,
'opensInPlace' => $opensInPlace,
'onPage' => $onPage,
'morePress' => $morePress,
]);

if ($rows === []) {
return [];
}

$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<array<string, mixed>> $rows
* @param list<array{left: float, lane: int|string, top?: int}> $spines Lines from further up running on past these rows.
* @param Closure(string): list<Commit> $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() && ! $onPage ? [] : $thread($reply->id);
$followed = $index < count($replies) - 1 || $more;
$top = ! $onPage && $depth === 1 && $index === 0 ? self::FirstReplyTop : 10;

$rows[] = self::reply($reply, [
'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,
]);

// 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($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']] : []),
]);
}
}

/**
* "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());
}

/**
* @param array<string, mixed> $data
* @return array{key: string, partial: string, data: array<string, mixed>, 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, '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.
*
* @param array<string, mixed> $data
* @return array{key: string, partial: string, data: array<string, mixed>, reply: null}
*/
private static function more(Commit $parent, array $data): array
{
return [
'key' => 'thread-more-'.$parent->id,
'partial' => 'native.partials.thread-more-row',
'data' => ['threadId' => $parent->id, 'last' => false, ...$data],
'reply' => null,
];
}
}
Loading
Loading