42 lines
1.7 KiB
PHP
42 lines
1.7 KiB
PHP
@props(['recipient', 'chats' => []])
|
|
<x-dashboard.page-heading class="m-0 mb-0.5" :title="$recipient->name" description=""/>
|
|
<div class="bg-gray-100 h-full overflow-hidden">
|
|
<div id="chat-container" data-auth-id="{{ auth()->id() }}" data-partner-id="{{ $recipient->id }}"
|
|
class="text-sm flex flex-col-reverse overflow-y-scroll h-full max-h-screen pb-50 scroll-snap-y-container">
|
|
@forelse($chats as $chat)
|
|
@ds($chat)
|
|
<x-chat.message :right="$chat->user_id === auth()->user()->id">{{$chat->message}}</x-chat.message>
|
|
@empty
|
|
<div id="no-messages-placeholder" class="grid px-4 my-1 w-full h-full place-items-center ">
|
|
<p class="text-gray-600">No Messages Found!</p>
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
<x-chat.message-input :recipient_id="$recipient->id"/>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const container = document.getElementById('chat-container');
|
|
|
|
if (container) {
|
|
const authId = parseInt(container.dataset.authId);
|
|
const partnerId = parseInt(container.dataset.partnerId);
|
|
|
|
// Sort IDs for consistent channel naming
|
|
const user1 = Math.min(authId, partnerId);
|
|
const user2 = Math.max(authId, partnerId);
|
|
|
|
window.Echo.private(`chat.${user1}.${user2}`)
|
|
.listen('MessageSent', (e) => {
|
|
const message = e.message;
|
|
if (!message) return;
|
|
// Check if user is the recipient of the message
|
|
if (message.user_id === partnerId) {
|
|
addMessageToChat({message: e.message.message}, false);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
</script>
|