Skip to content
Open
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
17 changes: 17 additions & 0 deletions app/Devnull/Data/CommitBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ public static function blocks(string $body, ?array $segments, array $mentions =
return $blocks;
}

/**
* Plain text as runs, with each standalone `/dev/null` outside code as a wordmark run, as the web's WordmarkText
* splits a guild's description or a Remote's preview (see partials/wordmark-text).
*
* @return list<BodyRun>
*/
public static function wordmarkRuns(string $text): array
{
$runs = [];

foreach (preg_split(self::CodeSpans, $text, flags: PREG_SPLIT_DELIM_CAPTURE) ?: [$text] as $index => $segment) {
array_push($runs, ...($index % 2 === 1 ? [new BodyRun($segment)] : self::withWordmarks($segment)));
}

return $runs;
}

/**
* Gives each hashtag that names a guild that guild, matched without case as devnull matches it, so it opens the
* guild rather than a search, as the web's guild mentions do.
Expand Down
2 changes: 1 addition & 1 deletion resources/views/native/partials/body-run.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@elseif ($run->isHashtag && ! ($static ?? false))
<native:text :text="$run->text" font="medium" class="{{ $pieceClasses }} font-medium text-theme-primary" @press="openHashtag('{{ $run->text }}')" />
@elseif ($run->isWordmark)
<native:text font="semibold" class="{{ $pieceClasses }} {{ $pieceInk }} font-semibold {{ $pieceClasses === '' ? 'tracking-tight' : '' }}">@if ($afterSpace)&#x200B;@endif/&#x2060;dev<native:text text="/" class="text-outline text-theme-lane-0" />&#x2060;null</native:text>
@include('native.partials.wordmark', ['classes' => $pieceClasses.' '.$pieceInk, 'tight' => $pieceClasses === ''])
@else
<native:text :text="$run->text" class="{{ $pieceClasses }} {{ $pieceInk }}" />
@endif
2 changes: 1 addition & 1 deletion resources/views/native/partials/guild-header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</native:column>

@if ($guild->description !== '')
<native:text ref="guild-description" class="w-full text-[15px] leading-relaxed text-theme-ink">{{ $guild->description }}</native:text>
<native:text ref="guild-description" class="w-full text-[15px] leading-relaxed text-theme-ink">@include('native.partials.wordmark-text', ['text' => $guild->description])</native:text>
@endif

<native:text ref="guild-how-to-post" class="w-full text-sm text-theme-ink-muted">{{ $guild->isPaused ? 'This guild is paused until it has a moderator. Its board and members are preserved.' : 'Include '.$guild->hashtag().' in any commit to post here.' }}</native:text>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/native/partials/guild-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<native:text font="semibold" class="w-full text-[15px] text-theme-ink" :max-lines="1">{{ $guild->name }}</native:text>
<native:text font="mono" class="w-full text-[13px] text-theme-ink-muted" :max-lines="1">{{ $guild->hashtag() }}</native:text>
@if ($guild->description !== '')
<native:text class="w-full text-sm text-theme-ink" :max-lines="2">{{ $guild->description }}</native:text>
<native:text class="w-full text-sm text-theme-ink" :max-lines="2">@include('native.partials.wordmark-text', ['text' => $guild->description])</native:text>
@endif
<native:text class="text-[13px] text-theme-ink-muted">{{ $members }}</native:text>
</native:column>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/native/partials/message-body.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
the guild's lane colour (see Guild::lane), which could match the colour of your own bubble.
$maxLines caps the body to the first block at that many lines, for the pinned sheet's preview, so its links work
before Show more.
A standalone /dev/null is the wordmark, in the bubble's ink (see partials/wordmark).
--}}
@php($linkInk ??= $mentionInk)
@php($linkPrefixInk ??= 'text-theme-ink-muted')
Expand Down Expand Up @@ -40,6 +41,8 @@
<native:text :text="$run->guild->name" font="mono-medium" class="text-[13px] {{ $mentionInk }}" @press="openGuild('{{ $run->guild->handle }}')" />
@elseif ($run->isHashtag)
<native:text :text="$run->text" font="medium" class="font-medium {{ $mentionInk }}" @press="openHashtag('{{ $run->text }}')" />
@elseif ($run->isWordmark)
@include('native.partials.wordmark', ['afterSpace' => $loop->index > 0 && ctype_space(substr($block->runs[$loop->index - 1]->text, -1))])
@else
<native:text :text="$run->text" />
@endif
Expand Down
4 changes: 2 additions & 2 deletions resources/views/native/partials/remote-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class="w-full"
])
@endif
@if ($last?->isEvent())
<native:text font="mono" class="flex-1 text-xs {{ $conversation->ahead > 0 ? 'text-theme-ink' : 'text-theme-ink-muted' }}" :max-lines="1">{{ $preview }}</native:text>
<native:text font="mono" class="flex-1 text-xs {{ $conversation->ahead > 0 ? 'text-theme-ink' : 'text-theme-ink-muted' }}" :max-lines="1">@include('native.partials.wordmark-text', ['text' => $preview])</native:text>
@else
<native:text class="flex-1 text-sm {{ $conversation->ahead > 0 ? 'text-theme-ink' : 'text-theme-ink-muted' }}" :max-lines="1">{{ $preview }}</native:text>
<native:text class="flex-1 text-sm {{ $conversation->ahead > 0 ? 'text-theme-ink' : 'text-theme-ink-muted' }}" :max-lines="1">@include('native.partials.wordmark-text', ['text' => $preview])</native:text>
@endif
</native:row>
</native:column>
Expand Down
18 changes: 18 additions & 0 deletions resources/views/native/partials/wordmark-text.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{--
The inside of a text element for plain text, with each standalone /dev/null as the wordmark, where the web's
WordmarkText draws one: a guild's description and a Remote's preview (see CommitBody::wordmarkRuns and
partials/wordmark). Text without one is the text alone, as before.

The runs sit flush with no line breaks between them, since a line break in text would print.
--}}@php($runs = \App\Devnull\Data\CommitBody::wordmarkRuns($text))
@if (array_any($runs, fn ($run): bool => $run->isWordmark))
@foreach ($runs as $run)
@if ($run->isWordmark)
@include('native.partials.wordmark', ['afterSpace' => $loop->index > 0 && ctype_space(substr($runs[$loop->index - 1]->text, -1))])
@else
<native:text :text="$run->text" />
@endif
@endforeach
@else
{{ $text }}
@endif
8 changes: 8 additions & 0 deletions resources/views/native/partials/wordmark.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{--
The /dev/null wordmark inside a run of text (see commit-body for how it's drawn and why). $afterSpace says it
follows a space, $classes are extra classes, and $tight false leaves out the tighter tracking, as a piece of a row
of words (see body-run). Nothing comes between this comment and the first directive, and the file ends without a
line break, since it sits inside whitespace-pre-wrap text.
--}}@php($afterSpace ??= false)
@php($tight ??= true)
<native:text font="semibold" class="{{ $classes ?? '' }} font-semibold {{ $tight ? 'tracking-tight' : '' }}">@if ($afterSpace)&#x200B;@endif/&#x2060;dev<native:text text="/" class="text-outline text-theme-lane-0" />&#x2060;null</native:text>
14 changes: 14 additions & 0 deletions tests/Feature/Screens/ConversationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,20 @@ function pulledAvatars(TestableComponent $screen, int $id): array
$screen->press("openGuild('android')")->assertNavigatedTo('/remotes/guilds/android');
});

it('draws /dev/null in a message as the wordmark', function () {
serveRemoteThread(threadJson([
remoteMessageJson(['id' => 1, 'body' => 'try the /dev/null app, not dev/null']),
], ['read_through_id' => 1]));

$screen = finishRefreshes(Native::visit('/remotes/conversations/ada'));

expect(paragraphRuns($screen, 'try the'))->toBe([
['try the '],
['/dev/null', 'wordmark'],
[' app, not dev/null'],
]);
});

it('opens no link preview that is not a web page', function () {
serveRemoteThread(threadJson([
remoteMessageJson(['id' => 1, 'body' => 'Tap me', 'link_preview' => ['url' => 'javascript:alert(1)', 'title' => 'Tap me']]),
Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/Screens/GuildTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ function guildMeta(TestableComponent $screen): string
expect(guildMeta($paused))->toBe('#rust · Public guild · Paused · 1 member');
});

it('draws /dev/null in the description as the wordmark, as the web does', function () {
serveBoard(['' => boardOf(['c1'], overrides: ['guild' => guildJson(['description' => 'Rust talk on /dev/null.'])])]);

expect(paragraphRuns(finishRefreshes(Native::visit('/log/guilds/rust')), 'Rust talk'))->toBe([['Rust talk on '], ['/dev/null', 'wordmark'], ['.']]);
});

it('opens a guilds directory link on top of the board, with a way back', function () {
serveBoard(['' => boardOf(['c1'], overrides: ['data' => [commitJson(['id' => 'c1', 'body' => 'See https://dev-null.sh/guilds'])]])]);

Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/Screens/GuildsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ function serveGuilds(array $pages): void
->and(nodeByRef($screen, 'guild-search-field')['props']['placeholder'])->toBe('Search guilds');
})->with(['ios', 'android']);

it("draws /dev/null in a guild's description as the wordmark", function () {
serveGuilds(['' => guildsPage([guildJson(['handle' => 'go', 'name' => 'Go', 'description' => 'Gophers on /dev/null'])])]);

expect(paragraphRuns(finishRefreshes(Native::visit('/profile/guilds')), 'Gophers'))->toBe([['Gophers on '], ['/dev/null', 'wordmark']]);
});

it('opens a tapped guild in the tab it was tapped in', function () {
serveGuilds(['' => guildsPage([guildJson(['handle' => 'rust'])])]);

Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/Screens/RemotesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
->and(app(Account::class)->unreadRemotes())->toBe(2);
});

it('draws /dev/null in the latest message as the wordmark, as the web inbox does', function () {
fakeApi(['GET /api/v1/remotes' => [remotesInboxJson([conversationJson(['last_message' => remoteMessageJson(['id' => 7, 'body' => 'try /dev/null'])])])]]);

expect(paragraphRuns(finishRefreshes(Native::visit('/remotes')), 'try'))->toBe([['try '], ['/dev/null', 'wordmark']]);
});

it('lists an org by its name, with how many are in it', function () {
fakeApi(['GET /api/v1/remotes' => [remotesInboxJson([conversationJson([
'id' => 'org-1',
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Devnull/CommitBodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,13 @@ function quotesOf(array $blocks): array
it('quotes a line that is only the marker', function () {
expect(quotesOf(CommitBody::blocks('>', null)))->toBe([['quote', '']]);
});

it('splits plain text around each standalone /dev/null and leaves code as written, as the web does', function (string $text, array $runs) {
expect(array_map(fn (BodyRun $run): array => [$run->text, $run->isWordmark], CommitBody::wordmarkRuns($text)))->toBe($runs);
})->with([
['Welcome to /dev/null.', [['Welcome to ', false], ['/dev/null', true], ['.', false]]],
['/dev/null and /dev/null', [['/dev/null', true], [' and ', false], ['/dev/null', true]]],
['run `cat /dev/null` on /dev/null', [['run ', false], ['`cat /dev/null`', false], [' on ', false], ['/dev/null', true]]],
['dev/null, /dev/nullish and ./dev/null', [['dev/null, /dev/nullish and ./dev/null', false]]],
['', []],
]);