From a9d07870769a90231d89d519ce72428fb3417024 Mon Sep 17 00:00:00 2001 From: Lizandro Date: Sun, 19 Jul 2026 19:00:13 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20limpiarChat=20crea=20conversaci=C3=B3n?= =?UTF-8?q?=20nueva=20en=20lugar=20de=20dejar=20convId=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Antes: limpiar → convId=null → 'Iniciando chat...' → refresh recuperaba la conv vieja. Ahora: limpiar → nueva conversación → menú principal inmediato, sin refresh. Co-Authored-By: Claude Sonnet 4.6 --- app/Http/Livewire/Chat/PublicChat.php | 28 ++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index b8d563d..1a90d67 100755 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -212,13 +212,27 @@ class PublicChat extends Component public function limpiarChat(): void { - $this->mensajes = []; - $this->convId = null; - $this->flujo = ''; - $this->flujoData = []; - $this->estadoConv = 'bot'; - session()->forget('chat_conv_id'); - // paso, userId, nombreUsuario, saldoUsuario se mantienen — sesión intacta + $this->flujo = ''; + $this->flujoData = []; + $this->mensajes = []; + + // Crear nueva conversación en lugar de dejar convId en null + if ($this->userId) { + $contact = ChatContact::where('canal', 'web')->where('user_id', $this->userId)->first(); + if ($contact) { + $conv = ChatConversation::create([ + 'contact_id' => $contact->id, + 'canal' => 'web', + 'estado' => 'bot', + 'ultimo_mensaje_at' => now(), + ]); + $this->convId = $conv->id; + $this->estadoConv = 'bot'; + session()->put('chat_conv_id', $conv->id); + $this->mostrarMenuPrincipal($conv->id); + $this->cargarMensajes(); + } + } } public function cerrarSesion(): void