{{-- Define previous message outside the loop --}} @php $previousMessage = null; @endphp @if ($loadedMessages) {{-- @dd($loadedMessages) --}} @foreach ($loadedMessages as $date => $messageGroup) {{-- Date --}}
{{ $date }}
@foreach ($messageGroup as $key => $message) {{-- @dd($message) --}} @php $belongsToAuth = $message->belongsToAuth(); $parent = $message->parent ?? null; $attachment = $message->attachment ?? null; $isEmoji = $message->isEmoji(); // keep track of previous message // The ($key -1 ) will get the previous message from loaded // messages since $key is directly linked to $message if ($key > 0) { $previousMessage = $messageGroup->get($key - 1); } // Get the next message $nextMessage = $key < $messageGroup->count() - 1 ? $messageGroup->get($key + 1) : null; @endphp
{{-- Message user Avatar --}} {{-- Hide avatar if message belongs to auth --}} @if (!$belongsToAuth && !$isPrivate)
$previousMessage && $message?->sendable?->is($previousMessage?->sendable), ])>
@endif {{-- we use w-[95%] to leave space for the image --}}
$belongsToAuth])> {{-- Show parent/reply message --}} @if ($parent != null)
$belongsToAuth, // 'ml-9 sm:ml-10' => !$belongsToAuth, ])> @php $sender = $message?->ownedBy($this->auth) ? __('wirechat::chat.labels.you') : ($message->sendable?->display_name ?? __('wirechat::chat.labels.user')); $receiver = $parent?->ownedBy($this->auth) ? __('wirechat::chat.labels.you') : ($parent->sendable?->display_name ?? __('wirechat::chat.labels.user')); @endphp
@if ($parent?->ownedBy($this->auth) && $message?->ownedBy($this->auth)) {{ __('wirechat::chat.labels.you_replied_to_yourself') }} @elseif ($parent?->ownedBy($this->auth)) {{ __('wirechat::chat.labels.participant_replied_to_you', ['sender' => $sender]) }} @elseif ($message?->ownedBy($parent->sendable)) {{ __('wirechat::chat.labels.participant_replied_to_themself', ['sender' => $sender]) }} @else {{ __('wirechat::chat.labels.participant_replied_other_participant', ['sender' => $sender, 'receiver' => $receiver]) }} @endif
$belongsToAuth, ' border-l-4 mr-auto ' => !$belongsToAuth, ])>

{{ $parent?->body != '' ? $parent?->body : ($parent->hasAttachment() ? __('wirechat::chat.labels.attachment') : '') }}

@endif {{-- Body section --}}
$belongsToAuth, ])> {{-- Message Actions --}} @if (($isGroup && $conversation->group?->allowsMembersToSendMessages()) || $authParticipant->isAdmin())
$belongsToAuth, 'order-3' => !$belongsToAuth, ])> {{-- reply button --}} {{-- Dropdown actions button --}} {{-- Dots --}} {{-- Keep message (if disappearing messages enabled) --}} @if (timebank_config('wirechat.disappearing_messages.enabled', true) && timebank_config('wirechat.disappearing_messages.allow_users_to_keep', true)) @endif @if ($message->ownedBy($this->auth)|| ($authParticipant->isAdmin() && $isGroup)) @endif {{-- Dont show delete for me if is group --}} @if (!$isGroup) @endif
@endif {{-- Kept Message Indicator (Bookmark) --}} @if (timebank_config('wirechat.disappearing_messages.enabled', true) && timebank_config('wirechat.disappearing_messages.allow_users_to_keep', true) && $message->kept_at)
@endif {{-- Message body --}}
$belongsToAuth, 'order-1' => !$belongsToAuth, ])> {{-- Show sender name is message does not belong to auth and conversation is group --}} {{-- -------------------- --}} {{-- Attachment section --}} {{-- -------------------- --}} @if ($attachment) @if (!$belongsToAuth && $isGroup)
$message?->sendable?->is($previousMessage?->sendable), ])> {{ $message->sendable?->display_name }}
@endif {{-- Attachemnt is Application/ --}} @if (str()->startsWith($attachment->mime_type, 'application/')) @include('wirechat::livewire.chat.partials.file', [ 'attachment' => $attachment ]) @endif {{-- Attachemnt is Video/ --}} @if (str()->startsWith($attachment->mime_type, 'video/')) @endif {{-- Attachemnt is image/ --}} @if (str()->startsWith($attachment->mime_type, 'image/')) @include('wirechat::livewire.chat.partials.image', [ 'previousMessage' => $previousMessage, 'message' => $message, 'nextMessage' => $nextMessage, 'belongsToAuth' => $belongsToAuth, 'attachment' => $attachment ]) @endif @endif {{-- if message is emoji then don't show the styled messagebody layout --}} @if ($isEmoji)

{{ $message->body }}

@endif {{-- -------------------- --}} {{-- Message body section --}} {{-- If message is not emoji then show the message body styles --}} {{-- -------------------- --}} @if ($message->body && !$isEmoji) @include('wirechat::livewire.chat.partials.message', [ 'previousMessage' => $previousMessage, 'message' => $message, 'nextMessage' => $nextMessage, 'belongsToAuth' => $belongsToAuth, 'isGroup' => $isGroup, 'attachment' => $attachment]) @endif
@endforeach @endforeach @endif