diff --git a/resources/views/native/partials/commit-media.blade.php b/resources/views/native/partials/commit-media.blade.php index 2e0851f7..fe6ea43e 100644 --- a/resources/views/native/partials/commit-media.blade.php +++ b/resources/views/native/partials/commit-media.blade.php @@ -1,6 +1,7 @@ {{-- What hangs under a commit's body on the web: its images, its poll, the commit it quotes, then the link preview, or - for a YouTube link the player devnull offers (see partials/commit-embed). Other players keep the preview for now. + for a YouTube link the player devnull offers (see partials/commit-embed). Other players keep the preview for now, and + so does a video under the commit's own images, as a compact row with no picture of its own. A Nata Nu//ers high score has its card first, which the web doesn't draw (see partials/score-card). A reply in a thread shows only its images and link preview ($withEmbeds false), as the web's thread does. Images hold their space at their aspect ratio on a wash, so one that fails to load leaves the row as it was. Each is @@ -42,23 +43,33 @@ @include('native.partials.quoted-commit') @endif -@if ($commit->linkPreview?->embed?->isYouTube()) +@if ($images === [] && $commit->linkPreview?->embed?->isYouTube()) @include('native.partials.commit-embed', ['preview' => $commit->linkPreview]) @elseif ($commit->linkPreview?->isReady()) @php($preview = $commit->linkPreview) - {{-- A compact row, not a card: a small image, the mono site, then the title and description. --}} - + {{-- A compact row, not a card: a small image, the mono site, then the title and description. Under the commit's own + images it has no image of its own, and a video is this row rather than its player. A YouTube video's row names + the video and its channel, as its card does (see VideoDetails), rather than YouTube's own page title and blurb. --}} + @if ($preview->embed?->isYouTube()) + @php($card = \App\Devnull\VideoDetails::card($preview)) + @php($rowTitle = $card['title'] ?? $preview->title) + @php($rowDescription = $card['author']) + @else + @php($rowTitle = $preview->title) + @php($rowDescription = $preview->description) + @endif + - @if ($preview->imageUrl) + @if ($preview->imageUrl && $images === []) @endif {{ $preview->site() }} - {{ $preview->title }} - @if ($preview->description) - {{ $preview->description }} + {{ $rowTitle }} + @if ($rowDescription) + {{ $rowDescription }} @endif diff --git a/tests/Feature/Screens/CommitEmbedTest.php b/tests/Feature/Screens/CommitEmbedTest.php index 2f6d7416..35515888 100644 --- a/tests/Feature/Screens/CommitEmbedTest.php +++ b/tests/Feature/Screens/CommitEmbedTest.php @@ -156,3 +156,77 @@ function imagesIn(array $node): array expect(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'embed-play-c1'))->toBeNull() ->and(nodeByRef($screen, 'link-preview-c1'))->not->toBeEmpty(); }); + +it("shows a video as a compact link row with no picture under the commit's own images", function () { + Http::fake(['www.youtube.com/oembed*' => Http::response(null, 404), 'devnull.test/*' => Http::response(pageJson([commitJson([ + 'id' => 'c1', + 'body' => 'Watch https://www.youtube.com/watch?v=E9Zx6rx0bWk', + 'images' => [['id' => 7, 'width' => 400, 'height' => 300, 'description' => null, 'url' => 'https://img.test/7']], + 'link_preview' => [ + 'url' => 'https://youtu.be/E9Zx6rx0bWk', + 'title' => 'The episode', + 'description' => null, + 'image_url' => 'https://i.ytimg.com/vi/E9Zx6rx0bWk/hqdefault.jpg', + 'site_name' => 'YouTube', + 'embed' => [ + 'provider' => 'YouTube', + 'kind' => 'video', + 'src' => 'https://www.youtube-nocookie.com/embed/E9Zx6rx0bWk?autoplay=1', + 'aspect_ratio' => '16 / 9', + 'height' => null, + 'poster' => 'https://i.ytimg.com/vi/E9Zx6rx0bWk/hqdefault.jpg', + ], + ], + ])]))]); + + $screen = Native::visit('/log')->assertSee('The episode'); + + $screen->assertMissingElement('pressable', fn (array $node): bool => ($node['ref'] ?? null) === 'embed-play-c1'); + + expect(imagesIn(nodeByRef($screen, 'link-preview-c1')))->toBe([]) + ->and(array_column(array_column(imagesIn(nodeByRef($screen, 'image-7')), 'props'), 'src'))->toHaveCount(1); +}); + +it("leaves a link preview's picture out under the commit's own images", function () { + Http::fake(['devnull.test/*' => Http::response(pageJson([commitJson([ + 'id' => 'c1', + 'body' => 'Read https://example.com/post', + 'images' => [['id' => 7, 'width' => 400, 'height' => 300, 'description' => null, 'url' => 'https://img.test/7']], + 'link_preview' => ['url' => 'https://example.com/post', 'title' => 'The post', 'description' => null, 'image_url' => 'https://example.com/og.png', 'site_name' => null], + ])]))]); + + $screen = Native::visit('/log')->assertSee('The post'); + + expect(imagesIn(nodeByRef($screen, 'link-preview-c1')))->toBe([]); +}); + +it("names the video and its channel in the compact row under the commit's own images", function () { + VideoDetails::remember('https://youtu.be/bod7JDMeF-0', 'Side Projects Got Me Hired', 'Shruti Balasa'); + + Http::fake(['devnull.test/*' => Http::response(pageJson([commitJson([ + 'id' => 'c1', + 'body' => 'Watch https://youtu.be/bod7JDMeF-0', + 'images' => [['id' => 7, 'width' => 400, 'height' => 300, 'description' => null, 'url' => 'https://img.test/7']], + 'link_preview' => [ + 'url' => 'https://youtu.be/bod7JDMeF-0', + 'title' => '- YouTube', + 'description' => 'Enjoy the videos and music you love, upload original content.', + 'image_url' => null, + 'site_name' => 'YouTube', + 'embed' => [ + 'provider' => 'YouTube', + 'kind' => 'video', + 'src' => 'https://www.youtube-nocookie.com/embed/bod7JDMeF-0?autoplay=1', + 'aspect_ratio' => '16 / 9', + 'height' => null, + 'poster' => null, + ], + ], + ])]))]); + + Native::visit('/log') + ->assertSee('Side Projects Got Me Hired') + ->assertSee('Shruti Balasa') + ->assertDontSee('- YouTube') + ->assertDontSee('Enjoy the videos and music you love'); +});