From bf9cf4807e114efed78d42b5bc810cfc0dfb78f7 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Tue, 1 Dec 2026 01:59:23 +1030 Subject: [PATCH] Say which joined guild brought a commit into Following On the web, a commit that's in your Following log because you joined a guild says "because you joined" with the guild's pill, under its header. devnull now sends this as joined_guild on the signed Following log, so the app shows the same line there, in place of "posted in". The guild's name and icon come from the commit's own guild or the guilds its hashtags name, falling back to the hashtag. The pill is now a shared partial that both lines use, and tapping it opens the guild. --- app/Devnull/Data/Commit.php | 22 +++++++++++++++ app/Devnull/RowInputs.php | 2 ++ app/NativeComponents/Log.php | 2 ++ .../partials/commit-row-content.blade.php | 7 +++-- .../native/partials/guild-badge.blade.php | 6 +--- .../native/partials/guild-pill.blade.php | 11 ++++++++ .../native/partials/joined-guild.blade.php | 11 ++++++++ .../views/native/partials/log-page.blade.php | 2 +- tests/Feature/Screens/CommitCardTest.php | 28 +++++++++++++++++++ tests/Unit/Devnull/CommitCardDataTest.php | 17 +++++++++++ 10 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 resources/views/native/partials/guild-pill.blade.php create mode 100644 resources/views/native/partials/joined-guild.blade.php diff --git a/app/Devnull/Data/Commit.php b/app/Devnull/Data/Commit.php index 13656d57..ba6cae7a 100644 --- a/app/Devnull/Data/Commit.php +++ b/app/Devnull/Data/Commit.php @@ -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 { @@ -84,6 +89,7 @@ public function __construct( public ?ScoreCard $scoreCard = null, public ?string $continuationId = null, public ?Guild $guild = null, + public ?Guild $joinedGuild = null, ) {} /** @@ -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 $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. */ diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index 843a5367..2b99ea2c 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -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, ]; diff --git a/app/NativeComponents/Log.php b/app/NativeComponents/Log.php index 3fd8facd..0a9fcb1c 100644 --- a/app/NativeComponents/Log.php +++ b/app/NativeComponents/Log.php @@ -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', ]; } diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 347af90b..211516b2 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -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). @@ -84,7 +85,9 @@ @endif - @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 diff --git a/resources/views/native/partials/guild-badge.blade.php b/resources/views/native/partials/guild-badge.blade.php index 83f32786..6f938ec0 100644 --- a/resources/views/native/partials/guild-badge.blade.php +++ b/resources/views/native/partials/guild-badge.blade.php @@ -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) posted in - - @include('native.partials.guild-mark', ['guild' => $guild, 'size' => 14, 'ref' => 'guild-pill-mark-'.$commit->id]) - {{ $guild->name }} - + @include('native.partials.guild-pill', ['guild' => $commit->guild, 'ref' => 'guild-pill-'.$commit->id, 'markRef' => 'guild-pill-mark-'.$commit->id]) ยท not shown in general logs diff --git a/resources/views/native/partials/guild-pill.blade.php b/resources/views/native/partials/guild-pill.blade.php new file mode 100644 index 00000000..e19ee808 --- /dev/null +++ b/resources/views/native/partials/guild-pill.blade.php @@ -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. +--}} + + @include('native.partials.guild-mark', ['guild' => $guild, 'size' => 14, 'ref' => $markRef]) + {{ $guild->name }} + diff --git a/resources/views/native/partials/joined-guild.blade.php b/resources/views/native/partials/joined-guild.blade.php new file mode 100644 index 00000000..b4ac0fde --- /dev/null +++ b/resources/views/native/partials/joined-guild.blade.php @@ -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). +--}} + + because you joined + @include('native.partials.guild-pill', ['guild' => $commit->joinedGuild, 'ref' => 'joined-guild-pill-'.$commit->id, 'markRef' => 'joined-guild-mark-'.$commit->id]) + diff --git a/resources/views/native/partials/log-page.blade.php b/resources/views/native/partials/log-page.blade.php index 4b18be87..435dadd7 100644 --- a/resources/views/native/partials/log-page.blade.php +++ b/resources/views/native/partials/log-page.blade.php @@ -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) diff --git a/tests/Feature/Screens/CommitCardTest.php b/tests/Feature/Screens/CommitCardTest.php index c60c3b5c..ae2fc8ba 100644 --- a/tests/Feature/Screens/CommitCardTest.php +++ b/tests/Feature/Screens/CommitCardTest.php @@ -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'); +}); diff --git a/tests/Unit/Devnull/CommitCardDataTest.php b/tests/Unit/Devnull/CommitCardDataTest.php index 3a213756..ea70cd13 100644 --- a/tests/Unit/Devnull/CommitCardDataTest.php +++ b/tests/Unit/Devnull/CommitCardDataTest.php @@ -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(); +});