From e8bb8d9cee4bb58c9031eb6c50dc4fffbad79823 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 15 Nov 2026 21:48:38 +0000 Subject: [PATCH] Open a Remotes message's images in the full-screen viewer Tapping an image in a direct-message or org thread now opens the image viewer from #175 at that image. It pages through that message's images only, as a commit's do. Drag to close and Save to Photos come with it. Images of a message still being pushed stay untappable, since they only exist on the phone until devnull has them. The long-press menu on a message's images is unchanged. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Conversation.php | 16 +++- resources/views/native/conversation.blade.php | 3 + .../native/partials/message-images.blade.php | 10 +- tests/Feature/Screens/ConversationTest.php | 95 +++++++++++++++++++ tests/Feature/Screens/RemotesComposerTest.php | 6 +- 5 files changed, 125 insertions(+), 5 deletions(-) diff --git a/app/NativeComponents/Conversation.php b/app/NativeComponents/Conversation.php index ef23ac67..a4301253 100644 --- a/app/NativeComponents/Conversation.php +++ b/app/NativeComponents/Conversation.php @@ -29,6 +29,7 @@ use App\NativeComponents\Concerns\PlaysVoiceNotes; use App\NativeComponents\Concerns\RecordsVoiceNotes; use App\NativeComponents\Concerns\RefreshesInBackground; +use App\NativeComponents\Concerns\ShowsImageViewer; use App\NativeComponents\Concerns\SuggestsMentions; use App\NativeComponents\Concerns\SyncsOutbox; use App\NativeComponents\Concerns\TalksToDevnull; @@ -77,7 +78,8 @@ * and letting go there sets the composer replying to it; it springs back * either way. A double tap toggles a heart. A long press opens its menu (see * MessageMenu), whose React shows the web's quick reactions in a bubble - * above it, with More for the phone's own emoji picker. + * above it, with More for the phone's own emoji picker. A tap on one of its + * images opens them full-screen (see ShowsImageViewer). * * An org's pinned messages show as the web shows them: the latest in a bar * over the top of the thread, which opens them all in a sheet, and a pin @@ -109,6 +111,7 @@ class Conversation extends NativeComponent use PlaysVoiceNotes; use RecordsVoiceNotes; use RefreshesInBackground; + use ShowsImageViewer; use SuggestsMentions; use SyncsOutbox; use TalksToDevnull; @@ -1109,6 +1112,17 @@ public function openLink(int $id): void } } + /** + * Opens a message's images full-screen (see ShowsImageViewer), from the one + * tapped, paging through that message's images only, as a commit's do. A + * message the thread isn't showing opens nothing, nor does one still being + * pushed, whose images are only on the phone. + */ + public function openMessageImage(int $id, int $index = 0): void + { + $this->showImagesInViewer($this->findMessage($id)?->images ?? [], $index); + } + /** * Opens a link in a message's body, by its place among the body's links: a * commit or another page on dev/null the app has a screen for here in the diff --git a/resources/views/native/conversation.blade.php b/resources/views/native/conversation.blade.php index c01b14b7..56343314 100644 --- a/resources/views/native/conversation.blade.php +++ b/resources/views/native/conversation.blade.php @@ -168,4 +168,7 @@ {{-- More reactions, from the bubble or anywhere else: the emoji keyboard on iOS, Jetpack's emoji picker on Android. --}} + + {{-- A message's images full-screen, over everything else. --}} + @include('native.partials.image-viewer') diff --git a/resources/views/native/partials/message-images.blade.php b/resources/views/native/partials/message-images.blade.php index e6c0bc12..94557fed 100644 --- a/resources/views/native/partials/message-images.blade.php +++ b/resources/views/native/partials/message-images.blade.php @@ -1,10 +1,16 @@ {{-- - A message's images. A long press on them opens the message's menu, as on its bubble ($photosMenu). + A message's images. A long press on them opens the message's menu, as on its bubble ($photosMenu). A tap on one + opens the message's images full-screen from that one (see Conversation::openMessageImage), once devnull has the + message: a message still being pushed has its images only on the phone. --}} @if ($message->images !== []) @foreach ($message->images as $index => $image) - + @if ($message->isPending()) + + @else + + @endif @endforeach @endif diff --git a/tests/Feature/Screens/ConversationTest.php b/tests/Feature/Screens/ConversationTest.php index 5e0634ef..8fa6bedd 100644 --- a/tests/Feature/Screens/ConversationTest.php +++ b/tests/Feature/Screens/ConversationTest.php @@ -2,8 +2,12 @@ use App\Devnull\Account; use App\Devnull\Data\Remotes; +use App\Devnull\ImageCache; +use App\Devnull\ImageViewer; use App\NativeComponents\Conversation; +use Devnull\Photos\Events\Saved; use Illuminate\Http\Client\Request; +use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; use Native\Mobile\Events\Alert\ButtonPressed; use Native\Mobile\Testing\Native; @@ -1389,3 +1393,94 @@ function orgWithMembers(array $people): array ->tap('mention-ada') ->assertSet('draft', 'hi'); }); + +/** + * A message's photos as devnull sends them: $count of them, numbered from $first, the first described. + * + * @return list> + */ +function remotePhotos(int $count, int $first = 1): array +{ + return array_map(fn (int $n): array => [ + 'id' => $n, + 'width' => 400, + 'height' => 300, + 'description' => $n === $first ? 'The new logo' : null, + 'url' => 'https://img.test/'.$n, + ], range($first, $first + $count - 1)); +} + +it("opens a message's image full-screen from the one tapped, and pages through that message's images only", function (string $platform) { + serveRemoteThread(threadJson([ + remoteMessageJson(['id' => 1, 'body' => '', 'images' => remotePhotos(3)]), + remoteMessageJson(['id' => 2, 'body' => 'and the dark one', 'images' => remotePhotos(2, first: 4)]), + ], ['read_through_id' => 2])); + + $screen = finishRefreshes(Native::visit('/remotes/conversations/ada', platform: $platform)); + + // Hidden until a tap, always in the tree. + expect(nodeByRef($screen, 'image-viewer')['props']['visible'])->toBeFalse() + ->and(nodeByRef($screen, 'image-1-1')['on_press'] ?? null)->not->toBeNull(); + + $screen->tap('image-1-1')->assertSet('viewerOpen', true)->assertSet('viewerIndex', 1); + + $shown = findNodes(nodeByRef($screen, 'image-viewer'), fn (array $node): bool => ($node['type'] ?? null) === 'image'); + + expect(nodeByRef($screen, 'image-viewer')['props']['visible'])->toBeTrue() + ->and(array_map(fn (array $node): string => $node['props']['src'], $shown))->toBe(['https://img.test/1', 'https://img.test/2', 'https://img.test/3']) + ->and(nodeByRef($screen, 'viewed-image-0')['props']['alt'])->toBe('The new logo, image 1 of 3') + ->and(nodeByRef($screen, 'viewer-dots')['props']['a11y_label'])->toBe('Image 2 of 3') + ->and(nodeByRef($screen, 'viewer-save')['props']['a11y_label'])->toBe('Save to Photos'); + + $screen->changeTab('viewerPaged', 2)->assertSet('viewerIndex', 2); + $screen->dismissSheet('image-viewer')->assertSet('viewerOpen', false)->assertSet('viewerImages', []); + + // A message with text keeps its images tappable too, and opens on its own. + $screen->tap('image-2-1')->assertSet('viewerIndex', 1); + + expect(array_map(fn ($image): string => $image->url, $screen->instance()->viewerImages))->toBe(['https://img.test/4', 'https://img.test/5']) + ->and(nodeByRef($screen, 'viewer-dots')['props']['a11y_label'])->toBe('Image 2 of 2'); + + $screen->assertNativeNotCalled('Browser.OpenInApp'); +})->with(['ios', 'android']); + +it("keeps a message's long-press menu on its images while a tap opens them", function () { + serveRemoteThread(threadJson([remoteMessageJson(['id' => 1, 'body' => '', 'images' => remotePhotos(2)])], ['read_through_id' => 1])); + + $screen = finishRefreshes(Native::visit('/remotes/conversations/ada', platform: 'ios')); + + expect(array_column(menuItems($screen, 'photos-1'), 1))->toBe(['Reply', 'React']); + + $screen->tap('image-1-0')->assertSet('viewerOpen', true); +}); + +it("drags a message's image away and saves it to the phone's photos", function () { + serveRemoteThread(threadJson([remoteMessageJson(['id' => 1, 'body' => '', 'images' => remotePhotos(2)])], ['read_through_id' => 1])); + $this->bridge->respondTo('Photos.Save', ['success' => true]); + + $kept = ImageCache::path('https://img.test/2'); + File::ensureDirectoryExists(dirname($kept)); + File::put($kept, 'jpeg bytes'); + + try { + $screen = finishRefreshes(Native::visit('/remotes/conversations/ada', platform: 'ios'))->tap('image-1-1'); + + $screen->tap('viewer-save') + ->assertNativeCalled('Photos.Save', fn (array $params): bool => $params['path'] === $kept) + ->emitNative(Saved::class) + ->assertNativeCalled('ToastKit.Show', fn (array $params): bool => $params['message'] === 'Saved to Photos'); + + $screen->dragEnd('viewer-dismiss', 0, ImageViewer::DismissDistance)->assertSet('viewerOpen', false); + } finally { + File::delete($kept); + } +}); + +it("opens nothing for a message the thread isn't showing, or a place with no image", function () { + serveRemoteThread(threadJson([remoteMessageJson(['id' => 1, 'body' => '', 'images' => remotePhotos(1)])], ['read_through_id' => 1])); + + $screen = finishRefreshes(Native::visit('/remotes/conversations/ada', platform: 'ios')); + + $screen->call('openMessageImage', 42, 0)->assertSet('viewerOpen', false); + $screen->call('openMessageImage', 1, 3)->assertSet('viewerOpen', false); +}); diff --git a/tests/Feature/Screens/RemotesComposerTest.php b/tests/Feature/Screens/RemotesComposerTest.php index b06a389a..f86f3e61 100644 --- a/tests/Feature/Screens/RemotesComposerTest.php +++ b/tests/Feature/Screens/RemotesComposerTest.php @@ -109,9 +109,10 @@ function threadWithAda(string $platform = 'ios'): TestableComponent $screen->tap('push')->assertSee('the new logo')->assertSee('staged')->assertSet('photos', []); $clientId = $screen->instance()->pending[0]->clientId; - // Drawn from the phone while they go. + // Drawn from the phone while they go, and not opened full-screen until devnull has them. expect(nodeByRef($screen, 'image-'.$clientId.'-0')['props']['src'])->toBe($kept[0]) - ->and(nodeByRef($screen, 'image-'.$clientId.'-1')['props']['src'])->toBe($kept[1]); + ->and(nodeByRef($screen, 'image-'.$clientId.'-1')['props']['src'])->toBe($kept[1]) + ->and(nodeByRef($screen, 'image-'.$clientId.'-0'))->not->toHaveKey('on_press'); finishRefreshes($screen)->assertSee('pushed')->assertSet('pending', []); @@ -121,6 +122,7 @@ function threadWithAda(string $platform = 'ios'): TestableComponent ['name' => 'images[]', 'type' => 'image/png', 'contents' => $contents[1]], ]]) ->and(nodeByRef($screen, 'image-99-0')['props']['src'])->toBe('http://devnull.test/message-images/1?signature=abc') + ->and(nodeByRef($screen, 'image-99-0')['on_press'] ?? null)->not->toBeNull() ->and(array_filter($kept, file_exists(...)))->toBe([]); });