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
22 changes: 22 additions & 0 deletions app/Devnull/Data/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*
* A commit posted straight to a guild's board knows that guild ($guild), which
* keeps it out of general logs.
*
* In the Following log, a commit that's there only because you joined a guild
* knows that guild ($joinedGuild), as the web's "because you joined" line does.
* devnull sends only its handle, so its name and icon come from the commit's
* own guild or the guilds its hashtags name.
*/
final readonly class Commit
{
Expand Down Expand Up @@ -84,6 +89,7 @@ public function __construct(
public ?ScoreCard $scoreCard = null,
public ?string $continuationId = null,
public ?Guild $guild = null,
public ?Guild $joinedGuild = null,
) {}

/**
Expand Down Expand Up @@ -156,9 +162,25 @@ public static function fromArray(array $data): self
scoreCard: $scoreCard,
continuationId: is_string($data['continuation_id'] ?? null) && $data['continuation_id'] !== '' ? $data['continuation_id'] : null,
guild: $guild,
joinedGuild: self::joinedGuild($data['joined_guild'] ?? null, $guilds),
);
}

/**
* The joined guild that brought this commit into Following, named as the
* commit names it, or by its hashtag when the commit doesn't.
*
* @param array<string, Guild> $guilds The commit's guilds, keyed by lowercase handle.
*/
private static function joinedGuild(mixed $handle, array $guilds): ?Guild
{
if (! is_string($handle) || $handle === '') {
return null;
}

return $guilds[mb_strtolower($handle)] ?? Guild::fromArray(['handle' => $handle]);
}

/**
* This commit with your star flipped and its count moved to match.
*/
Expand Down
2 changes: 2 additions & 0 deletions app/Devnull/RowInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static function for(Commit $commit, array $scope): array
'video' => $commit->linkPreview?->embed === null ? null : VideoDetails::card($commit->linkPreview),
// On a guild's board, its moderator's More pins or unpins it.
'boardPin' => ($scope['pinsToBoard'] ?? false) ? ($scope['boardPinnedId'] ?? null) === $commit->id : null,
// In Following, a commit a joined guild brought there says which.
'joinedGuild' => ($scope['showsJoinedGuild'] ?? false) ? $commit->joinedGuild?->handle : null,
// A poll's Vote button wears your lane colour.
'colour' => $scope['myColour'] ?? null,
];
Expand Down
2 changes: 2 additions & 0 deletions app/NativeComponents/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,8 @@ private function page(string $log, array $state, Ownership $ownership, int $list
'lastCommit' => $commits[array_key_last($commits) ?? -1] ?? $latestCommits[array_key_last($latestCommits) ?? -1] ?? null,
'rows' => $rows,
'whoToFollow' => $showsWhoToFollow ? $this->whoToFollow() : null,
// Only Following says which joined guild brought a commit there, as on the web.
'showsJoinedGuild' => $log === 'following',
];
}

Expand Down
7 changes: 5 additions & 2 deletions resources/views/native/partials/commit-row-content.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
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 posted straight to a guild's board says so under its header (see guild-badge), except in search.
A commit posted straight to a guild's board says so under its header (see guild-badge), except in search. In the
Following log ($showsJoinedGuild), a commit a joined guild brought there says that instead (see joined-guild).

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).
Expand Down Expand Up @@ -84,7 +85,9 @@
@endif
</native:row>

@if ($commit->guild !== null && ! ($hidesGuildBadge ?? false))
@if ($commit->joinedGuild !== null && ($showsJoinedGuild ?? false))
@include('native.partials.joined-guild')
@elseif ($commit->guild !== null && ! ($hidesGuildBadge ?? false))
@include('native.partials.guild-badge')
@endif

Expand Down
6 changes: 1 addition & 5 deletions resources/views/native/partials/guild-badge.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
Tapping the pill opens the guild's own screen (see OpensGuilds). A guild's own board
leaves the badge off its commits, since they're all posted there (see Guild).
--}}
@php($guild = $commit->guild)
<native:row ref="guild-badge-{{ $commit->id }}" class="w-full gap-1 items-center">
<native:text class="text-xs text-theme-ink-muted">posted in</native:text>
<native:pressable ref="guild-pill-{{ $commit->id }}" @press="openGuild('{{ $guild->handle }}')" class="flex-row flex-shrink gap-1 items-center rounded-sm bg-theme-wash px-1 py-[2]" a11y-label="{{ $guild->name }}, {{ $guild->hashtag() }}">
@include('native.partials.guild-mark', ['guild' => $guild, 'size' => 14, 'ref' => 'guild-pill-mark-'.$commit->id])
<native:text font="mono" class="text-xs text-theme-ink flex-shrink" :max-lines="1">{{ $guild->name }}</native:text>
</native:pressable>
@include('native.partials.guild-pill', ['guild' => $commit->guild, 'ref' => 'guild-pill-'.$commit->id, 'markRef' => 'guild-pill-mark-'.$commit->id])
<native:text class="text-xs text-theme-ink-muted">· not shown in general logs</native:text>
</native:row>
11 changes: 11 additions & 0 deletions resources/views/native/partials/guild-pill.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{--
A guild as a small pill: its mark (uploaded icon or emoji, see guild-mark) and its name in mono, on the wash.
The lines under a commit's header use it, "posted in" (see guild-badge) and "because you joined" (see
joined-guild). Tapping it opens the guild's own screen (see OpensGuilds).

$ref names the pill and $markRef its mark.
--}}
<native:pressable ref="{{ $ref }}" @press="openGuild('{{ $guild->handle }}')" class="flex-row flex-shrink gap-1 items-center rounded-sm bg-theme-wash px-1 py-[2]" a11y-label="{{ $guild->name }}, {{ $guild->hashtag() }}">
@include('native.partials.guild-mark', ['guild' => $guild, 'size' => 14, 'ref' => $markRef])
<native:text font="mono" class="text-xs text-theme-ink flex-shrink" :max-lines="1">{{ $guild->name }}</native:text>
</native:pressable>
11 changes: 11 additions & 0 deletions resources/views/native/partials/joined-guild.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{--
In the Following log, the web says why a commit by someone you don't follow is there: "because you joined
#guild". It's either posted in a guild you joined or tags one with its hashtag. The line takes the place of
"posted in" (see guild-badge), as on the web.

Tapping the pill opens the guild's own screen (see OpensGuilds).
--}}
<native:row ref="joined-guild-{{ $commit->id }}" class="w-full gap-1 items-center">
<native:text class="text-xs text-theme-ink-muted">because you joined</native:text>
@include('native.partials.guild-pill', ['guild' => $commit->joinedGuild, 'ref' => 'joined-guild-pill-'.$commit->id, 'markRef' => 'joined-guild-mark-'.$commit->id])
</native:row>
2 changes: 1 addition & 1 deletion resources/views/native/partials/log-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class="w-full flex-1 bg-theme-surface {{ $embedded ? '' : \App\Devnull\Display::
@endif
@endif

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

@if ($page['lastCommit'])
@if ($page['nextCursor'] !== null)
Expand Down
28 changes: 28 additions & 0 deletions tests/Feature/Screens/CommitCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,31 @@ function logOf(array $commits): TestableComponent

expect(nodeByRef($screen, 'guild-pill-mark-g1')['props']['text'] ?? null)->toBe('🦀');
});

it('says which joined guild brought a commit into Following, in place of where it was posted, as the web does', function () {
$rust = ['handle' => 'rust', 'name' => 'Rust', 'emoji' => '🦀', 'icon_url' => null];
$screen = logOf([
['id' => 'g1', 'guild_handle' => 'rust', 'guild' => $rust, 'joined_guild' => 'rust'],
['id' => 't1', 'body' => 'Deleted 80 lines #php', 'guild_mentions' => [['handle' => 'php', 'name' => 'PHP', 'emoji' => '🐘', 'icon_url' => null]], 'joined_guild' => 'php'],
])->assertSee('because you joined');

expect(nodeByRef($screen, 'joined-guild-pill-g1')['props']['a11y_label'])->toBe('Rust, #rust')
->and(nodeByRef($screen, 'joined-guild-pill-t1')['props']['a11y_label'])->toBe('PHP, #php')
->and(rendersRef($screen, 'guild-badge-g1'))->toBeFalse();
$screen->assertDontSee('posted in');
});

it('opens the joined guild that brought a commit into Following', function () {
logOf([['id' => 't1', 'joined_guild' => 'php']])
->tap('joined-guild-pill-t1')
->assertNavigatedTo('/log/guilds/php');
});

it('says nothing about joined guilds outside Following, as the web does', function () {
$screen = logOf([['id' => 'g1', 'guild_handle' => 'rust', 'guild' => ['handle' => 'rust', 'name' => 'Rust', 'emoji' => '🦀', 'icon_url' => null], 'joined_guild' => 'rust']]);
$latest = tapLogTab($screen, 'latest');
$refs = array_column(findNodes(showingLog($latest), fn (array $node): bool => isset($node['ref'])), 'ref');

expect($refs)->not->toContain('joined-guild-g1')
->and($refs)->toContain('guild-badge-g1');
});
17 changes: 17 additions & 0 deletions tests/Unit/Devnull/CommitCardDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,20 @@ function pollJson(array $overrides = []): array
->and(Commit::fromArray(cardJson())->guild)->toBeNull()
->and(Commit::fromArray(cardJson(['guild_handle' => '', 'guild' => ['name' => 'Rust']]))->guild)->toBeNull();
});

it('knows which joined guild brought a commit into Following, named as the commit names it', function () {
$postedIn = Commit::fromArray(cardJson(['guild_handle' => 'rust', 'guild' => ['handle' => 'rust', 'name' => 'Rust', 'emoji' => '🦀'], 'joined_guild' => 'rust']));
$tagged = Commit::fromArray(cardJson(['guild_mentions' => [['handle' => 'php', 'name' => 'PHP', 'emoji' => '🐘']], 'joined_guild' => 'PHP']));

expect($postedIn->joinedGuild?->name)->toBe('Rust')
->and($postedIn->withStar(true)->joinedGuild?->handle)->toBe('rust')
->and($tagged->joinedGuild?->name)->toBe('PHP')
->and($tagged->joinedGuild?->emoji)->toBe('🐘');
});

it('names a joined guild by its hashtag when the commit says nothing else about it, and knows none without a handle', function () {
expect(Commit::fromArray(cardJson(['joined_guild' => 'laravel']))->joinedGuild?->name)->toBe('#laravel')
->and(Commit::fromArray(cardJson())->joinedGuild)->toBeNull()
->and(Commit::fromArray(cardJson(['joined_guild' => null]))->joinedGuild)->toBeNull()
->and(Commit::fromArray(cardJson(['joined_guild' => 5]))->joinedGuild)->toBeNull();
});