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
14 changes: 9 additions & 5 deletions resources/views/native/partials/message-images.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{{--
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.
A message's images, on the wash and edged in their sender's colour like a bubble (see partials/message-item), so a
dark image doesn't melt into a dark thread. 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 !== [])
<native:pressable ref="photos-{{ $key }}" class="gap-1" :context-menu="$photosMenu">
@foreach ($message->images as $index => $image)
@php($shape = $image->width > 0 && $image->height > 0 ? $image->width / $image->height : $image->ratio())
@php($imageWidth = (int) round(min(240, 240 * $shape)))
@if ($message->isPending())
<native:image ref="image-{{ $key }}-{{ $index }}" :src="$image->url" :width="240" :height="(int) round(240 / $image->ratio())" :fit="2" class="rounded-xl bg-theme-wash" a11y-label="{{ $image->label($index, count($message->images)) }}" />
<native:image ref="image-{{ $key }}-{{ $index }}" :src="$image->url" :width="$imageWidth" :height="(int) round($imageWidth / $shape)" :fit="2" class="rounded-xl {{ $tighten(! $startsRun || $index > 0, ! $endsRun || $index < count($message->images) - 1 || $message->voice !== null || $message->body !== '') }} {{ $bubble }}/60" a11y-label="{{ $image->label($index, count($message->images)) }}" />
@else
<native:image ref="image-{{ $key }}-{{ $index }}" @press="openMessageImage({{ $message->id }}, {{ $index }})" :src="$image->url" :width="240" :height="(int) round(240 / $image->ratio())" :fit="2" class="rounded-xl bg-theme-wash" a11y-label="{{ $image->label($index, count($message->images)) }}" />
<native:image ref="image-{{ $key }}-{{ $index }}" @press="openMessageImage({{ $message->id }}, {{ $index }})" :src="$image->url" :width="$imageWidth" :height="(int) round($imageWidth / $shape)" :fit="2" class="rounded-xl {{ $tighten(! $startsRun || $index > 0, ! $endsRun || $index < count($message->images) - 1 || $message->voice !== null || $message->body !== '') }} {{ $bubble }}" a11y-label="{{ $image->label($index, count($message->images)) }}" />
@endif
@endforeach
</native:pressable>
Expand Down
18 changes: 11 additions & 7 deletions resources/views/native/partials/message-item.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{--
One message in a thread, as the web draws it: yours on the right in your lane, everyone else's on the left on
the wash. In an org, a run of someone else's messages starts with their avatar and name, a tap on which opens their profile. Above the bubble, the
One message in a thread: every bubble on the wash, edged in its sender's colour, yours on the right and everyone
else's on the left. In an org, a run of someone else's messages starts with their avatar and name, a tap on which opens their profile. Above the bubble, the
ghost of the message it replies to; beside it its images and link card; under it its reactions, one chip per
emoji, yours outlined in your lane and a tap to take it back or add yours. A run ends in the time, or for the
message the web gives a status, in that status.
Expand All @@ -20,18 +20,22 @@
--}}
@php($key = $message->id > 0 ? $message->id : $message->clientId)
@php($laneToken = \App\Devnull\Lane::token(($author ?? null)?->lane()))
@php($bubble = 'bg-theme-wash border border-theme-'.($mine ? $myColour : $laneToken))
@php($tighten = fn (bool $above, bool $below): string => ($above ? 'rounded-t'.($mine ? 'r' : 'l').'-[4] ' : '').($below ? 'rounded-b'.($mine ? 'r' : 'l').'-[4]' : ''))
@php($replyAuthor = $message->replyTo === null ? null : ($message->replyTo['user_id'] === $viewer?->id ? 'You' : ($authors[$message->replyTo['user_id']]->name ?? 'Someone')))
@php($replyLane = $message->replyTo === null ? 'primary' : \App\Devnull\Lane::token(($authors[$message->replyTo['user_id']] ?? null)?->lane()))
@php($replyable = ($canPush ?? false) && ! $message->isPending())
@php($pull = \App\NativeComponents\Conversation::ReplyPull)
@php($swipeHint = $replyable ? ($mine ? 'Swipe right to reply' : 'Swipe left to reply') : '')
@php($reactionsAnchor = 'absolute top-0 bottom-0 w-[44] '.($mine ? 'right-0' : 'left-0'))
@php($hasChips = $message->reactionChips($viewer?->id) !== [])
@php($chipsHang = $hasChips && ! $endsRun && $status === null)
<native:row native:key="message-{{ $key }}" ref="message-{{ $key }}" class="w-full px-3 {{ $startsRun ? 'pt-3' : 'pt-[3]' }}">
@if ($replyable)
<native:gesture-area ref="swipe-{{ $key }}" :pan-x="$pan" :trigger-x="$mine ? $pull : -$pull" @trigger="reply({{ $message->id }})" class="flex-1">
@endif
{{-- A set width, not a max: a column that only hugs its bubble measures the text on one line and clips it. --}}
<native:column ref="pulled-{{ $key }}" class="{{ $replyable ? 'w-full' : 'flex-1' }} gap-1 {{ $mine ? 'items-end' : 'items-start' }}" :translate-x="! $replyable ? 0 : ($slide >= $pull ? $pan : ($mine ? $pan->clamp(0, $slide) : $pan->clamp(-$slide, 0)))">
<native:column ref="pulled-{{ $key }}" class="{{ $replyable ? 'w-full' : 'flex-1' }} gap-1 {{ $mine ? 'items-end' : 'items-start' }} {{ $chipsHang ? 'pb-[10]' : '' }}" :translate-x="! $replyable ? 0 : ($slide >= $pull ? $pan : ($mine ? $pan->clamp(0, $slide) : $pan->clamp(-$slide, 0)))">
@if ($isOrg && ! $mine && $startsRun && $author)
<native:pressable ref="author-{{ $key }}" @press="openProfile('{{ $author->username }}')" a11y-label="{{ $author->name }}'s profile">
<native:row class="gap-[6] items-center px-1">
Expand Down Expand Up @@ -84,14 +88,14 @@
@endif
@if ($message->isPending())
<native:pressable ref="bubble-{{ $key }}" class="flex-shrink" :context-menu="$menu">
<native:column class="px-3 py-2 rounded-2xl {{ $message->status === 'rejected' ? 'border border-theme-destructive bg-theme-surface' : 'bg-theme-'.$myColour.'/60' }}">
@include('native.partials.message-body', ['ink' => $message->status === 'rejected' ? 'text-theme-ink' : 'text-theme-on-'.$myColour, 'mentionInk' => 'text-theme-on-'.$myColour, 'quoteRule' => $message->status === 'rejected' ? 'border-theme-lane-5' : 'border-theme-on-'.$myColour, 'linkPrefixInk' => $message->status === 'rejected' ? 'text-theme-ink-muted' : 'text-theme-on-'.$myColour.'/70'])
<native:column class="px-3 {{ $hasChips ? 'pt-2 pb-[18]' : 'py-2' }} rounded-2xl {{ $tighten(! $startsRun || $message->images !== [] || $message->voice !== null, ! $endsRun) }} {{ $message->status === 'rejected' ? 'border border-theme-destructive bg-theme-surface' : $bubble.'/60' }}">
@include('native.partials.message-body', ['ink' => 'text-theme-ink', 'mentionInk' => 'text-theme-primary', 'quoteRule' => 'border-theme-lane-5'])
</native:column>
</native:pressable>
@else
<native:pressable ref="bubble-{{ $key }}" class="flex-shrink" @doubleTap="heart({{ $message->id }})" :context-menu="$menu" a11y-hint="{{ $swipeHint }}">
<native:column class="px-3 py-2 rounded-2xl {{ $mine ? 'bg-theme-'.$myColour : 'bg-theme-wash' }}">
@include('native.partials.message-body', ['ink' => $mine ? 'text-theme-on-'.$myColour : 'text-theme-ink', 'mentionInk' => $mine ? 'text-theme-on-'.$myColour : 'text-theme-primary', 'quoteRule' => $mine ? 'border-theme-on-'.$myColour : 'border-theme-lane-5', 'linkPrefixInk' => $mine ? 'text-theme-on-'.$myColour.'/70' : 'text-theme-ink-muted'])
<native:column class="px-3 {{ $hasChips ? 'pt-2 pb-[18]' : 'py-2' }} rounded-2xl {{ $tighten(! $startsRun || $message->images !== [] || $message->voice !== null, ! $endsRun) }} {{ $bubble }}">
@include('native.partials.message-body', ['ink' => 'text-theme-ink', 'mentionInk' => 'text-theme-primary', 'quoteRule' => 'border-theme-lane-5'])
</native:column>
</native:pressable>
@endif
Expand Down
24 changes: 18 additions & 6 deletions resources/views/native/partials/message-reactions.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
{{--
A message's reactions, one chip per emoji in the order it was first left, with how many left it: yours outlined in
your lane, and a tap to take yours back or add it.
A message's reactions in one pill with the fill and edge of the bubble they sit on: each emoji in the order it was
first left, with how many left it, the count in your lane where one is yours, and a tap to take yours back or add it.
The pinned sheet has no bubble, so there the pill is on the surface with a hairline edge. The reactions mostly
overlap the bottom of what they react to, 8pt hanging below it, set in from its side on a solid fill; a text or voice
bubble with reactions has room for them under its content (see partials/message-item). They can run wider than a
short message. Android draws a negative margin without giving its space back (see ComposeFlexLayout), so within a run
($chipsHang) they're pinned to the bottom of the message's column, whose padding holds only the 8pt that hangs
below, and the next message comes up close. Otherwise they're a row drawn 19pt higher, with the time or status under
them.
--}}
@php($chipsHang ??= false)
@php($mine ??= false)
@php($pill = $bubble ?? 'bg-theme-surface border border-theme-hairline')
@php($chips = $message->reactionChips($viewer?->id))
@if ($chips !== [])
<native:row ref="reactions-{{ $key }}" class="gap-1">
<native:row class="{{ $chipsHang ? 'absolute -bottom-[8] '.($mine ? 'right-2' : 'left-2') : 'px-2' }} {{ $mine ? 'justify-end' : 'justify-start' }}" :translate-y="$chipsHang ? 0 : -19">
<native:row ref="reactions-{{ $key }}" class="px-2 py-[1] gap-2 items-center rounded-full {{ $pill }}">
@foreach ($chips as $chip)
<native:pressable ref="chip-{{ $key }}-{{ $loop->index }}" @press="toggleReaction({{ $message->id }}, '{{ $chip['emoji'] }}')" a11y-label="{{ $chip['emoji'] }} {{ $chip['count'] }}{{ $chip['mine'] ? ', yours' : '' }}">
<native:row class="px-2 py-[2] gap-1 items-center rounded-full border {{ $chip['mine'] ? 'border-theme-'.$myColour.' bg-theme-'.$myColour.'/10' : 'border-theme-hairline bg-theme-surface' }}">
<native:text class="text-[13px]">{{ $chip['emoji'] }}</native:text>
<native:text font="mono" class="text-[11px] text-theme-ink-muted">{{ $chip['count'] }}</native:text>
<native:row class="gap-1 items-center">
<native:text class="text-[20px]">{{ $chip['emoji'] }}</native:text>
<native:text font="mono" class="text-[13px] {{ $chip['mine'] ? 'text-theme-'.$myColour : 'text-theme-ink-muted' }}">{{ $chip['count'] }}</native:text>
</native:row>
</native:pressable>
@endforeach
</native:row>
</native:row>
@endif
13 changes: 6 additions & 7 deletions resources/views/native/partials/message-voice.blade.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{{--
A message's voice note, in a bubble of its own as the web draws it, with the message's pin and Reply beside it as a
text bubble has them (see partials/message-item). Yours is in your lane, staged in it faded until devnull has it, or
outlined in red once it turned the note down; everyone else's is on the wash. The player is partials/voice-note.
text bubble has them (see partials/message-item). Each is on the wash, edged in its sender's colour, yours faded
until devnull has it, or outlined in red once it turned the note down. The player is partials/voice-note.
A long press opens the message's menu, as on a text bubble, without Copy text, and React's quick reactions point
at the bubble.
--}}
@if ($message->voice !== null)
@php($voiceInk = $message->status === 'rejected' ? 'ink' : ($mine ? 'on-'.$myColour : 'ink'))
<native:row ref="content-{{ $key }}" class="w-full gap-1 items-center {{ $mine ? 'justify-end pl-16' : 'justify-start pr-16' }}">
<native:row ref="bubble-and-pin-{{ $key }}" class="gap-1 items-center">
@if ($mine)
@include('native.partials.message-pin')
@endif
@if ($message->isPending())
<native:column ref="bubble-{{ $key }}" class="p-2 rounded-2xl {{ $message->status === 'rejected' ? 'border border-theme-destructive bg-theme-surface' : 'bg-theme-'.$myColour.'/60' }}">
@include('native.partials.voice-note', ['voice' => $message->voice, 'voiceKey' => $message->voiceKey(), 'ref' => 'voice-'.$key, 'ink' => $voiceInk])
<native:column ref="bubble-{{ $key }}" class="px-2 {{ $message->body === '' && $hasChips ? 'pt-2 pb-[18]' : 'py-2' }} rounded-2xl {{ $tighten(! $startsRun || $message->images !== [], ! $endsRun || $message->body !== '') }} {{ $message->status === 'rejected' ? 'border border-theme-destructive bg-theme-surface' : $bubble.'/60' }}">
@include('native.partials.voice-note', ['voice' => $message->voice, 'voiceKey' => $message->voiceKey(), 'ref' => 'voice-'.$key, 'ink' => 'ink'])
</native:column>
@else
<native:pressable ref="bubble-{{ $key }}" @doubleTap="heart({{ $message->id }})" :context-menu="$menu" a11y-hint="{{ $swipeHint }}">
<native:column class="p-2 rounded-2xl {{ $mine ? 'bg-theme-'.$myColour : 'bg-theme-wash' }}">
@include('native.partials.voice-note', ['voice' => $message->voice, 'voiceKey' => $message->voiceKey(), 'ref' => 'voice-'.$key, 'ink' => $voiceInk])
<native:column class="px-2 {{ $message->body === '' && $hasChips ? 'pt-2 pb-[18]' : 'py-2' }} rounded-2xl {{ $tighten(! $startsRun || $message->images !== [], ! $endsRun || $message->body !== '') }} {{ $bubble }}">
@include('native.partials.voice-note', ['voice' => $message->voice, 'voiceKey' => $message->voiceKey(), 'ref' => 'voice-'.$key, 'ink' => 'ink'])
</native:column>
</native:pressable>
@endif
Expand Down
48 changes: 45 additions & 3 deletions tests/Feature/Screens/ConversationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function serveRemoteThread(array $thread, ?array $poll = null, int $pushStatus =
->and(nodeByRef($screen, 'thread')['props']['scroll_anchor'] ?? null)->toBe('bottom');
});

it('draws quotes in messages behind a rule, amber in theirs and in the label colour in yours', function () {
it('draws quotes in messages behind an amber rule, in theirs and in yours', function () {
serveRemoteThread(threadJson([
remoteMessageJson(['id' => 1, 'body' => "> did you see the PR?\nnot yet"]),
remoteMessageJson(['id' => 2, 'user_id' => RemotesViewerId, 'body' => "> not yet\nlooking now"]),
Expand All @@ -87,8 +87,50 @@ function serveRemoteThread(array $thread, ?array $poll = null, int $pushStatus =
$rule = fn (string $ref): ?string => findNode(nodeByRef($screen, $ref), fn (array $node): bool => (float) ($node['props']['border_l'] ?? 0) === 2.0)['style']['border_color'] ?? null;

expect(strtolower((string) $rule('bubble-1')))->toBe(strtolower((string) theme('lane-5')))
->and(strtolower((string) $rule('bubble-2')))->not->toBe(strtolower((string) theme('lane-5')))
->and($rule('bubble-2'))->not->toBeNull();
->and(strtolower((string) $rule('bubble-2')))->toBe(strtolower((string) theme('lane-5')));
});

it('tightens the corners where a run of bubbles from the same person meet, on their side', function () {
serveRemoteThread(threadJson([
remoteMessageJson(['id' => 1, 'body' => 'first']),
remoteMessageJson(['id' => 2, 'body' => 'second']),
remoteMessageJson(['id' => 3, 'body' => 'third']),
remoteMessageJson(['id' => 4, 'user_id' => RemotesViewerId, 'body' => 'only mine']),
]));

$screen = finishRefreshes(Native::visit('/remotes/conversations/ada'));
$corners = function (string $ref) use ($screen): array {
$props = findNode(nodeByRef($screen, $ref), fn (array $node): bool => isset($node['style']['bg_color']))['props'] ?? [];

return array_map(fn (string $corner): ?float => isset($props[$corner]) ? (float) $props[$corner] : null, ['tl' => 'radius_tl', 'tr' => 'radius_tr', 'br' => 'radius_br', 'bl' => 'radius_bl']);
};

expect($corners('bubble-1'))->toBe(['tl' => 16.0, 'tr' => 16.0, 'br' => 16.0, 'bl' => 4.0])
->and($corners('bubble-2'))->toBe(['tl' => 4.0, 'tr' => 16.0, 'br' => 16.0, 'bl' => 4.0])
->and($corners('bubble-3'))->toBe(['tl' => 4.0, 'tr' => 16.0, 'br' => 16.0, 'bl' => 16.0])
->and($corners('bubble-4'))->toBe(['tl' => null, 'tr' => null, 'br' => null, 'bl' => null]);
});

it('tightens the corners where images meet the bubbles and images around them from the same person', function () {
$photo = fn (int $id): array => ['id' => $id, 'width' => 400, 'height' => 300, 'description' => null, 'url' => "http://devnull.test/i/{$id}.png"];

serveRemoteThread(threadJson([
remoteMessageJson(['id' => 1, 'body' => '', 'images' => [$photo(7), $photo(8)]]),
remoteMessageJson(['id' => 2, 'body' => 'the view from here', 'images' => [$photo(9)]]),
]));

$screen = finishRefreshes(Native::visit('/remotes/conversations/ada'));
$corners = function (array $node): array {
$props = $node['props'] ?? [];

return array_map(fn (string $corner): ?float => isset($props[$corner]) ? (float) $props[$corner] : null, ['tl' => 'radius_tl', 'bl' => 'radius_bl']);
};
$bubble = findNode(nodeByRef($screen, 'bubble-2'), fn (array $node): bool => isset($node['style']['bg_color']));

expect($corners(nodeByRef($screen, 'image-1-0')))->toBe(['tl' => 12.0, 'bl' => 4.0])
->and($corners(nodeByRef($screen, 'image-1-1')))->toBe(['tl' => 4.0, 'bl' => 4.0])
->and($corners(nodeByRef($screen, 'image-2-0')))->toBe(['tl' => 4.0, 'bl' => 4.0])
->and($corners($bubble))->toBe(['tl' => 4.0, 'bl' => 16.0]);
});

it('marks HEAD where you left off, and pulls what is showing', function () {
Expand Down