diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index 8b83ca1..3c8f0fa 100644 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -1225,7 +1225,7 @@ class PublicChat extends Component $this->mensajes = ChatMessage::where('conversation_id', $this->convId) ->orderBy('id') ->get() - ->map(fn($m) => [ + ->map(fn ($m) => [ 'tipo' => $m->tipo, 'tipo_ui' => $m->tipo_ui ?? 'text', 'contenido' => $m->contenido, @@ -1237,6 +1237,27 @@ class PublicChat extends Component $this->dispatchBrowserEvent('scroll-chat'); } + // Llamado por wire:poll — igual que cargarMensajes pero sin forzar scroll + public function pollMensajes(): void + { + if (! $this->convId) { + return; + } + + $this->mensajes = ChatMessage::where('conversation_id', $this->convId) + ->orderBy('id') + ->get() + ->map(fn ($m) => [ + 'tipo' => $m->tipo, + 'tipo_ui' => $m->tipo_ui ?? 'text', + 'contenido' => $m->contenido, + 'payload' => $m->payload ?? [], + 'created_at' => $m->created_at->format('H:i'), + ]) + ->toArray(); + // No dispatches scroll-chat — el MutationObserver del JS maneja el badge + } + // ───────────────────────────────────────────────────────── // Helpers // ───────────────────────────────────────────────────────── diff --git a/resources/views/chat-publico.blade.php b/resources/views/chat-publico.blade.php index 9f5273e..4a077d9 100644 --- a/resources/views/chat-publico.blade.php +++ b/resources/views/chat-publico.blade.php @@ -104,30 +104,109 @@ @livewireScripts diff --git a/resources/views/livewire/chat/public-chat.blade.php b/resources/views/livewire/chat/public-chat.blade.php index 5d3867d..127b261 100644 --- a/resources/views/livewire/chat/public-chat.blade.php +++ b/resources/views/livewire/chat/public-chat.blade.php @@ -154,12 +154,8 @@ {{-- ══ PASO 3: Interfaz de chat ══ --}} @else -
+
{{-- Header --}}
@@ -196,10 +192,22 @@
+ {{-- Badge: nuevos mensajes mientras se lee el historial --}} + + {{-- Mensajes --}}
@forelse($mensajes as $msg)