{{-- Thread and reply form of the SMS conversation page (#2957 slice 5b, card #3019). Sent messages sit right on a tinted background, replies left on white, a day divider above the first message of each day (Idag, Igår or the date) and the time under each message, as before; replies that were unread when the page opened say Oläst (the controller has marked them read since). The reply form posts the old fields to sms-sendout.store: sendout_id, parent_id, receiver_id, reply (the first message's third party id), parts (written by sms-form.js) and message. --}} @php $types = \App\Models\SMS::$type; $messages = collect($conversation)->map(fn ($message) => (object) $message) ->filter(fn ($message) => in_array((int) $message->type, [$types['sent'], $types['received']], true))->values(); $first = collect($conversation)->map(fn ($message) => (object) $message)->first(); $dayLabel = function ($day) { if ($day->isToday()) { return __('sms.edit.today'); } if ($day->isYesterday()) { return __('sms.edit.yesterday'); } return $day->copy()->locale(app()->getLocale())->isoFormat($day->isCurrentYear() ? 'dddd D MMMM' : 'dddd D MMMM YYYY'); }; $previousDay = null; @endphp

{{ __('sms.nhForm.conversationTitle', ['who' => $receiver->phone ?: $receiver->email]) }}

@if ($messages->isEmpty())

{{ __('sms.nhForm.noMessages') }}

@else
    @foreach ($messages as $message) @php $time = \Illuminate\Support\Carbon::parse($message->created_at); $sent = (int) $message->type === $types['sent']; @endphp @if ($previousDay === null || ! $previousDay->isSameDay($time))
  1. {{ $dayLabel($time) }}
  2. @php $previousDay = $time; @endphp @endif
  3. {{ $sent ? __('sms.nhForm.sentBy') : __('sms.nhForm.receivedFrom') }}:

    {{ $message->text }}

    @if (! $sent && is_null($message->read)) {{ __('sms.edit.unread') }}@endif

  4. @endforeach
@endif
@if (! empty($receiver->phone) && $first)

{{ __('sms.sendmessage') }}

@csrf @include('sms.partials.nh-counter')
{{ __('sms.submit') }}
@elseif (empty($receiver->phone)) {{ __('sms.nhForm.noPhone') }} @endif